From f25912c87291bd84a9d1a430c3c35b3604d4bd56 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 24 Oct 2025 14:49:06 -0700 Subject: Add references --- shaders/cook_torrance.frag | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shaders/cook_torrance.frag b/shaders/cook_torrance.frag index 1a4faf8..74a89e2 100644 --- a/shaders/cook_torrance.frag +++ b/shaders/cook_torrance.frag @@ -1,3 +1,6 @@ +/* +[1] BRDF reference: https://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html +*/ precision highp float; uniform vec4 BaseColorFactor; @@ -86,8 +89,10 @@ vec3 get_ws_normal(vec3 normalWs, vec3 normalMapSample) { } #endif // HAS_TANGENTS || HAS_TEXCOORDS +// Normal distribution function (NDF). +// Eq (4) in reference [1]. float trowbridge_reitz_GGX(float roughness, float NdotH) { - float a = roughness * roughness; + float a = roughness * roughness; // "alpha roughness" in the reference. float a2 = a * a; float d = NdotH * NdotH * (a2 - 1.0) + 1.0; return a2 / (PI * d * d); @@ -97,6 +102,8 @@ float geometry_schlick_GGX(float k, float NdotV) { return NdotV / (NdotV * (1.0 - k) + k); } +// Geometry function. +// See "Smith" under "Geometric Shadowing" in reference [1]. float geometry_smith(float roughness, float NdotL, float NdotV) { float k = roughness * roughness / 2.0; // IBL return geometry_schlick_GGX(k, NdotV) * geometry_schlick_GGX(k, NdotL); @@ -138,7 +145,7 @@ vec3 cook_torrance_IBL( vec3 irradiance, vec3 prefiltered_env, vec2 BRDF_env) { vec3 F0 = mix(vec3(0.04), albedo, metallic); vec3 F = fresnel_schlick_roughness(F0, NdotV, roughness); - vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); + vec3 Kd = (vec3(1.0) - F) * (1.0 - metallic); // A non-HDR environment map essentially has the 1/pi baked in as it does not // use physical units. See: // https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ -- cgit v1.2.3