From 4c41d7cd0f4db1c262371fbe6b4db13639d9fc7b Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 6 Aug 2025 17:13:15 -0700 Subject: Fix SH brightness, add better schlick fresnel --- brdf.cginc | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/brdf.cginc b/brdf.cginc index d36d82b..ea21b49 100644 --- a/brdf.cginc +++ b/brdf.cginc @@ -6,17 +6,15 @@ #include "lysenko.cginc" #include "math.cginc" -float fresnel(float LoH) { - // Schlick's approximation - float n1 = 1.0; - float n2 = 1.33; - float r0 = (n1 - n2) / (n1 + n2); - r0 = r0 * r0; - - float term = 1.0 - LoH; +// Schlick "An Inexpensive BRDF Model for Physically-based Rendering". +// Equation 24. +// f0: Reflectance at normal incidence. Typically around 0.04. +// f90: Reflectance at grazing incidence. Typically around 1.0. +float F_Schlick(float LoH, float f0, float f90) { + float term = 1.0f - LoH; float term2 = term * term; float term5 = term2 * term2 * term; - return r0 + (1.0 - r0) * term5; + return f0 + (f90 - f0) * term5; } float4 brdf(Pbr pbr, LightData data) { @@ -25,7 +23,7 @@ float4 brdf(Pbr pbr, LightData data) { // Direct if (true) { - float F = fresnel(data.direct.LoH); + float F = F_Schlick(data.direct.LoH, 0.04f, 1.0f); float D = D_GGX(pbr.roughness, data.direct.NoH, data.direct.H); float V = V_SmithGGXCorrelated_Fast(pbr.roughness, data.common.NoV, data.direct.NoL); @@ -41,11 +39,11 @@ float4 brdf(Pbr pbr, LightData data) { // Indirect if (true) { - float F = fresnel(data.indirect.LoH); + float F = F_Schlick(data.indirect.LoH, 0.04f, 1.0f); specular += F * data.indirect.specular; - float Fd = 1.0 / PI; + float Fd = 1.0f; // Lambertian divide is baked into SH float3 remainder = (1.0f - F); diffuse += Fd * remainder * pbr.albedo.xyz * data.indirect.diffuse; remainder *= (1.0f - Fd * pbr.albedo); -- cgit v1.2.3