0beqz / realism-effects

SSGI, Motion Blur, TRAA - Effects to enhance your three.js scene's realism
https://realism-effects-obeqz.vercel.app/
MIT License
1.44k stars 70 forks source link

Env maps to goes black for other WebGLRenderer with MeshStandardMaterial. #42

Open benzsuankularb opened 8 months ago

benzsuankularb commented 8 months ago

I have 2 WebGLRenderer(Canvas) in my web. However, The second one didn't make use of realism effects. But the env map goes black when realism effects were used in the first canvas.

I've dug a bit and found the patches of ShaderChunk.envmap_physical_pars_fragment (https://github.com/0beqz/realism-effects/blob/main/src/ssgi/utils/Utils.js)

I also found the SSGIEffect is trying to disable the patch at the end of each frame. (https://github.com/0beqz/realism-effects/blob/main/src/ssgi/SSGIEffect.js) But that's not working when another renderer tries to use envmap_physical_pars_fragment along the way.

globalIblRadianceDisabledUniform.value = true

this.rAF = requestAnimationFrame(() => {
    this.rAF2 = requestAnimationFrame(() => {
        globalIblRadianceDisabledUniform.value = false
    })
})
0beqz commented 7 months ago

Hey, thanks for reporting.

I see, that was a somewhat hack I implemented. The idea is to disable only specular and not diffuse environment lighting for all materials. Well with SSGI where both these things are calculated I can fix it by enforcing that the envMapIntensity of the scene is set to 0. However, with SSR it's more complicated. So it looks like I need to fix it by unsetting that after the render and not the frame. I'll look into it.