summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorclayjohn <claynjohn@gmail.com>2022-07-28 11:01:46 -0700
committerclayjohn <claynjohn@gmail.com>2022-07-31 15:45:21 -0700
commit0c65ed38a69c12f293e3718d73915eeeef2a7d83 (patch)
treed32bdaf9ec30eeefe7a1f0cb011f79565bbdc9ec /drivers
parent674ccdb244a8a7d806bdf024c1127226eff11976 (diff)
Treat specular less than 0.02 as occlusion
This is a very common hack used in almost all PBR renderers to allow removing specular contribution in dielectric materials
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/shaders/scene.glsl7
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 4f2be8bf60..2f9ffac89b 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -686,7 +686,10 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, float atte
#endif // LIGHT_ANISOTROPY_USED
// F
float cLdotH5 = SchlickFresnel(cLdotH);
- vec3 F = mix(vec3(cLdotH5), vec3(1.0), f0);
+ // Calculate Fresnel using cheap approximate specular occlusion term from Filament:
+ // https://google.github.io/filament/Filament.html#lighting/occlusion/specularocclusion
+ float f90 = clamp(50.0 * f0.g, 0.0, 1.0);
+ vec3 F = f0 + (f90 - f0) * cLdotH5;
vec3 specular_brdf_NL = cNdotL * D * F * G;
@@ -1107,7 +1110,7 @@ void main() {
float a004 = min(r.x * r.x, exp2(-9.28 * ndotv)) * r.x + r.y;
vec2 env = vec2(-1.04, 1.04) * a004 + r.zw;
- specular_light *= env.x * f0 + env.y;
+ specular_light *= env.x * f0 + env.y * clamp(50.0 * f0.g, 0.0, 1.0);
#endif
}