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 #define occTextureCubeLod textureCubeLod
39 #if (__VERSION__ >= 300)
40 #define THE_PREC_ENUM highp // lowp should be enough for enums but triggers driver bugs
42 #define THE_PREC_ENUM lowp
50 THE_ATTRIBUTE vec4 occVertex;
51 THE_ATTRIBUTE vec3 occNormal;
52 THE_ATTRIBUTE vec4 occTexCoord;
53 THE_ATTRIBUTE vec4 occVertColor;
54 #elif defined(FRAGMENT_SHADER)
55 #if (__VERSION__ >= 130)
56 #ifdef OCC_ENABLE_draw_buffers
57 out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];
58 #define occFragColorArrayAlias occFragColorArray
59 #define occFragColor0 occFragColorArray[0]
61 out vec4 occFragColor0;
64 #ifdef OCC_ENABLE_draw_buffers
65 #define occFragColorArrayAlias gl_FragData
66 #define occFragColor0 gl_FragData[0]
68 #define occFragColor0 gl_FragColor
72 #if (THE_NB_FRAG_OUTPUTS >= 2)
73 #define occFragColor1 occFragColorArrayAlias[1]
77 #if (THE_NB_FRAG_OUTPUTS >= 3)
78 #define occFragColor2 occFragColorArrayAlias[2]
82 #if (THE_NB_FRAG_OUTPUTS >= 4)
83 #define occFragColor3 occFragColorArrayAlias[3]
88 // Built-in outputs notation
89 #define occFragColor occFragColor0
90 #define occFragCoverage occFragColor1
92 //! Define the main Fragment Shader output - color value.
93 void occSetFragColor (in vec4 theColor);
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
106 uniform mat4 occWorldViewMatrix; //!< World-view matrix
107 uniform mat4 occProjectionMatrix; //!< Projection matrix
108 uniform mat4 occModelWorldMatrix; //!< Model-world matrix
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
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
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
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
128 vec3 occDiffIBLMap (in vec3 theNormal); //!< Unpacks spherical harmonics coefficients to diffuse IBL map's values
131 // light type enumeration (same as Graphic3d_TypeOfLightSource)
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
137 uniform vec4 occLightAmbient; //!< Cumulative ambient color
138 #if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
139 uniform THE_PREC_ENUM int occLightSourcesCount; //!< Total number of light sources
141 //! Type of light source, int (see OccLightType enum).
142 #define occLight_Type(theId) occLightSourcesTypes[theId].x
144 //! Is light a headlight, int?
145 #define occLight_IsHeadlight(theId) (occLightSourcesTypes[theId].y != 0)
147 //! Specular intensity (equals to diffuse), vec4.
148 #define occLight_Specular(theId) occLightSources[theId * 4 + 0]
150 //! Position of specified light source, vec4.
151 #define occLight_Position(theId) occLightSources[theId * 4 + 1]
153 //! Direction of specified spot light source, vec4.
154 #define occLight_SpotDirection(theId) occLightSources[theId * 4 + 2]
156 //! Maximum spread angle of the spot light (in radians), float.
157 #define occLight_SpotCutOff(theId) occLightSources[theId * 4 + 3].z
159 //! Attenuation of the spot light intensity (from 0 to 1), float.
160 #define occLight_SpotExponent(theId) occLightSources[theId * 4 + 3].w
162 #if defined(THE_IS_PBR)
163 //! Intensity of light source (>= 0), float.
164 #define occLight_Intensity(theId) occLightSources[theId * 4 + 0].a
167 //! Diffuse intensity (equals to Specular), vec4.
168 #define occLight_Diffuse(theId) occLightSources[theId * 4 + 0]
170 //! Const attenuation factor of positional light source, float.
171 #define occLight_ConstAttenuation(theId) occLightSources[theId * 4 + 3].x
173 //! Linear attenuation factor of positional light source, float.
174 #define occLight_LinearAttenuation(theId) occLightSources[theId * 4 + 3].y
178 // Converts roughness value from range [0, 1] to real value for calculations
179 float occRoughness (in float theNormalizedRoughness);
181 // Front material properties accessors
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
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
198 // Back material properties accessors
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
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
215 #ifdef THE_HAS_DEFAULT_SAMPLER
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;
220 //! occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
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?
224 uniform vec4 occTexTrsf2d[2]; //!< 2D texture transformation parameters
225 uniform float occPointSize; //!< point size
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
230 uniform float occAlphaCutoff; //!< alpha test cutoff value
232 //! Parameters of clipping planes
233 #if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0)
234 uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
235 uniform THE_PREC_ENUM int occClipPlaneChains[THE_MAX_CLIP_PLANES]; //! Indicating the number of planes in the Chain
236 uniform THE_PREC_ENUM int occClipPlaneCount; //!< Total number of clip planes
238 //! @endfile Declarations.glsl