Draw spatial as wireframe if occluded

I would like to draw a spatial with different material if it is occluded by other geometry. If the spatial is partly occluded only that part should be drawn differently. Think of an RTS where some units are behind a mountain and they are drawn in a different shade so the player can still see them. How to achieve that effect? Is there an easy way or do I have to write a shader for that? Thank you for helping!

If they are behind the mountain then they will not be drawn at all…

You would need to swap the model out for another one (or swap the material) and turn off depth test on the 2nd one.

Thx for the quick answer. But how do I know if the spatial is occluded? I can do a ray test. But what if only parts of the geometry associated with that spatial are occluded? I would like to draw only the occluded part with a different material then. Using the stencil buffer or render buckets came to my mind. But my knowledge about these is very limited. I looked through the documentation but couldn’t figure out a way how to achieve that effect.

I would image something like this. First draw all scenery, writing z-buffer. Then, draw wireframe versions of all units (all wireframe, regardless of occlusion), ignoring z-buffer (and not writing anything to it). Then, draw normal versions of all units, this time again with normal z-buffer behaviour. It should be drawn over wireframe everywhere where units are not obscured by terrain and leave wireframes only on terrain parts.

4 Likes

Yeah, this works. It doesn’t look good with the wireframe because some pixels of the frame are not covered by the version that is drawn solid. But I will just use a darkened version of the original material instead. Thanks for helping me!

1 Like