I have two objects in my 3D scene where one object partially covers the other object. I want to draw the outline / wireframe of the covered object on top of the covering object to give the user a glimpse of the covered object. I am aiming for a similar effect as in the RTS Age of Empires 2, where units that are visually covered by walls are displayed as wireframes as seen in this screenshot:
I am not concerned about the wireframe drawing itself, but how to partially make it wireframe.
My concept to achieve this so far is:
- Draw the covering object and draw it also to the stencil buffer.
- Draw the covered object two times, both time with z-Test disabled.
- One time with the regular material, everywhere it is not covered by the stencil
- second time with the wireframe material, everywhere where it is covered by the stencil.
- Is this the right approach?
- Is there a standard way to draw a Mesh two times with different materials?
- I think internally, the mesh has several hidden “second” materials, for example for edge rending, glow etc.
Otherwise, I have to clone the mesh or switch the material during rendering and I am afraid this is not a supported usecase.