0030700: Visualization, TKOpenGl - support PBR Metallic-Roughness shading model
[occt.git] / src / Shaders / PBRCookTorrance.glsl
diff --git a/src/Shaders/PBRCookTorrance.glsl b/src/Shaders/PBRCookTorrance.glsl
new file mode 100644 (file)
index 0000000..3d86363
--- /dev/null
@@ -0,0 +1,20 @@
+//! Calculates Cook-Torrance BRDF.
+vec3 occPBRCookTorrance (in vec3  theView,
+                         in vec3  theLight,
+                         in vec3  theNormal,
+                         in vec3  theBaseColor,
+                         in float theMetallic,
+                         in float theRoughness,
+                         in float theIOR)
+{
+  vec3 aHalf = normalize (theView + theLight);
+  float aCosV = max(dot(theView, theNormal), 0.0);
+  float aCosL = max(dot(theLight, theNormal), 0.0);
+  float aCosH = max(dot(aHalf, theNormal), 0.0);
+  float aCosVH = max(dot(aHalf, theView), 0.0);
+  vec3 aCookTorrance = occPBRDistribution (aCosH, theRoughness)
+                     * occPBRGeometry     (aCosV, aCosL, theRoughness)
+                     * occPBRFresnel      (theBaseColor, theMetallic, theIOR, aCosVH);
+  aCookTorrance /= 4.0;
+  return aCookTorrance;
+}