I am really surprised there is no info on this supposedly trivial task.
I was able to enable custom stencil buffer.
I set stencil id on my mesh component.
I can visualize the stencil buffer using post processing material. It looks good.
I made a scene capture component and set it with a render target…
BUT I CAN"T UNDERSTAND HOW ON EARTH I ACCESS THAT STENCIL BUFFER!
No one ever wanted to do that from the user side in UE? I don’t want to render the stencil data on material, I want to read values from it. How would I go about this?
If anyone wonders why, here is my use case. I need to perform hit test (aka 3d picking) on a Text3D mesh. Now, the problem with the Text3D component is that doesn’t have bounds. And adding AABB doesn’t wrap it tightly (as it is axis aligned). I need a precise, topology based hit test on the Text’s glyph meshes. The only way to achieve it is to use stencil/color 3d picking (an old school trick for pixel perfect hit testing ). And it goes like this:
- Assign every “3d pickable” object a unique ID
- Render those into stencil buffer.
- Get coordinates under mouse, read pixel from the stencil buffer on that location.
- Look up for the related mesh using that pixel value.
If I need to do that with the RHI, that’s fine, but I would like to get any info or direction how to do that without spending hours reading UE source code.
Thanks!