summaryrefslogtreecommitdiffstats
path: root/brdf.cginc
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2026-02-23 20:20:31 -0800
committeryum <yum.food.vr@gmail.com>2026-02-23 20:20:31 -0800
commit5fa1c0ec5b2b59db3858a7dfe9f4001eeeff8cc9 (patch)
tree5e1d7729e2fe52964c9d7c52aece72b4f2ecb3e5 /brdf.cginc
parent2d205f1f5df12b6e66f6cca1a05152b18d53c0d1 (diff)
Add ambient occlusion & normal filtering
Diffstat (limited to 'brdf.cginc')
-rwxr-xr-xbrdf.cginc29
1 files changed, 8 insertions, 21 deletions
diff --git a/brdf.cginc b/brdf.cginc
index 42ab988..1e920bb 100755
--- a/brdf.cginc
+++ b/brdf.cginc
@@ -116,7 +116,7 @@ float4 brdf(Pbr pbr, LightData data) {
// Direct
{
- float3 layer_attenuation = 1.0f;
+ float3 remainder = 1.0f;
#if defined(_CLEARCOAT)
float Fcc = F_Schlick(data.direct.LoH, cc_f0, f90);
@@ -125,10 +125,10 @@ float4 brdf(Pbr pbr, LightData data) {
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 *= layer_attenuation;
+ direct_specular_cc *= remainder;
direct_specular_cc = max(0, direct_specular_cc);
specular += direct_specular_cc;
- layer_attenuation *= saturate(1.0f - Fcc * pbr.cc_strength);
+ remainder *= saturate(1.0f - Fcc * pbr.cc_strength);
#endif
float3 F = F_Schlick(data.direct.LoH, f0_color, f90);
@@ -138,7 +138,7 @@ float4 brdf(Pbr pbr, LightData data) {
float3 direct_specular = (D * G) * F;
direct_specular *= data.direct.color * data.direct.NoL;
direct_specular *= energy_comp;
- direct_specular *= layer_attenuation;
+ direct_specular *= remainder;
direct_specular = max(0, direct_specular);
specular += direct_specular;
@@ -148,7 +148,7 @@ float4 brdf(Pbr pbr, LightData data) {
float Fd = Fd_Lambertian(data.direct.NoL);
#endif
float3 direct_diffuse = Fd * (1.0f - pbr.metallic) * pbr.albedo.xyz * data.direct.color;
- direct_diffuse *= layer_attenuation;
+ direct_diffuse *= remainder;
direct_diffuse = max(0, direct_diffuse);
diffuse += direct_diffuse;
}
@@ -156,25 +156,12 @@ float4 brdf(Pbr pbr, LightData data) {
// Indirect
#if !defined(FURNACE_TEST_DIRECT) && defined(FORWARD_BASE_PASS)
{
- float3 remainder = 1.0f;
-
-#if defined(_CLEARCOAT)
- 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
-
- float3 specular_tint = lerp(1, pbr.albedo.xyz, pbr.metallic);
- // Filament whitepaper section 5.3.4.6
- float3 specular_dfg = dfg.xxx * f0 + dfg.yyy;
- float3 indirect_specular = specular_tint * data.indirect.specular * specular_dfg;
+ float3 specular_dfg = dfg.xxx * f0_color + dfg.yyy; // filament 5.3.4.6
+ float3 indirect_specular = data.indirect.specular * specular_dfg;
specular += indirect_specular;
- //remainder = saturate(remainder - indirect_specular);
- float3 indirect_diffuse = pbr.albedo.xyz * data.indirect.diffuse * remainder * (1.0 - pbr.metallic);
+ float3 indirect_diffuse = pbr.albedo.xyz * data.indirect.diffuse * (1.0 - pbr.metallic);
diffuse += indirect_diffuse;
}
#endif