From 7bfc0ecde84604abf8974ec2ffd1e9b0efb84bea Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 16 Mar 2026 15:51:20 -0700 Subject: Add more debug views --- brdf.cginc | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) (limited to 'brdf.cginc') diff --git a/brdf.cginc b/brdf.cginc index 2b1b754..cdf09fd 100755 --- a/brdf.cginc +++ b/brdf.cginc @@ -20,11 +20,6 @@ float Fd_Lambertian(float NoL) { // 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 term5 = pow5(1.0f - LoH); - return f0 + (f90 - f0) * term5; -} - float3 F_Schlick(float LoH, float3 f0, float f90) { float term5 = pow5(1.0f - LoH); float3 f90v = float3(f90, f90, f90); @@ -66,7 +61,8 @@ float G_GGXSmith(float roughness, float NoL, float NoV) { return rcp(denom); } -float4 brdf(Pbr pbr, LightData data) { +float4 brdf(Pbr pbr, LightData data, out BrdfData bd) { + bd = (BrdfData)0; float3 specular = 0; float3 diffuse = 0; @@ -86,28 +82,26 @@ float4 brdf(Pbr pbr, LightData data) { float f0 = 0.04f; const float f90 = 1.0f; float2 dfg_uv = float2(data.common.NoV, pbr.roughness_perceptual); - float3 dfg; [branch] if (textureExists(_DFG_LUT)) { - dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, dfg_uv, 0).rgb; + bd.ibl_dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, dfg_uv, 0).rgb; } else { - dfg = float3(1, 1, 1); + bd.ibl_dfg = float3(1, 1, 1); } float3 f0_color = lerp(f0, pbr.albedo.xyz, pbr.metallic); - float3 energy_comp = 1.0f + f0_color * (1.0f / (dfg.xxx + dfg.yyy) - 1.0f); + float3 energy_comp = 1.0f + f0_color * (1.0f / (bd.ibl_dfg.xxx + bd.ibl_dfg.yyy) - 1.0f); #if defined(_CLEARCOAT) const float cc_f0 = 0.04f; float2 cc_dfg_uv = float2(data.common.NoV_cc, pbr.cc_roughness_perceptual); - float3 cc_dfg; [branch] if (textureExists(_DFG_LUT)) { - cc_dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, cc_dfg_uv, 0).rgb; + bd.ibl_dfg_cc = _DFG_LUT.SampleLevel(bilinear_clamp_s, cc_dfg_uv, 0).rgb; } else { - cc_dfg = float3(1, 1, 1); + bd.ibl_dfg_cc = float3(1, 1, 1); } float3 cc_f0_color = lerp(cc_f0, pbr.albedo.xyz, pbr.metallic); - float3 cc_energy_comp = 1.0f + cc_f0_color * (1.0f / (cc_dfg.xxx + cc_dfg.yyy) - 1.0f); + float3 cc_energy_comp = 1.0f + cc_f0_color * (1.0f / (bd.ibl_dfg_cc.xxx + bd.ibl_dfg_cc.yyy) - 1.0f); #endif // Direct @@ -115,23 +109,23 @@ float4 brdf(Pbr pbr, LightData data) { float3 remainder = 1.0f; #if defined(_CLEARCOAT) - float Fcc = F_Schlick(data.direct.LoH, cc_f0, f90); - float Dcc = D_GGX(pbr.cc_roughness, data.direct.NoH_cc); - float Gcc = G_GGXSmith(pbr.cc_roughness, data.direct.NoL_cc, data.common.NoV_cc); - float DFGcc = Fcc * Dcc * Gcc; + bd.direct_f_cc = F_Schlick(data.direct.LoH, cc_f0, f90); + bd.direct_d_cc = D_GGX(pbr.cc_roughness, data.direct.NoH_cc); + bd.direct_g_cc = G_GGXSmith(pbr.cc_roughness, data.direct.NoL_cc, data.common.NoV_cc); + float DFGcc = bd.direct_f_cc * bd.direct_d_cc * bd.direct_g_cc; float3 direct_specular_cc = DFGcc * data.direct.color * data.direct.NoL_cc * pbr.cc_strength; direct_specular_cc *= cc_energy_comp; direct_specular_cc *= remainder; direct_specular_cc = max(0, direct_specular_cc); specular += direct_specular_cc; - remainder *= saturate(1.0f - Fcc * pbr.cc_strength); + remainder *= saturate(1.0f - bd.direct_f_cc * pbr.cc_strength); #endif - float3 F = F_Schlick(data.direct.LoH, f0_color, f90); - float D = D_GGX(pbr.roughness, data.direct.NoH); - float G = G_GGXSmith(pbr.roughness, data.direct.NoL, data.common.NoV); + bd.direct_f = F_Schlick(data.direct.LoH, f0_color, f90); + bd.direct_d = D_GGX(pbr.roughness, data.direct.NoH); + bd.direct_g = G_GGXSmith(pbr.roughness, data.direct.NoL, data.common.NoV); - float3 direct_specular = (D * G) * F; + float3 direct_specular = (bd.direct_d * bd.direct_g) * bd.direct_f; direct_specular *= data.direct.color * data.direct.NoL; direct_specular *= energy_comp; direct_specular *= remainder; @@ -155,14 +149,14 @@ float4 brdf(Pbr pbr, LightData data) { { float3 remainder = 1.0f; #if defined(_CLEARCOAT) - float3 cc_specular_dfg = cc_dfg.xxx * cc_f0_color + cc_dfg.yyy; // filament 5.3.4.6 + float3 cc_specular_dfg = bd.ibl_dfg_cc.xxx * cc_f0_color + bd.ibl_dfg_cc.yyy; // filament 5.3.4.6 float3 cc_indirect_specular = data.indirect.specular_cc * cc_specular_dfg; cc_indirect_specular *= cc_energy_comp; specular += cc_indirect_specular; remainder -= cc_specular_dfg; #endif - float3 specular_dfg = dfg.xxx * f0_color + dfg.yyy; // filament 5.3.4.6 + float3 specular_dfg = bd.ibl_dfg.xxx * f0_color + bd.ibl_dfg.yyy; // filament 5.3.4.6 float3 indirect_specular = data.indirect.specular * specular_dfg; indirect_specular *= energy_comp; -- cgit v1.2.3