From f6beb386d0ac005dc1b4f88ff93cd8030443b97b Mon Sep 17 00:00:00 2001 From: David Labode Date: Wed, 4 Nov 2020 18:46:59 +0100 Subject: [PATCH] Apply ambient occlusion only to diffuse part of IBL. Not to direct lighting or specular. --- src/shaders/pbr.frag | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/shaders/pbr.frag b/src/shaders/pbr.frag index dc9ffa07..8444e664 100644 --- a/src/shaders/pbr.frag +++ b/src/shaders/pbr.frag @@ -537,6 +537,13 @@ void main() #endif #endif + float ao = 1.0; + // Apply optional PBR terms for additional (optional) shading +#ifdef HAS_OCCLUSION_MAP + ao = texture(u_OcclusionSampler, getOcclusionUV()).r; + f_diffuse = mix(f_diffuse, f_diffuse * ao, u_OcclusionStrength); +#endif + #ifdef USE_PUNCTUAL for (int i = 0; i < LIGHT_COUNT; ++i) { @@ -645,13 +652,6 @@ void main() color = (f_emissive + diffuse + f_specular + f_subsurface + (1.0 - reflectance) * f_sheen) * (1.0 - clearcoatFactor * clearcoatFresnel) + f_clearcoat * clearcoatFactor; - float ao = 1.0; - // Apply optional PBR terms for additional (optional) shading -#ifdef HAS_OCCLUSION_MAP - ao = texture(u_OcclusionSampler, getOcclusionUV()).r; - color = mix(color, color * ao, u_OcclusionStrength); -#endif - #ifndef DEBUG_OUTPUT // no debug #ifdef ALPHAMODE_MASK