For my application, I need some fine-grained control over render order for a number of reasons. Thankfully the layers system offers an easy and convenient way to render specific objects in a specific order.
camera.layers.set(1); renderer.render(scene, camera); // Render some objects with depthRead/depthWrite set differently maybe camera.layers.set(2); renderer.render(scene, camera); // Apply some postprocessing effects to specific objects camera.layers.set(3); renderer.render(scene, camera); // Render world-space UI after postprocessing camera.layers.set(4); renderer.render(scene, camera);
The above pattern works fine, is flexible, and (I think) is perfectly performant. However, I have found that I need more granular control over shadow map rendering. In the above example, I have an object on layer 1 that needs to show the shadow of an object on layer 3.
To fix the issue, I’d need to render only the shadow map with both layers 1-3 active before layer 1 is rendered ‘for real’. However, I don’t see any way to actually do this.
renderer.shadowMap.render() is exposed but calling it directly results in errors as the render state isn’t set up correctly.
Does anyone have any ideas as to how I can achieve what I need here?