We'll define a function for each of the three terms in the specular BRDF. Use the following steps:
- Define a function for the Fresnel term using the Schlick approximation:
vec3 schlickFresnel( float lDotH ) { vec3 f0 = vec3(0.04); // Dielectrics if( Material.Metal ) { f0 = Material.Color; } return f0 + (1 - f0) * pow(1.0 - lDotH, 5);}
- Define a function for the geometry term G:
float geomSmith( float dotProd ) { float k = (Material.Rough + 1.0) * (Material.Rough + 1.0) / 8.0; float denom = dotProd * (1 - k) + k; return 1.0 / denom;}
- The normal distribution function D, based on GGX/Trowbridge-Reitz:
float ggxDistribution( float nDotH ) { float alpha2 = Material.Rough * Material.Rough * Material.Rough * Material.Rough; ...