0031096: Visualization, TKOpenGl - support metallic-roughness texture mapping
[occt.git] / src / Shaders / Shaders_Declarations_glsl.pxx
index 586183a..c0e596d 100644 (file)
@@ -178,49 +178,76 @@ static const char Shaders_Declarations_glsl[] =
   "#endif\n"
   "#endif\n"
   "\n"
-  "// Converts roughness value from range [0, 1] to real value for calculations\n"
+  "#if defined(THE_IS_PBR)\n"
+  "//! Converts roughness value from range [0, 1] to real value for calculations\n"
   "float occRoughness (in float theNormalizedRoughness);\n"
   "\n"
-  "// Front material properties accessors\n"
-  "#if !defined(THE_IS_PBR)\n"
-  "vec4  occFrontMaterial_Emission(void);            //!< Emission color\n"
-  "vec4  occFrontMaterial_Ambient(void);             //!< Ambient  reflection\n"
-  "vec4  occFrontMaterial_Diffuse(void);             //!< Diffuse  reflection\n"
-  "vec4  occFrontMaterial_Specular(void);            //!< Specular reflection\n"
-  "float occFrontMaterial_Shininess(void);           //!< Specular exponent\n"
-  "float occFrontMaterial_Transparency(void);        //!< Transparency coefficient\n"
+  "// Front/back material properties accessors\n"
+  "vec4  occPBRMaterial_Color(in bool theIsFront);    //!< Base color of PBR material\n"
+  "float occPBRMaterial_Metallic(in bool theIsFront); //!< Metallic coefficient\n"
+  "float occPBRMaterial_NormalizedRoughness(in bool theIsFront); //!< Normalized roughness coefficient\n"
+  "vec3  occPBRMaterial_Emission(in bool theIsFront); //!< Light intensity emitted by material\n"
+  "float occPBRMaterial_IOR(in bool theIsFront);      //!< Index of refraction\n"
   "#else\n"
-  "vec4  occPBRFrontMaterial_Color(void);               //!< Base color of PBR material\n"
-  "float occPBRFrontMaterial_Metallic(void);            //!< Metallic coefficient\n"
-  "float occPBRFrontMaterial_Roughness(void);           //!< Roughness coefficient\n"
-  "float occPBRFrontMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient\n"
-  "vec3  occPBRFrontMaterial_Emission(void);            //!< Light intensity emitted by material\n"
-  "float occPBRFrontMaterial_IOR(void);                 //!< Index of refraction\n"
-  "#endif\n"
+  "// Front material properties accessors\n"
+  "vec4  occFrontMaterial_Emission(void);           //!< Emission color\n"
+  "vec4  occFrontMaterial_Ambient(void);            //!< Ambient  reflection\n"
+  "vec4  occFrontMaterial_Diffuse(void);            //!< Diffuse  reflection\n"
+  "vec4  occFrontMaterial_Specular(void);           //!< Specular reflection\n"
+  "float occFrontMaterial_Shininess(void);          //!< Specular exponent\n"
+  "float occFrontMaterial_Transparency(void);       //!< Transparency coefficient\n"
   "\n"
   "// Back material properties accessors\n"
-  "#if !defined(THE_IS_PBR)\n"
   "vec4  occBackMaterial_Emission(void);            //!< Emission color\n"
   "vec4  occBackMaterial_Ambient(void);             //!< Ambient  reflection\n"
   "vec4  occBackMaterial_Diffuse(void);             //!< Diffuse  reflection\n"
   "vec4  occBackMaterial_Specular(void);            //!< Specular reflection\n"
   "float occBackMaterial_Shininess(void);           //!< Specular exponent\n"
   "float occBackMaterial_Transparency(void);        //!< Transparency coefficient\n"
-  "#else\n"
-  "vec4  occPBRBackMaterial_Color(void);               //!< Base color of PBR material\n"
-  "float occPBRBackMaterial_Metallic(void);            //!< Metallic coefficient\n"
-  "float occPBRBackMaterial_Roughness(void);           //!< Roughness coefficient\n"
-  "float occPBRBackMaterial_NormalizedRoughness(void); //!< Normalized roughness coefficient\n"
-  "vec3  occPBRBackMaterial_Emission(void);            //!< Light intensity emitted by material\n"
-  "float occPBRBackMaterial_IOR(void);                 //!< Index of refraction\n"
   "#endif\n"
   "\n"
   "#ifdef THE_HAS_DEFAULT_SAMPLER\n"
