0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Shaders / Declarations.glsl
1
2 //! @file Declarations.glsl includes definition of common uniform variables in OCCT GLSL programs
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
10
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
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
21   #define occTexture1D   texture
22   #define occTexture2D   texture
23   #define occTexture3D   texture
24   #define occTextureCube texture
25   #define occTextureCubeLod textureLod
26 #else
27   #define THE_ATTRIBUTE  attribute
28   #define THE_SHADER_IN  varying
29   #define THE_SHADER_OUT varying
30   #define THE_OUT
31   #define occTexture1D   texture1D
32   #define occTexture2D   texture2D
33   #define occTexture3D   texture3D
34   #define occTextureCube textureCube
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
40 #endif
41
42 #ifdef GL_ES
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
48 #else
49   #define THE_PREC_ENUM
50 #endif
51
52 // Vertex attributes
53 #ifdef VERTEX_SHADER
54   THE_ATTRIBUTE vec4 occVertex;
55   THE_ATTRIBUTE vec3 occNormal;
56   THE_ATTRIBUTE vec4 occTexCoord;
57   THE_ATTRIBUTE vec4 occVertColor;
58 #elif defined(FRAGMENT_SHADER)
59   #if (__VERSION__ >= 130)
60     #ifdef OCC_ENABLE_draw_buffers
61       out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];
62       #define occFragColorArrayAlias occFragColorArray
63       #define occFragColor0 occFragColorArray[0]
64     #else
65       out vec4 occFragColor0;
66     #endif
67   #else
68     #ifdef OCC_ENABLE_draw_buffers
69       #define occFragColorArrayAlias gl_FragData
70       #define occFragColor0 gl_FragData[0]
71     #else
72       #define occFragColor0 gl_FragColor
73     #endif
74   #endif
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
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
103   //! Define the main Fragment Shader output - color value.
104   void occSetFragColor (in vec4 theColor);
105 #endif
106
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
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
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
142 // light type enumeration (same as Graphic3d_TypeOfLightSource)
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
148 uniform               vec4 occLightAmbient;      //!< Cumulative ambient color
149 #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
150 #if (THE_MAX_LIGHTS > 1)
151   #define occLight_Index(theId) theId
152 #else
153   #define occLight_Index(theId) 0
154 #endif
155 uniform THE_PREC_ENUM int  occLightSourcesCount; //!< Total number of light sources
156
157 //! Type of light source, int (see OccLightType enum).
158 #define occLight_Type(theId)              occLightSourcesTypes[occLight_Index(theId)]
159
160 //! Specular intensity (equals to diffuse), vec3.
161 #define occLight_Specular(theId)          occLightSources[occLight_Index(theId) * 4 + 0].rgb
162
163 //! Intensity of light source (>= 0), float.
164 #define occLight_Intensity(theId)         occLightSources[occLight_Index(theId) * 4 + 0].a
165
166 //! Is light a headlight, bool? DEPRECATED method.
167 #define occLight_IsHeadlight(theId) false
168
169 //! Position of specified light source or direction of directional light source, vec3.
170 #define occLight_Position(theId)          occLightSources[occLight_Index(theId) * 4 + 1].xyz
171
172 //! Direction of specified spot light source, vec3.
173 #define occLight_SpotDirection(theId)     occLightSources[occLight_Index(theId) * 4 + 2].xyz
174
175 //! Range on which point light source (positional or spot) can affect (>= 0), float.
176 #define occLight_Range(theId)             occLightSources[occLight_Index(theId) * 4 + 2].w
177
178 //! Maximum spread angle of the spot light (in radians), float.
179 #define occLight_SpotCutOff(theId)        occLightSources[occLight_Index(theId) * 4 + 3].z
180
181 //! Attenuation of the spot light intensity (from 0 to 1), float.
182 #define occLight_SpotExponent(theId)      occLightSources[occLight_Index(theId) * 4 + 3].w
183
184 #if !defined(THE_IS_PBR)
185 //! Diffuse intensity (equals to Specular), vec3.
186 #define occLight_Diffuse(theId)           occLightSources[occLight_Index(theId) * 4 + 0].rgb
187
188 //! Const attenuation factor of positional light source, float.
189 #define occLight_ConstAttenuation(theId)  occLightSources[occLight_Index(theId) * 4 + 3].x
190
191 //! Linear attenuation factor of positional light source, float.
192 #define occLight_LinearAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].y
193 #endif
194 #endif
195
196 #if defined(THE_IS_PBR)
197 //! Converts roughness value from range [0, 1] to real value for calculations
198 float occRoughness (in float theNormalizedRoughness);
199
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
206 #define occMaterial_Emission occPBRMaterial_Emission
207 #define occMaterial_Color occPBRMaterial_Color
208 #else
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
215 #endif
216
217 #ifdef THE_HAS_DEFAULT_SAMPLER
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
223 #if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)
224 #define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))
225 #else
226 #define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)
227 #endif
228
229 #if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)
230 uniform sampler2D occSamplerOcclusion;   //!< R occlusion texture sampler
231 #define occMaterialOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;
232 #else
233 #define occMaterialOcclusion(theColor, theTexCoord)
234 #endif
235
236 #if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)
237 uniform sampler2D occSamplerEmissive;    //!< RGB emissive texture sampler
238 #define occMaterialEmission(theIsFront, theTexCoord) (occMaterial_Emission(theIsFront) * occTexture2D(occSamplerEmissive, theTexCoord).rgb)
239 #else
240 #define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)
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
252 #define occMaterialRoughness(theIsFront, theTexCoord) (occPBRMaterial_NormalizedRoughness(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)
253 #define occMaterialMetallic(theIsFront,  theTexCoord) (occPBRMaterial_Metallic(theIsFront) * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)
254 #else
255 #define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)
256 #define occMaterialMetallic(theIsFront,  theTexCoord) occPBRMaterial_Metallic(theIsFront)
257 #endif
258
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?
262 uniform               vec4      occTexTrsf2d[2];       //!< 2D texture transformation parameters
263 uniform               float     occPointSize;          //!< point size
264
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
268 uniform               float     occAlphaCutoff;    //!< alpha test cutoff value
269
270 //! Parameters of clipping planes
271 #if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0)
272 uniform               vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
273 uniform THE_PREC_ENUM int  occClipPlaneChains[THE_MAX_CLIP_PLANES]; //! Indicating the number of planes in the Chain
274 uniform THE_PREC_ENUM int  occClipPlaneCount;   //!< Total number of clip planes
275 #endif
276 //! @endfile Declarations.glsl