Performance drop with layer masked-out lights

Hello, for some special effects, I like to have scene rendered twice, to two WebGLRenderTargets, only with different camera.layers.mask settings. (I then do some postprocessing on both render targets together to get final image.)

When it renders scene for second time and some light is masked out by modified layers, it recompile shaders.
In WebGLRenderer initMaterial(), it match condition (because different light combination)
} else if ( program.code !== code ) {
// changed glsl or parameters
releaseMaterialProgramReference( material );
and then it goes into programCache.acquireProgram() …


Is there some way, how to have two renders, different only by layers/lights?
I din’t want two scenes because of animations.

THREE.Layers is not intended to enable selective lighting in three.js apps. For now, use different scenes like in this updated fiddle:

Support for real selective lighting is on the roadmap. But honestly I can’t tell when it is actually added.

1 Like