diff options
Diffstat (limited to 'brdf.cginc')
| -rw-r--r-- | brdf.cginc | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -145,6 +145,20 @@ float4 brdf(Pbr pbr, LightData data) { dfg = float3(1, 1, 1); } +#if defined(_CLEARCOAT) + const float cc_f0 = 0.04f; + float2 cc_dfg_uv = float2(pbr.cc_roughness, data.common.NoV_cc); + float3 cc_dfg; + [branch] + if (textureExists(_DFG_LUT)) { + cc_dfg = _DFG_LUT.SampleLevel(bilinear_clamp_s, cc_dfg_uv, 0).rgb; + } else { + 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); +#endif + float3 F0_color = lerp(float3(f0, f0, f0), pbr.albedo.xyz, pbr.metallic); // Direct @@ -152,12 +166,12 @@ float4 brdf(Pbr pbr, LightData data) { float3 remainder = 1.0f; #if defined(_CLEARCOAT) - float cc_f0 = 0.04f; 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; float3 direct_specular_cc = DFGcc * data.direct.color * data.direct.NoL_cc * pbr.cc_strength; + direct_specular_cc *= cc_energy_comp; direct_specular_cc = max(0, direct_specular_cc); specular += direct_specular_cc; remainder = saturate(remainder - direct_specular_cc); @@ -203,9 +217,9 @@ float4 brdf(Pbr pbr, LightData data) { float3 remainder = 1.0f; #if defined(_CLEARCOAT) - float cc_f0 = 0.04f; - float Fcc = F_Schlick(data.common.NoV, cc_f0, 1.0f); - float3 indirect_specular_cc = Fcc * data.indirect.specular_cc * pbr.cc_strength; + float cc_single_scatter = cc_f0 * cc_dfg.x + cc_dfg.y; + float3 indirect_specular_cc = data.indirect.specular_cc * (cc_single_scatter * cc_energy_comp) * pbr.cc_strength; + indirect_specular_cc = max(0, indirect_specular_cc); specular += indirect_specular_cc; remainder = saturate(remainder - indirect_specular_cc); #endif |
