0030700: Visualization, TKOpenGl - support PBR Metallic-Roughness shading model
[occt.git] / src / Shaders / Shaders_DeclarationsImpl_glsl.pxx
index 71a6b03..3b31ea9 100644 (file)
@@ -22,15 +22,59 @@ static const char Shaders_DeclarationsImpl_glsl[] =
   "\n"
   "#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)\n"
   "// arrays of light sources\n"
-  "uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types\n"
   "uniform               vec4  occLightSources[THE_MAX_LIGHTS * 4];  //!< packed light sources parameters\n"
+  "uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types\n"
+  "#endif\n"
+  "\n"
+  "#if defined(THE_IS_PBR)\n"
+  "vec3 occDiffIBLMap (in vec3 theNormal)\n"
+  "{\n"
+  "  vec3 aSHCoeffs[9];\n"
+  "  for (int i = 0; i < 9; ++i)\n"
+  "  {\n"
+  "    aSHCoeffs[i] = occTexture2D (occDiffIBLMapSHCoeffs, vec2 ((float(i) + 0.5) / 9.0, 0.0)).rgb;\n"
+  "  }\n"
+  "  return aSHCoeffs[0]\n"
+  "\n"
+  "       + aSHCoeffs[1] * theNormal.x\n"
+  "       + aSHCoeffs[2] * theNormal.y\n"
+  "       + aSHCoeffs[3] * theNormal.z\n"
+  "\n"
+  "       + aSHCoeffs[4] * theNormal.x * theNormal.z\n"
+  "       + aSHCoeffs[5] * theNormal.y * theNormal.z\n"
+  "       + aSHCoeffs[6] * theNormal.x * theNormal.y\n"
+  "\n"
+  "       + aSHCoeffs[7] * (3.0 * theNormal.z * theNormal.z - 1.0)\n"
+  "       + aSHCoeffs[8] * (theNormal.x * theNormal.x - theNormal.y * theNormal.y);\n"
+  "}\n"
   "#endif\n"
   "\n"
-  "// material state\n"
+  "// front and back material properties accessors\n"
+  "#if defined(THE_IS_PBR)\n"
+  "uniform vec4 occPbrFrontMaterial[3];\n"
+  "uniform vec4 occPbrBackMaterial[3];\n"
+  "\n"
+  "#define MIN_ROUGHNESS 0.01\n"
+  "// Converts roughness value from range [0, 1] to real value for calculations\n"
+  "float occRoughness (in float theNormalizedRoughness) { return theNormalizedRoughness * (1.0 - MIN_ROUGHNESS) + MIN_ROUGHNESS; }\n"
+  "\n"
+  "vec4  occPBRFrontMaterial_Color(void)     { return occPbrFrontMaterial[0]; }\n"
+  "vec3  occPBRFrontMaterial_Emission(void)  { return occPbrFrontMaterial[1].rgb; }\n"
+  "float occPBRFrontMaterial_IOR(void)       { return occPbrFrontMaterial[1].w; }\n"
+  "float occPBRFrontMaterial_Metallic(void)  { return occPbrFrontMaterial[2].b; }\n"
+  "float occPBRFrontMaterial_Roughness(void) { return occRoughness (occPbrFrontMaterial[2].g); }\n"
+  "float occPBRFrontMaterial_NormalizedRoughness(void) { return occPbrFrontMaterial[2].g; }\n"
+  "\n"
+  "vec4  occPBRBackMaterial_Color(void)     { return occPbrBackMaterial[0]; }\n"
+  "vec3  occPBRBackMaterial_Emission(void)  { return occPbrBackMaterial[1].rgb; }\n"
+  "float occPBRBackMaterial_IOR(void)       { return occPbrBackMaterial[1].w; }\n"
+  "float occPBRBackMaterial_Metallic(void)  { return occPbrBackMaterial[2].b; }\n"
+  "float occPBRBackMaterial_Roughness(void) { return occRoughness (occPbrBackMaterial[2].g); }\n"
+  "float occPBRBackMaterial_NormalizedRoughness(void) { return occPbrBackMaterial[2].g; }\n"
+  "#else\n"
   "uniform vec4 occFrontMaterial[5];\n"
   "uniform vec4 occBackMaterial[5];\n"
   "\n"
-  "// front material properties accessors\n"
   "vec4  occFrontMaterial_Ambient(void)      { return occFrontMaterial[0]; }\n"
   "vec4  occFrontMaterial_Diffuse(void)      { return occFrontMaterial[1]; }\n"
   "vec4  occFrontMaterial_Specular(void)     { return occFrontMaterial[2]; }\n"
@@ -38,13 +82,13 @@ static const char Shaders_DeclarationsImpl_glsl[] =
   "float occFrontMaterial_Shininess(void)    { return occFrontMaterial[4].x; }\n"
   "float occFrontMaterial_Transparency(void) { return occFrontMaterial[4].y; }\n"
   "\n"
-  "// back material properties accessors\n"
   "vec4  occBackMaterial_Ambient(void)       { return occBackMaterial[0]; }\n"
   "vec4  occBackMaterial_Diffuse(void)       { return occBackMaterial[1]; }\n"
   "vec4  occBackMaterial_Specular(void)      { return occBackMaterial[2]; }\n"
   "vec4  occBackMaterial_Emission(void)      { return occBackMaterial[3]; }\n"
   "float occBackMaterial_Shininess(void)     { return occBackMaterial[4].x; }\n"
   "float occBackMaterial_Transparency(void)  { return occBackMaterial[4].y; }\n"
+  "#endif\n"
   "\n"
   "// 2D texture coordinates transformation\n"
   "vec2  occTextureTrsf_Translation(void) { return occTexTrsf2d[0].xy; }\n"