How to read custom stencil buffer data?

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:

  1. Assign every “3d pickable” object a unique ID
  2. Render those into stencil buffer.
  3. Get coordinates under mouse, read pixel from the stencil buffer on that location.
  4. 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!

I’m with you on this one! Sometimes the best solution is to reference exactly what was being rendered.
I too find it underwhelming that this is not a directly exposed function of custom stencil buffers.

If you don’t mind and are willing, could you share if (and what) you found as a solution to this?