diff options
| author | yum <yum.food.vr@gmail.com> | 2026-03-03 18:10:28 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2026-03-03 18:10:32 -0800 |
| commit | 23014acf1bd834744018425e7aeba314a10e12f9 (patch) | |
| tree | 161c736c37ed8f3d687307304f96688c0801ea95 | |
| parent | f186fd5523b313e90da8f99ab752d40a0012cfca (diff) | |
Add energy compensation term; rough metals look right under direct lighting now
| -rwxr-xr-x | brdf.cginc | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -93,6 +93,8 @@ float4 brdf(Pbr pbr, LightData data) { } else { 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 - 1.0f); #if defined(_CLEARCOAT) const float cc_f0 = 0.04f; @@ -105,14 +107,9 @@ float4 brdf(Pbr pbr, LightData data) { cc_dfg = float3(1, 1, 1); } float cc_Ess = max(cc_dfg.y, 1e-4f); - //float cc_energy_comp = 1.0f + cc_f0 * (rcp(cc_Ess) - 1.0f); - float cc_energy_comp = 1; + float cc_energy_comp = 1.0f + cc_f0 * (1.0f / cc_dfg.xxx - 1.0f); #endif - float3 f0_color = lerp(f0, pbr.albedo.xyz, pbr.metallic); - //float3 energy_comp = 1.0f + f0_color * (rcp(dfg.yyy) - 1.0f); - float3 energy_comp = 1.0f; - // Direct { float3 remainder = 1.0f; @@ -158,6 +155,7 @@ float4 brdf(Pbr pbr, LightData data) { float3 specular_dfg = dfg.xxx * f0_color + dfg.yyy; // filament 5.3.4.6 float3 indirect_specular = data.indirect.specular * specular_dfg; + indirect_specular *= energy_comp; specular += indirect_specular; float3 indirect_diffuse = pbr.albedo.xyz * data.indirect.diffuse * (1.0 - pbr.metallic); |
