Possible issue with shadowGenerator on needDepthPrePass meshes

While trying to get partially visible meshes to render correctly, I’ve found setting needDepthPrePass to true fixes issues with occluded mesh faces rendering on top. However I found that setting needDepthPrePass to true stops shadows from being generated for that mesh, but only if the visibility of the mesh is set to 1. If visibility is set to less than 1 (and the shadow generator is setup for transparent shadows) they still cast.

Example playground of a mesh jumping between 1 and .9999 visibility with needDepthPrePass set to true Babylon.js Playground

Is there something I’m not understanding with how needDepthPrePass and shadow generators interact or is this a bug? Any good workaround for this, other than rendering a mesh at .9999 visibility, since I imagine doing that has a bigger performance impact?

Hi @jlivak - maybe @Evgeni_Popov or @CraigFeldspar can help on this?

Sounds like a bug to me as needDepthPrePass should not prevent the rendering but is actually only usefull on Opaque if you have unsorted rendering to limit overdraw.

@Evgeni_Popov might have a look tomorrow.

Ok, thanks for the quick feedback all. I only have it on opaque meshes that often change in opacity/visibility.

I’ve thought of pre-calculating and caching versions of all the their materials with needDepthPrePass set to false and swapping the materials when they become fully opaque as another work-around.

This PR will fix the problem:

2 Likes

Awesome, thanks for the quick turn-around on that fix!