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 |
35 | #define occTextureCubeLod textureCubeLod |
b86bb3df |
36 | #endif |
37 | |
8a53d1c4 |
38 | #ifdef GL_ES |
67312b79 |
39 | #if (__VERSION__ >= 300) |
40 | #define THE_PREC_ENUM highp // lowp should be enough for enums but triggers driver bugs |
41 | #else |
42 | #define THE_PREC_ENUM lowp |
43 | #endif |
8a53d1c4 |
44 | #else |
45 | #define THE_PREC_ENUM |
46 | #endif |
47 | |
12381341 |
48 | // Vertex attributes |
12381341 |
49 | #ifdef VERTEX_SHADER |
b86bb3df |
50 | THE_ATTRIBUTE vec4 occVertex; |
51 | THE_ATTRIBUTE vec3 occNormal; |
52 | THE_ATTRIBUTE vec4 occTexCoord; |
53 | THE_ATTRIBUTE vec4 occVertColor; |
8e0a2b19 |
54 | #elif defined(FRAGMENT_SHADER) |
55 | #if (__VERSION__ >= 130) |
56 | #ifdef OCC_ENABLE_draw_buffers |
b17e5bae |
57 | out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS]; |
58 | #define occFragColorArrayAlias occFragColorArray |
59 | #define occFragColor0 occFragColorArray[0] |
8e0a2b19 |
60 | #else |
b17e5bae |
61 | out vec4 occFragColor0; |
8e0a2b19 |
62 | #endif |
177781da |
63 | #else |
8e0a2b19 |
64 | #ifdef OCC_ENABLE_draw_buffers |
b17e5bae |
65 | #define occFragColorArrayAlias gl_FragData |
66 | #define occFragColor0 gl_FragData[0] |
8e0a2b19 |
67 | #else |
b17e5bae |
68 | #define occFragColor0 gl_FragColor |
8e0a2b19 |
69 | #endif |
a1073ae2 |
70 | #endif |
b17e5bae |
71 | |
72 | #if (THE_NB_FRAG_OUTPUTS >= 2) |
73 | #define occFragColor1 occFragColorArrayAlias[1] |
74 | #else |
75 | vec4 occFragColor1; |
76 | #endif |
77 | #if (THE_NB_FRAG_OUTPUTS >= 3) |
78 | #define occFragColor2 occFragColorArrayAlias[2] |
79 | #else |
80 | vec4 occFragColor2; |
81 | #endif |
82 | #if (THE_NB_FRAG_OUTPUTS >= 4) |
83 | #define occFragColor3 occFragColorArrayAlias[3] |
84 | #else |
85 | vec4 occFragColor3; |
86 | #endif |
87 | |
88 | // Built-in outputs notation |
89 | #define occFragColor occFragColor0 |
90 | #define occFragCoverage occFragColor1 |
91 | |
92 | //! Define the main Fragment Shader output - color value. |
93 | void occSetFragColor (in vec4 theColor); |
30f0ad28 |
94 | #endif |
95 | |
67312b79 |
96 | // Pi number definitions |
97 | #define PI 3.141592654 |
98 | #define PI_2 6.283185307 |
99 | #define PI_DIV_2 1.570796327 |
100 | #define PI_DIV_3 1.047197551 |
101 | #define PI_DIV_4 0.785398163 |
102 | #define INV_PI 0.318309886 |
103 | #define INV_PI_2 0.159154943 |
104 | |
12381341 |
105 | // Matrix state |
106 | uniform mat4 occWorldViewMatrix; //!< World-view matrix |
107 | uniform mat4 occProjectionMatrix; //!< Projection matrix |
108 | uniform mat4 occModelWorldMatrix; //!< Model-world matrix |
109 | |
110 | uniform mat4 occWorldViewMatrixInverse; //!< Inverse of the world-view matrix |
111 | uniform mat4 occProjectionMatrixInverse; //!< Inverse of the projection matrix |
112 | uniform mat4 occModelWorldMatrixInverse; //!< Inverse of the model-world matrix |
113 | |
114 | uniform mat4 occWorldViewMatrixTranspose; //!< Transpose of the world-view matrix |
115 | uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection matrix |
116 | uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix |
117 | |
118 | uniform mat4 occWorldViewMatrixInverseTranspose; //!< Transpose of the inverse of the world-view matrix |
119 | uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection matrix |
120 | uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix |
121 | |
67312b79 |
122 | #if defined(THE_IS_PBR) |
123 | uniform sampler2D occEnvLUT; //!< Environment Lookup Table |
124 | uniform sampler2D occDiffIBLMapSHCoeffs; //!< Packed diffuse (irradiance) IBL map's spherical harmonics coefficients |
125 | uniform samplerCube occSpecIBLMap; //!< Specular IBL map |
126 | uniform int occNbSpecIBLLevels; //!< Number of mipmap levels used in occSpecIBLMap to store different roughness values maps |
127 | |
128 | vec3 occDiffIBLMap (in vec3 theNormal); //!< Unpacks spherical harmonics coefficients to diffuse IBL map's values |
129 | #endif |
130 | |
565baee6 |
131 | // light type enumeration (same as Graphic3d_TypeOfLightSource) |
12381341 |
132 | const int OccLightType_Direct = 1; //!< directional light source |
133 | const int OccLightType_Point = 2; //!< isotropic point light source |
134 | const int OccLightType_Spot = 3; //!< spot light source |
135 | |
136 | // Light sources |
8a53d1c4 |
137 | uniform vec4 occLightAmbient; //!< Cumulative ambient color |
daf73ab7 |
138 | #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0) |
8a53d1c4 |
139 | uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources |
565baee6 |
140 | |
141 | //! Type of light source, int (see OccLightType enum). |
142 | #define occLight_Type(theId) occLightSourcesTypes[theId].x |
143 | |
144 | //! Is light a headlight, int? |
67312b79 |
145 | #define occLight_IsHeadlight(theId) (occLightSourcesTypes[theId].y != 0) |
565baee6 |
146 | |
147 | //! Specular intensity (equals to diffuse), vec4. |
148 | #define occLight_Specular(theId) occLightSources[theId * 4 + 0] |
149 | |
150 | //! Position of specified light source, vec4. |
151 | #define occLight_Position(theId) occLightSources[theId * 4 + 1] |
152 | |
153 | //! Direction of specified spot light source, vec4. |
154 | #define occLight_SpotDirection(theId) occLightSources[theId * 4 + 2] |
155 | |
156 | //! Maximum spread angle of the spot light (in radians), float. |
157 | #define occLight_SpotCutOff(theId) occLightSources[theId * 4 + 3].z |
158 | |
159 | //! Attenuation of the spot light intensity (from 0 to 1), float. |
160 | #define occLight_SpotExponent(theId) occLightSources[theId * 4 + 3].w |
161 | |
67312b79 |
162 | #if defined(THE_IS_PBR) |
163 | //! Intensity of light source (>= 0), float. |
164 | #define occLight_Intensity(theId) occLightSources[theId * 4 + 0].a |
165 | #else |
166 | |
565baee6 |
167 | //! Diffuse intensity (equals to Specular), vec4. |
168 | #define occLight_Diffuse(theId) occLightSources[theId * 4 + 0] |
169 | |
170 | //! Const attenuation factor of positional light source, float. |
171 | #define occLight_ConstAttenuation(theId) occLightSources[theId * 4 + 3].x |
172 | |
173 | //! Linear attenuation factor of positional light source, float. |
174 | #define occLight_LinearAttenuation(theId) occLightSources[theId * 4 + 3].y |
daf73ab7 |
175 | #endif |
67312b79 |
176 | #endif |
177 | |
178 | // Converts roughness value from range [0, 1] to real value for calculations |
179 | float occRoughness (in float theNormalizedRoughness); |
12381341 |
180 | |
181 | // Front material properties accessors |
67312b79 |
182 | #if !defined(THE_IS_PBR) |
183 | vec4 occFrontMaterial_Emission(void); //!< Emission color |
184 | vec4 occFrontMaterial_Ambient(void); //!< Ambient reflection |
185 | vec4 occFrontMaterial_Diffuse(void); //!< Diffuse reflection |
186 | vec4 occFrontMaterial_Specular(void); //!< Specular reflection |
187 | float occFrontMaterial_Shininess(void); //!< Specular exponent |
188 | float occFrontMaterial_Transparency(void); //!< Transparency coefficient |
189 | #else |
190 | vec4 occPBRFrontMaterial_Color(void); //!< Base color of PBR material |
191 | float occPBRFrontMaterial_Metallic(void); //!< Metallic coefficient |
192 | float occPBRFrontMaterial_Roughness(void); //!< Roughness coefficient |
193 | float occPBRFrontMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient |
194 | vec3 occPBRFrontMaterial_Emission(void); //!< Light intensity emitted by material |
195 | float occPBRFrontMaterial_IOR(void); //!< Index of refraction |
196 | #endif |
12381341 |
197 | |
8625ef7e |
198 | // Back material properties accessors |
67312b79 |
199 | #if !defined(THE_IS_PBR) |
200 | vec4 occBackMaterial_Emission(void); //!< Emission color |
201 | vec4 occBackMaterial_Ambient(void); //!< Ambient reflection |
202 | vec4 occBackMaterial_Diffuse(void); //!< Diffuse reflection |
203 | vec4 occBackMaterial_Specular(void); //!< Specular reflection |
204 | float occBackMaterial_Shininess(void); //!< Specular exponent |
205 | float occBackMaterial_Transparency(void); //!< Transparency coefficient |
206 | #else |
207 | vec4 occPBRBackMaterial_Color(void); //!< Base color of PBR material |
208 | float occPBRBackMaterial_Metallic(void); //!< Metallic coefficient |
209 | float occPBRBackMaterial_Roughness(void); //!< Roughness coefficient |
210 | float occPBRBackMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient |
211 | vec3 occPBRBackMaterial_Emission(void); //!< Light intensity emitted by material |
212 | float occPBRBackMaterial_IOR(void); //!< Index of refraction |
213 | #endif |
12381341 |
214 | |
737e9a8d |
215 | #ifdef THE_HAS_DEFAULT_SAMPLER |
cc8cbabe |
216 | #define occActiveSampler occSampler0 //!< alias for backward compatibility |
217 | #define occSamplerBaseColor occSampler0 //!< alias to a base color texture |
218 | uniform sampler2D occSampler0; //!< current active sampler; |
737e9a8d |
219 | #endif |
cc8cbabe |
220 | //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing |
8a53d1c4 |
221 | uniform vec4 occColor; //!< color value (in case of disabled lighting) |
222 | uniform THE_PREC_ENUM int occDistinguishingMode; //!< Are front and back faces distinguished? |
223 | uniform THE_PREC_ENUM int occTextureEnable; //!< Is texture enabled? |
79f4f036 |
224 | uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters |
8a53d1c4 |
225 | uniform float occPointSize; //!< point size |
12381341 |
226 | |
a1073ae2 |
227 | //! Parameters of blended order-independent transparency rendering algorithm |
228 | uniform int occOitOutput; //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage) |
229 | uniform float occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment |
c40eb6b9 |
230 | uniform float occAlphaCutoff; //!< alpha test cutoff value |
a1073ae2 |
231 | |
12381341 |
232 | //! Parameters of clipping planes |
daf73ab7 |
233 | #if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0) |
8a53d1c4 |
234 | uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES]; |
25c35042 |
235 | uniform THE_PREC_ENUM int occClipPlaneChains[THE_MAX_CLIP_PLANES]; //! Indicating the number of planes in the Chain |
8a53d1c4 |
236 | uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes |
daf73ab7 |
237 | #endif |
d95f5ce1 |
238 | //! @endfile Declarations.glsl |