Declarations.glsl 12 KB

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