-  "#define occActiveSampler    occSampler0                //!< alias for backward compatibility\n"
-  "#define occSamplerBaseColor occSampler0                //!< alias to a base color texture\n"
-  "uniform               sampler2D occSampler0;           //!< current active sampler;\n"
+  "#define occActiveSampler    occSampler0  //!< alias for backward compatibility\n"
+  "#define occSamplerBaseColor occSampler0  //!< alias to a base color texture\n"
+  "uniform sampler2D           occSampler0; //!< current active sampler;\n"
+  "#endif                                   //!  occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
+  "\n"
+  "#if defined(THE_HAS_TEXTURE_COLOR)\n"
+  "#define occTextureColor(theMatColor, theTexCoord) (theMatColor * occTexture2D(occSamplerBaseColor, theTexCoord))\n"
+  "#else\n"
+  "#define occTextureColor(theMatColor, theTexCoord) theMatColor\n"
+  "#endif\n"
+  "\n"
+  "#if defined(THE_HAS_TEXTURE_OCCLUSION) && defined(FRAGMENT_SHADER)\n"
+  "uniform sampler2D occSamplerOcclusion;   //!< R occlusion texture sampler\n"
+  "#define occTextureOcclusion(theColor, theTexCoord) theColor *= occTexture2D(occSamplerOcclusion, theTexCoord).r;\n"
+  "#else\n"
+  "#define occTextureOcclusion(theColor, theTexCoord)\n"
   "#endif\n"
-  "                                                       //!  occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing\n"
+  "\n"
+  "#if defined(THE_HAS_TEXTURE_EMISSIVE) && defined(FRAGMENT_SHADER)\n"
+  "uniform sampler2D occSamplerEmissive;    //!< RGB emissive texture sampler\n"
+  "#define occTextureEmissive(theMatEmis, theTexCoord) (theMatEmis * occTexture2D(occSamplerEmissive, theTexCoord).rgb)\n"
+  "#else\n"
+  "#define occTextureEmissive(theMatEmis, theTexCoord) theMatEmis\n"
+  "#endif\n"
+  "\n"
+  "#if defined(THE_HAS_TEXTURE_NORMAL) && defined(FRAGMENT_SHADER)\n"
+  "uniform sampler2D occSamplerNormal;      //!< XYZ normal texture sampler with W==0 indicating no texture\n"
+  "#define occTextureNormal(theTexCoord) occTexture2D(occSamplerNormal, theTexCoord)\n"
+  "#else\n"
+  "#define occTextureNormal(theTexCoord) vec4(0.0) // no normal map\n"
+  "#endif\n"
+  "\n"
+  "#if defined(THE_HAS_TEXTURE_METALROUGHNESS) && defined(FRAGMENT_SHADER)\n"
+  "uniform sampler2D occSamplerMetallicRoughness; //!< BG metallic-roughness texture sampler\n"
+  "#define occTextureRoughness(theRoug, theTexCoord) (theRoug * occTexture2D(occSamplerMetallicRoughness, theTexCoord).g)\n"
+  "#define occTextureMetallic(theMet,   theTexCoord) (theMet  * occTexture2D(occSamplerMetallicRoughness, theTexCoord).b)\n"
+  "#else\n"
+  "#define occTextureRoughness(theRoug, theTexCoord) theRoug\n"
+  "#define occTextureMetallic(theMet,   theTexCoord) theMet\n"
+  "#endif\n"
+  "\n"
   "uniform               vec4      occColor;              //!< color value (in case of disabled lighting)\n"
   "uniform THE_PREC_ENUM int       occDistinguishingMode; //!< Are front and back faces distinguished?\n"
   "uniform THE_PREC_ENUM int       occTextureEnable;      //!< Is texture enabled?\n"