From fd5d500009bc47d4f5b07c7d0cb2b88fdb337aa5 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Thu, 23 Oct 2025 21:45:35 -0700 Subject: Do not divide by PI --- shaders/cook_torrance.frag | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shaders/cook_torrance.frag b/shaders/cook_torrance.frag index 1975491..1a4faf8 100644 --- a/shaders/cook_torrance.frag +++ b/shaders/cook_torrance.frag @@ -121,7 +121,11 @@ vec3 cook_torrance( vec3 F = fresnel_schlick(F0, HdotV); float G = geometry_smith(roughness, NdotL, NdotV); vec3 Kd = mix(vec3(1.0) - F, vec3(0.0), metallic); - vec3 diffuse = Kd*albedo*INV_PI; + // 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/ + // vec3 diffuse = Kd * albedo * INV_PI; + vec3 diffuse = Kd * albedo * INV_PI; // Take a max to prevent division by 0 when either dot product is 0. vec3 specular = (D*F*G) / max(4.0 * NdotV * NdotL, 0.0001); return diffuse + specular; @@ -135,7 +139,11 @@ vec3 cook_torrance_IBL( 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 diffuse = Kd * albedo * INV_PI * irradiance; + // 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/ + // vec3 diffuse = Kd * albedo * INV_PI * irradiance; + vec3 diffuse = Kd * albedo * irradiance; vec3 specular = prefiltered_env * (F * BRDF_env.x + BRDF_env.y); return occlusion * (diffuse + specular); } -- cgit v1.2.3