Hi,
I would like to implement a realistic looking HUD system, a bit like this:
The graphics are only visible when viewed through the glass plate, and they look like they are floating in the air further away than the glass plate is.
To make it a bit more complex, I would also like to get this working in VR. I know how to draw the graphics with a world space UI, or just textured, transparent planes, but I don’t know how to clip it so it’s only visible through the glass plate. I really want to be able to move my head sideways and look around the glass plate and not see anything.
There are a couple of ways to do this. I believe it might be possible with UI Masks, but I don’t use Unity’s GUI systems much, so here are two alternatives.
First one is to use stencils. I would have a separate camera that only renders the UI using layers and the camera’s layer mask and have that camera be rendering to a render texture. Then have your glass use a custom shader that writes to the stencil buffer and place your UI on a plane also using a custom shader that only shows where the stencil has been written to by the glass. Technically you don’t need to use the render texture setup and could just have the UI floating in the world behind the glass, but again I’m not super familiar with Unity’s GUI stuff.
The second one would to use a parallax offset shader. Same render texture setup as above, but have the glass itself render the UI with an offset UV.
Both require custom shaders. Stencils might be a little easier as there’s enough documentation to get you there with out much help. I like the parallax offset method, but it definitely requires a lot more shader knowledge.
It’s also possible the Soft Mask asset could do this if the default Unity UI masks can’t.
Did that in the past for visualization purposes. The HUD is mirrored a few times before projected on the glass and therefore it seems like it is further away. So you have a 3D effect but the actual image is 2D.
What we did was to render the GUI in world space with the center camera and then used a custom shader that projected hat image on our artificial display (e.g. 1m in front of the windshield) with the same projection matrix. If you do not do AR and the GUI is flat hen this step is not necessary and you can place your GUI right at that distance.
Then we had to mask this by the actual display. I guess as it was rectangular we simply used GUI Mask for that purpose.
This provides an accurate result but maybe an offset depending on camera angle might work as well.