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
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
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
15 // compatibility macros
16 #if (__VERSION__ >= 130)
17 #define THE_ATTRIBUTE in
18 #define THE_SHADER_IN in
19 #define THE_SHADER_OUT out
21 #define occTexture1D texture
22 #define occTexture2D texture
23 #define occTexture3D texture
24 #define occTextureCube texture
25 #define occTextureCubeLod textureLod
27 #define THE_ATTRIBUTE attribute
28 #define THE_SHADER_IN varying
29 #define THE_SHADER_OUT varying
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
38 #define occTextureCubeLod(theSampl,theCoord,theLod) textureCube(theSampl,theCoord)
43 #if (__VERSION__ >= 300)
44 #define THE_PREC_ENUM highp // lowp should be enough for enums but triggers driver bugs
46 #define THE_PREC_ENUM lowp
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]
65 out vec4 occFragColor0;
68 #ifdef OCC_ENABLE_draw_buffers
69 #define occFragColorArrayAlias gl_FragData
70 #define occFragColor0 gl_FragData[0]
72 #define occFragColor0 gl_FragColor
76 #if (THE_NB_FRAG_OUTPUTS >= 2)
77 #define occFragColor1 occFragColorArrayAlias[1]
81 #if (THE_NB_FRAG_OUTPUTS >= 3)
82 #define occFragColor2 occFragColorArrayAlias[2]
86 #if (THE_NB_FRAG_OUTPUTS >= 4)
87 #define occFragColor3 occFragColorArrayAlias[3]
92 // Built-in outputs notation
93 #define occFragColor occFragColor0
94 #define occFragCoverage occFragColor1
96 #define occPeelDepth occFragColor0
97 #define occPeelFrontColor occFragColor1
98 #define occPeelBackColor occFragColor2
100 //! Define the main Fragment Shader early return procedure.
101 bool occFragEarlyReturn();
103 //! Define the main Fragment Shader output - color value.
104 void occSetFragColor (in vec4 theColor);
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
117 uniform mat4 occWorldViewMatrix; //!< World-view matrix
118 uniform mat4 occProjectionMatrix; //!< Projection matrix
119 uniform mat4 occModelWorldMatrix; //!< Model-world matrix
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
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
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
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
139 vec3 occDiffIBLMap (in vec3 theNormal); //!< Unpacks spherical harmonics coefficients to diffuse IBL map's values
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
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
153 #define occLight_Index(theId) 0
155 uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources
157 //! Type of light source, int (see OccLightType enum).
158 #define occLight_Type(theId) occLightSourcesTypes[occLight_Index(theId)]
160 //! Specular intensity (equals to diffuse), vec3.
161 #define occLight_Specular(theId) occLightSources[occLight_Index(theId) * 4 + 0].rgb
163 //! Intensity of light source (>= 0), float.
164 #define occLight_Intensity(theId) occLightSources[occLight_Index(theId) * 4 + 0].a
166 //! Is light a headlight, bool? DEPRECATED method.
167 #define occLight_IsHeadlight(theId) false
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
172 //! Direction of specified spot light source, vec3.
173 #define occLight_SpotDirection(theId) occLightSources[occLight_Index(theId) * 4 + 2].xyz
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
178 //! Maximum spread angle of the spot light (in radians), float.
179 #define occLight_SpotCutOff(theId) occLightSources[occLight_Index(theId) * 4 + 3].z
181 //! Attenuation of the spot light intensity (from 0 to 1), float.
182 #define occLight_SpotExponent(theId) occLightSources[occLight_Index(theId) * 4 + 3].w
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
188 //! Const attenuation factor of positional light source, float.
189 #define occLight_ConstAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].x
191 //! Linear attenuation factor of positional light source, float.
192 #define occLight_LinearAttenuation(theId) occLightSources[occLight_Index(theId) * 4 + 3].y
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);
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
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
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
223 #if defined(THE_HAS_TEXTURE_COLOR) && defined(FRAGMENT_SHADER)
224 #define occMaterialBaseColor(theIsFront, theTexCoord) (occMaterial_Color(theIsFront) * occTexture2D(occSamplerBaseColor, theTexCoord))
226 #define occMaterialBaseColor(theIsFront, theTexCoord) occMaterial_Color(theIsFront)
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;
233 #define occMaterialOcclusion(theColor, theTexCoord)
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)
240 #define occMaterialEmission(theIsFront, theTexCoord) occMaterial_Emission(theIsFront)
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)
247 #define occTextureNormal(theTexCoord) vec4(0.0) // no normal map
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)
255 #define occMaterialRoughness(theIsFront, theTexCoord) occPBRMaterial_NormalizedRoughness(theIsFront)
256 #define occMaterialMetallic(theIsFront, theTexCoord) occPBRMaterial_Metallic(theIsFront)
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
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
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
276 //! @endfile Declarations.glsl