30f0ad28 |
1 | |
d95f5ce1 |
2 | //! @file Declarations.glsl includes definition of common uniform variables in OCCT GLSL programs |
daf73ab7 |
3 | //! @def THE_MAX_LIGHTS |
4 | //! Specifies the length of array of lights, which is 8 by default. Defined by Shader Manager. |
5 | // #define THE_MAX_LIGHTS 8 |
6 | |
7 | //! @def THE_MAX_CLIP_PLANES |
8 | //! Specifies the length of array of clipping planes, which is 8 by default. Defined by Shader Manager. |
9 | // #define THE_MAX_CLIP_PLANES 8 |
30f0ad28 |
10 | |
b17e5bae |
11 | //! @def THE_NB_FRAG_OUTPUTS |
12 | //! Specifies the length of array of Fragment Shader outputs, which is 1 by default. Defined by Shader Manager. |
13 | // #define THE_NB_FRAG_OUTPUTS 1 |
14 | |
b86bb3df |
15 | // compatibility macros |
16 | #if (__VERSION__ >= 130) |
17 | #define THE_ATTRIBUTE in |
18 | #define THE_SHADER_IN in |
19 | #define THE_SHADER_OUT out |
20 | #define THE_OUT out |
ff6665dc |
21 | #define occTexture1D texture |
b86bb3df |
22 | #define occTexture2D texture |
ff6665dc |
23 | #define occTexture3D texture |
67312b79 |
24 | #define occTextureCube texture |
25 | #define occTextureCubeLod textureLod |
b86bb3df |
26 | #else |
27 | #define THE_ATTRIBUTE attribute |
28 | #define THE_SHADER_IN varying |
29 | #define THE_SHADER_OUT varying |
30 | #define THE_OUT |
ff6665dc |
31 | #define occTexture1D texture1D |
b86bb3df |
32 | #define occTexture2D texture2D |
ff6665dc |
33 | #define occTexture3D texture3D |
67312b79 |
34 | #define occTextureCube textureCube |
75642c14 |
35 | #if !defined(GL_ES) || defined(textureCubeLod) |
36 | #define occTextureCubeLod textureCubeLod |
37 | #else // fallback |
38 | #define occTextureCubeLod(theSampl,theCoord,theLod) textureCube(theSampl,theCoord) |
39 | #endif |
b86bb3df |
40 | #endif |
41 | |
8a53d1c4 |
42 | #ifdef GL_ES |
67312b79 |
43 | #if (__VERSION__ >= 300) |
44 | #define THE_PREC_ENUM highp // lowp should be enough for enums but triggers driver bugs |
45 | #else |
46 | #define THE_PREC_ENUM lowp |
47 | #endif |
8a53d1c4 |
48 | #else |
49 | #define THE_PREC_ENUM |
50 | #endif |
51 | |
12381341 |
52 | // Vertex attributes |
12381341 |
53 | #ifdef VERTEX_SHADER |
b86bb3df |
54 | THE_ATTRIBUTE vec4 occVertex; |
55 | THE_ATTRIBUTE vec3 occNormal; |
56 | THE_ATTRIBUTE vec4 occTexCoord; |
57 | THE_ATTRIBUTE vec4 occVertColor; |
8e0a2b19 |
58 | #elif defined(FRAGMENT_SHADER) |
59 | #if (__VERSION__ >= 130) |
60 | #ifdef OCC_ENABLE_draw_buffers |
b17e5bae |
61 | out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS]; |
62 | #define occFragColorArrayAlias occFragColorArray |
63 | #define occFragColor0 occFragColorArray[0] |
8e0a2b19 |
64 | #else |
b17e5bae |
65 | out vec4 occFragColor0; |
8e0a2b19 |
66 | #endif |
177781da |
67 | #else |
8e0a2b19 |
68 | #ifdef OCC_ENABLE_draw_buffers |
b17e5bae |
69 | #define occFragColorArrayAlias gl_FragData |
70 | #define occFragColor0 gl_FragData[0] |
8e0a2b19 |
71 | #else |
b17e5bae |
72 | #define occFragColor0 gl_FragColor |
8e0a2b19 |
73 | #endif |
a1073ae2 |
74 | #endif |
b17e5bae |
75 | |
76 | #if (THE_NB_FRAG_OUTPUTS >= 2) |
77 | #define occFragColor1 occFragColorArrayAlias[1] |
78 | #else |
79 | vec4 occFragColor1; |
80 | #endif |
81 | #if (THE_NB_FRAG_OUTPUTS >= 3) |
82 | #define occFragColor2 occFragColorArrayAlias[2] |
83 | #else |
84 | vec4 occFragColor2; |
85 | #endif |
86 | #if (THE_NB_FRAG_OUTPUTS >= 4) |
87 | #define occFragColor3 occFragColorArrayAlias[3] |
88 | #else |
89 | vec4 occFragColor3; |
90 | #endif |
91 | |
92 | // Built-in outputs notation |
93 | #define occFragColor occFragColor0 |
94 | #define occFragCoverage occFragColor1 |
95 | |
78c4e836 |
96 | #define occPeelDepth occFragColor0 |
97 | #define occPeelFrontColor occFragColor1 |
98 | #define occPeelBackColor occFragColor2 |
99 | |
100 | //! Define the main Fragment Shader early return procedure. |
101 | bool occFragEarlyReturn(); |
102 | |
b17e5bae |
103 | //! Define the main Fragment Shader output - color value. |
104 | void occSetFragColor (in vec4 theColor); |
30f0ad28 |
105 | #endif |
106 | |
67312b79 |
107 | // Pi number definitions |
108 | #define PI 3.141592654 |
109 | #define PI_2 6.283185307 |
110 | #define PI_DIV_2 1.570796327 |
111 | #define PI_DIV_3 1.047197551 |
112 | #define PI_DIV_4 0.785398163 |
113 | #define INV_PI 0.318309886 |
114 | #define INV_PI_2 0.159154943 |
115 | |
12381341 |
116 | // Matrix state |
117 | uniform mat4 occWorldViewMatrix; //!< World-view matrix |
118 | uniform mat4 occProjectionMatrix; //!< Projection matrix |
119 | uniform mat4 occModelWorldMatrix; //!< Model-world matrix |
120 | |
121 | uniform mat4 occWorldViewMatrixInverse; //!< Inverse of the world-view matrix |
122 | uniform mat4 occProjectionMatrixInverse; //!< Inverse of the projection matrix |
123 | uniform mat4 occModelWorldMatrixInverse; //!< Inverse of the model-world matrix |
124 | |
125 | uniform mat4 occWorldViewMatrixTranspose; //!< Transpose of the world-view matrix |
126 | uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection matrix |
127 | uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix |
128 | |
129 | uniform mat4 occWorldViewMatrixInverseTranspose; //!< Transpose of the inverse of the world-view matrix |
130 | uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection matrix |
131 | uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix |
132 | |
67312b79 |
133 | #if defined(THE_IS_PBR) |
134 | uniform sampler2D occEnvLUT; //!< Environment Lookup Table |
135 | uniform sampler2D occDiffIBLMapSHCoeffs; //!< Packed diffuse (irradiance) IBL map's spherical harmonics coefficients |
136 | uniform samplerCube occSpecIBLMap; //!< Specular IBL map |
137 | uniform int occNbSpecIBLLevels; //!< Number of mipmap levels used in occSpecIBLMap to store different roughness values maps |
138 | |
139 | vec3 occDiffIBLMap (in vec3 theNormal); //!< Unpacks spherical harmonics coefficients to diffuse IBL map's values |
140 | #endif |
141 | |
565baee6 |
142 | // light type enumeration (same as Graphic3d_TypeOfLightSource) |
12381341 |
143 | const int OccLightType_Direct = 1; //!< directional light source |
144 | const int OccLightType_Point = 2; //!< isotropic point light source |
145 | const int OccLightType_Spot = 3; //!< spot light source |
146 | |
147 | // Light sources |
8a53d1c4 |
148 | uniform vec4 occLightAmbient; //!< Cumulative ambient color |
daf73ab7 |
149 | #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0) |
8f8fe4a9 |
150 | #if (THE_MAX_LIGHTS > 1) |
151 | #define occLight_Index(theId) theId |
152 | #else |
153 | #define occLight_Index(theId) 0 |
154 | #endif |
8a53d1c4 |
155 | uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources |
565baee6 |
156 | |
157 | //! Type of light source, int (see OccLightType enum). |
8f8fe4a9 |
158 | #define occLight_Type(theId) occLightSourcesTypes[occLight_Index(theId)] |
565baee6 |
159 | |
9504a30d |
160 | //! Specular intensity (equals to diffuse), vec3. |
8f8fe4a9 |
161 | #define occLight_Specular(theId) occLightSources[occLight_Index(theId) * 4 + 0].rgb |
565baee6 |
162 | |
9504a30d |
163 | //! Intensity of light source (>= 0), float. |
8f8fe4a9 |
164 | #define occLight_Intensity(theId) occLightSources[occLight_Index(theId) * 4 + 0].a |
565baee6 |
165 | |
37f80e16 |
166 | //! Is light a headlight, bool? DEPRECATED method. |
167 | #define occLight_IsHeadlight(theId) false |
565baee6 |
168 | |
37f80e16 |
169 | //! Position of specified light source or direction of directional light source, vec3. |
8f8fe4a9 |
170 | #define occLight_Position(theId) occLightSources[occLight_Index(theId) * 4 + 1].xyz |
9504a30d |
171 | |
172 | //! Direction of specified spot light source, vec3. |
8f8fe4a9 |
173 | #define occLight_SpotDirection(theId) occLightSources[occLight_Index(theId) * 4 + 2].xyz |
565baee6 |
174 | |
88b312d3 |
175 | //! Range on which point light source (positional or spot) can affect (>= 0), float. |
8f8fe4a9 |
176 | #define occLight_Range(theId) occLightSources[occLight_Index(theId) * 4 + 2].w |
88b312d3 |
177 | |
565baee6 |
178 | //! Maximum spread angle of the spot light (in radians), float. |
8f8fe4a9 |
179 | #define occLight_SpotCutOff(theId) occLightSources[occLight_Index(theId) * 4 + 3].z |
565baee6 |
180 | |
181 | //! Attenuation of the spot light intensity (from 0 to 1), float. |
8f8fe4a9 |
182 | #define occLight_SpotExponent(theId) occLightSources[occLight_Index(theId) * 4 + 3].w |
565baee6 |
183 | |
9504a30d |
184 | #if !defined(THE_IS_PBR) |
185 | //! Diffuse intensity (equals to Specular), vec3. |
8f8fe4a9 |
186 | #define occLight_Diffuse(theId) occLightSources[occLight_Index(theId) * 4 + 0].rgb |
565baee6 |
187 | |
188 | //! Const attenuation factor of positional light source, float. |
8f8fe4a9 |
189 | #define occLight_ConstAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].x |
565baee6 |
190 | |
191 | //! Linear attenuation factor of positional light source, float. |
8f8fe4a9 |
192 | #define occLight_LinearAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].y |
daf73ab7 |
193 | #endif |
67312b79 |
194 | #endif |
195 | |
72f6dc61 |
196 | #if defined(THE_IS_PBR) |
197 | //! Converts roughness value from range [0, 1] to real value for calculations |
67312b79 |
198 | float occRoughness (in float theNormalizedRoughness); |
12381341 |
199 | |
72f6dc61 |
200 | // Front/back material properties accessors |
201 | vec4 occPBRMaterial_Color(in bool theIsFront); //!< Base color of PBR material |
202 | float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient |
203 | float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient |
204 | vec3 occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material |
205 | float occPBRMaterial_IOR(in bool theIsFront); //!< Index of refraction |
941f6cae |
206 | #define occMaterial_Emission occPBRMaterial_Emission |
207 | #define occMaterial_Color occPBRMaterial_Color |
67312b79 |
208 | #else |
941f6cae |
209 | vec4 occMaterial_Diffuse(in bool theIsFront); //!< Diffuse reflection |
210 | vec3 occMaterial_Specular(in bool theIsFront); //!< Specular reflection |
211 | float occMaterial_Shininess(in bool theIsFront); //!< Specular exponent |
212 | vec3 occMaterial_Ambient(in bool theIsFront); //!< Ambient reflection |
213 | vec3 occMaterial_Emission(in bool theIsFront); //!< Emission color |
214 | #define occMaterial_Color occMaterial_Diffuse |
67312b79 |
215 | #endif |
12381341 |
216 | |
737e9a8d |
217 | #ifdef THE_HAS_DEFAULT_SAMPLER |
72f6dc61 |
218 | #define occActiveSampler occSampler0 //!< alias for backward compatibility |
219 | #define occSamplerBaseColor occSampler0 //!< alias to a base color texture |
220 | uniform sampler2D occSampler0; //!< current active sampler; |
221 | #endif //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing |
222 | |
941f6cae |
223 | #if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER) |
224 | #define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord)) |
72f6dc61 |
225 | #else |
941f6cae |
226 | #define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront) |
72f6dc61 |
227 | #endif |
228 | |
229 | #if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER) |
230 | uniform sampler2D occSamplerOcclusion; //!< R occlusion texture sampler |
941f6cae |
231 | #define occMaterialOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r; |
72f6dc61 |
232 | #else |
941f6cae |
233 | #define occMaterialOcclusion(theColor, theTexCoord) |
737e9a8d |
234 | #endif |
72f6dc61 |
235 | |
236 | #if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER) |
237 | uniform sampler2D occSamplerEmissive; //!< RGB emissive texture sampler |
941f6cae |
238 | #define occMaterialEmission(theIsFront, theTexCoord) (occMaterial_Emission(theIsFront) * occTexture2D(occSamplerEmissive, theTexCoord).rgb) |
72f6dc61 |
239 | #else |
941f6cae |
240 | #define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront) |
72f6dc61 |
241 | #endif |
242 | |
243 | #if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER) |
244 | uniform sampler2D occSamplerNormal; //!< XYZ normal texture sampler with W==0 indicating no texture |
245 | #define occTextureNormal(theTexCoord) occTexture2D(occSamplerNormal, theTexCoord) |
246 | #else |
247 | #define occTextureNormal(theTexCoord) vec4(0.0) // no normal map |
248 | #endif |
249 | |
250 | #if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER) |
251 | uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler |
941f6cae |
252 | #define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g) |
253 | #define occMaterialMetallic(theIsFront, theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b) |
72f6dc61 |
254 | #else |
941f6cae |
255 | #define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront) |
256 | #define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront) |
72f6dc61 |
257 | #endif |
258 | |
8a53d1c4 |
259 | uniform vec4 occColor; //!< color value (in case of disabled lighting) |
260 | uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished? |
261 | uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled? |
79f4f036 |
262 | uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters |
8a53d1c4 |
263 | uniform float occPointSize; //!< point size |
12381341 |
264 | |
a1073ae2 |
265 | //! Parameters of blended order-independent transparency rendering algorithm |
266 | uniform int occOitOutput; //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage) |
267 | uniform float occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment |
c40eb6b9 |
268 | uniform float occAlphaCutoff; //!< alpha test cutoff value |
a1073ae2 |
269 | |
12381341 |
270 | //! Parameters of clipping planes |
daf73ab7 |
271 | #if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0) |
8a53d1c4 |
272 | uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES]; |
25c35042 |
273 | uniform THE_PREC_ENUM int occClipPlaneChains[THE_MAX_CLIP_PLANES]; //! Indicating the number of planes in the Chain |
8a53d1c4 |
274 | uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes |
daf73ab7 |
275 | #endif |
d95f5ce1 |
276 | //! @endfile Declarations.glsl |