KhronosGroup / glTF-Sample-Viewer

Physically-Based Rendering in glTF 2.0 using WebGL
Apache License 2.0
1.21k stars 229 forks source link

Occlusion map ignored when enabling only "Punctual Lighting" #526

Closed alexGuntha closed 4 months ago

alexGuntha commented 4 months ago

Hi, I'm using glTF-Sample-Viewer for a viewer I'm currently implementing, and models that feature an occlusion map do not behave as I expect when enabling only Punctual Lighting. Two screenshots showcasing the difference between IBL and Punctual, which is very visible in the Corset model: ibl punctual

For reference, here is something closer to what I expect (unless I misunderstood something about lighting) punctual-custom This viewer actually uses a directional light casting from the camera, which I believe in this case should look pretty similar to a point light at the same position.

I believe the issue is in source/Renderer/shaders/pbr.frag: the occlusion is computed only on the ..._ibl values, which are not updated when only USE_PUNCTUAL is defined. The comment suggests it's intentional, but I don't understand why?

#ifdef HAS_OCCLUSION_MAP
    ao = texture(u_OcclusionSampler,  getOcclusionUV()).r;
    diffuse = f_diffuse + mix(f_diffuse_ibl, f_diffuse_ibl * ao, u_OcclusionStrength);
    // apply ambient occlusion to all lighting that is not punctual
    specular = f_specular + mix(f_specular_ibl, f_specular_ibl * ao, u_OcclusionStrength);
    sheen = f_sheen + mix(f_sheen_ibl, f_sheen_ibl * ao, u_OcclusionStrength);
    clearcoat = f_clearcoat + mix(f_clearcoat_ibl, f_clearcoat_ibl * ao, u_OcclusionStrength);
#else
    diffuse = f_diffuse_ibl + f_diffuse;
    specular = f_specular_ibl + f_specular;
    sheen = f_sheen_ibl + f_sheen;
    clearcoat = f_clearcoat_ibl + f_clearcoat;
#endif
UX3D-kanzler commented 4 months ago

Yes, this is intentional. The question whether occlusion should affect IBL and punctual lights was discussed in these threads:

https://github.com/KhronosGroup/glTF/issues/1427 https://github.com/KhronosGroup/glTF/issues/915

It was concluded that occlusion is not affected by direct light sources.

alexGuntha commented 4 months ago

All right, thank you, I should have been more careful about this one line in the glTF 2.0 spec image