Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
oivLegacyShaderHelper.h
1#ifndef OIV_LEGACY_SHADER_HELPER_H
2#define OIV_LEGACY_SHADER_HELPER_H
3// For convenience when migrating legacy GLSL shaders.
4// Initializes legacy point and material parameter structs.
5
7
9// Replaces:
10// uniform gl_MaterialParameters gl_FrontMaterial;
11// uniform gl_MaterialParameters gl_BackMaterial;
12
13gl_MaterialParameters OivFrontMaterial()
14{
15 gl_MaterialParameters mat;
16 mat.emission = OivFrontMaterialEmissive();
17 mat.ambient = OivFrontMaterialAmbient();
18 mat.diffuse = OivFrontMaterialDiffuse();
19 mat.specular = OivFrontMaterialSpecular();
20 mat.shininess = OivFrontMaterialShininess();
21 return mat;
22}
23
24gl_MaterialParameters OivBackMaterial()
25{
26 gl_MaterialParameters params;
27 params.emission = OivBackMaterialEmissive();
28 params.ambient = OivBackMaterialAmbient();
29 params.diffuse = OivBackMaterialDiffuse();
30 params.specular = OivBackMaterialSpecular();
31 params.shininess = OivBackMaterialShininess();
32 return params;
33}
34
36// Replaces
37// uniform gl_LightSourceParameters gl_LightSource[gl_MaxLights];
38//
39// Notes:
40// - Name "OivLightSource" is already used in oivShaderState.h
41// - gl_LightSourceParameters.halfVector is not supported
42
43gl_LightSourceParameters OivLightSourceParameters( int i )
44{
45 gl_LightSourceParameters params;
46 params.ambient = OivLightSourceAmbient(i);
47 params.diffuse = OivLightSourceDiffuse(i);
48 params.specular = OivLightSourceSpecular(i);
49 params.position = OivLightSourcePosition(i);
50 //params.halfVector = OivLightSourceHalfVector(i);
51 params.spotDirection = OivLightSourceSpotDirection(i);
52 params.spotExponent = OivLightSourceSpotExponent(i);
53 params.spotCutoff = OivLightSourceSpotCutoff(i);
54 params.spotCosCutoff = OivLightSourceSpotCosCutoff(i);
55 params.constantAttenuation = OivLightSourceConstantAttenuation(i);
56 params.linearAttenuation = OivLightSourceLinearAttenuation(i);
57 params.quadraticAttenuation = OivLightSourceQuadraticAttenuation(i);
58 return params;
59}
60
62// Replaces:
63// uniform gl_LightModelParameters gl_LightModel;
64gl_LightModelParameters OivLightModel()
65{
66 gl_LightModelParameters params;
67 params.ambient = OivGlobalAmbient(); // Acs
68 return params;
69};
70
72// Replaces:
73// uniform gl_LightModelProducts gl_FrontLightModelProduct;
74// uniform gl_LightModelProducts gl_BackLightModelProduct;
75gl_LightModelProducts OivFrontLightModelProduct()
76{
77 gl_LightModelProducts params;
78 params.sceneColor = // vec4 Derived. Ecm + Acm * Acs
80 return params;
81};
82
83gl_LightModelProducts OivBackLightModelProduct()
84{
85 gl_LightModelProducts params;
86 params.sceneColor = // vec4 Derived. Ecm + Acm * Acs
88 return params;
89};
90
92// Replaces:
93// uniform gl_LightProducts gl_FrontLightProduct[gl_MaxLights];
94// uniform gl_LightProducts gl_BackLightProduct[gl_MaxLights];
95
96gl_LightProducts OivFrontLightProduct( int i )
97{
98 gl_LightProducts params;
99 params.ambient = OivFrontLightProductAmbient(i);
100 params.diffuse = OivFrontLightProductDiffuse(i);
101 params.specular = OivFrontLightProductSpecular(i);
102 return params;
103}
104
105gl_LightProducts OivBackLightProduct( int i )
106{
107 gl_LightProducts params;
108 params.ambient = OivBackLightProductAmbient(i);
109 params.diffuse = OivBackLightProductDiffuse(i);
110 params.specular = OivBackLightProductSpecular(i);
111 return params;
112}
113
115// Replaces:
116// uniform gl_FogParameters gl_Fog;
117gl_FogParameters OivFogParameters()
118{
119 gl_FogParameters params;
120 params.color = OivFogColor();
121 params.density = OivFogDensity();
122 params.start = OivFogStart();
123 params.end = OivFogEnd();
124 params.scale = OivFogScale();
125 return params;
126};
127
129// Replaces:
130// uniform gl_PointParameters gl_Point;
131// WARNING: Not possible to fully implement this.
132gl_PointParameters OivPointParameters()
133{
134 gl_PointParameters params;
135 params.size = gl_PointSize;
136 params.sizeMin = 0;
137 params.sizeMax = 0;
138 params.fadeThresholdSize = 0;
139 params.distanceConstantAttenuation = 0;
140 params.distanceLinearAttenuation = 0;
141 params.distanceQuadraticAttenuation = 0;
142 return params;
143};
144
145#endif
vec4 OivFrontLightProductDiffuse(int id)
Get product of diffuse component between back material and id'th light.
float OivLightSourceLinearAttenuation(int id)
Get the light linear attenuation value.
float OivFrontMaterialShininess()
Get front material shininess value.
float OivLightSourceSpotExponent(int id)
Get the light spot exponent.
vec3 OivLightSourceSpotDirection(int id)
Get the light spot direction.
float OivFogStart()
Get the near distance used in the linear fog equation.
float OivFogEnd()
Get the far distance used in the linear fog equation.
float OivFogScale()
Get the fog scale derived from start and end parameters : 1.0 / (end - start)
vec4 OivFogColor()
Get the fog color.
vec4 OivFrontMaterialAmbient()
Get front material ambient color.
vec4 OivBackLightProductSpecular(int id)
Get product of specular component between back material and id'th light.
vec4 OivBackMaterialEmissive()
Get back material emissive color.
vec4 OivFrontLightProductSpecular(int id)
Get product of specular component between back material and id'th light.
vec4 OivFrontLightProductAmbient(int id)
Get product of ambient component between back material and id'th light.
vec4 OivBackLightProductDiffuse(int id)
Get product of diffuse component between back material and id'th light.
float OivBackMaterialShininess()
Get back material shininess value.
vec4 OivGlobalAmbient()
Gets the global ambient color value.
vec4 OivLightSourcePosition(int id)
Get the light position.
float OivLightSourceSpotCutoff(int id)
Get the light spot cutoff.
float OivLightSourceSpotCosCutoff(int id)
Get the light spot cutoff cosine.
vec4 OivLightSourceSpecular(int id)
Get the light specular color.
float OivLightSourceConstantAttenuation(int id)
Get the light constant attenuation value.
float OivLightSourceQuadraticAttenuation(int id)
Get the light quadratic attenuation value.
vec4 OivFrontMaterialDiffuse()
Get front material diffuse color.
vec4 OivBackLightProductAmbient(int id)
Get product of ambient component between back material and id'th light.
vec4 OivLightSourceDiffuse(int id)
Get the light diffuse color.
float OivFogDensity()
Get fog density used in exponential fog equations.
vec4 OivLightSourceAmbient(int id)
Get the light ambient color.
vec4 OivFrontMaterialEmissive()
Get front material emissive color.
vec4 OivBackMaterialSpecular()
Get back material specular color.
vec4 OivFrontMaterialSpecular()
Get front material specular color.
vec4 OivBackMaterialDiffuse()
Get back material diffuse color.
vec4 OivBackMaterialAmbient()
Get back material ambient color.