How to get custom stencil depth value or rendering group id in custom Shader code?

Hello ,

I want to distinguish different objects in custom shader and one useful approach is to set custom stencil value for mesh and get this value in custom shader. I don’t know if babylon has some releative functions or not.

The most similar info I find is the renderingGroupId in RenderingManager, but I donnot how to get this value in custom shader, and not sure renderingGroupId is really useful for my purpose.

Thanks first.

You can not read this from a shader, the only things you would have access to are textures.

So either you rely on shaders to prevent rendering for instance if it already has a certain value or you need to render to texture to fetch the info from your shader.

Sorry, I’m not understand about the certain value. Could you please provide a PG about how to get some info about instance in the custom shader ?

You need a render target and a custom shader where you would render one different color per group. then on your main rendering you could read from this texture to know which object it is.

Get it, thanks!