0030700: Visualization, TKOpenGl - support PBR Metallic-Roughness shading model
[occt.git] / src / Shaders / PBRIllumination.glsl
1 //! Calculates direct illumination using Cook-Torrance BRDF.
2 vec3 occPBRIllumination (in vec3  theView,
3                          in vec3  theLight,
4                          in vec3  theNormal,
5                          in vec4  theBaseColor,
6                          in float theMetallic,
7                          in float theRoughness,
8                          in float theIOR,
9                          in vec3  theLightColor,
10                          in float theLightIntensity)
11 {
12   vec3 aHalf = normalize (theView + theLight);
13   float aCosVH = max(dot(theView, aHalf), 0.0);
14   vec3 aFresnel = occPBRFresnel (theBaseColor.rgb, theMetallic, theIOR, aCosVH);
15   vec3 aSpecular = occPBRCookTorrance (theView,
16                                        theLight,
17                                        theNormal,
18                                        theBaseColor.rgb,
19                                        theMetallic,
20                                        theRoughness,
21                                        theIOR);
22   vec3 aDiffuse = vec3(1.0) - aFresnel;
23   aDiffuse *= 1.0 - theMetallic;
24   aDiffuse *= INV_PI;
25   aDiffuse *= theBaseColor.rgb;
26   aDiffuse = mix (vec3(0.0), aDiffuse, theBaseColor.a);
27   return (aDiffuse + aSpecular) * theLightColor * theLightIntensity * max(0.0, dot(theLight, theNormal));
28 }