Archive 17/01/2023.

The object visible before one other regardless of the depth

Marcin

Hi,
I would like to have one object (StaticModel) always visible over one chosen another object (regardless of depth), something like using technique ‘NoTextureOverlay’, but my object should be rendered normally in relation to all other models (with depth test, etc…). Please, let me know how to do it?
Thanks in advance

Eugene

It’s quite tricky request because it contradicts usual rendering pipeline.
It’s possible with stencil tricks, but this is really hard way.
What’s the target hardware and how much objects you want to draw this way?

Marcin

Thanks for your answer, I was hoping that there is some simple way to do this…
I want to draw only one object this way. Target platform: PC with Windows.

Eugene

The problem is that you need depht test enabled to draw any non-convex object, so you need depth test on for both objects. On the other hand, you don’t want these objects to interfere with each other…

If you use forward lighting for these objects, the problem become even more severe.

Possible solution (no forward lighting) is:

  1. Draw object below, depth test on, depth write on.
  2. Redraw the object below with custom shader that sets depth to 1. depth test on, depth write on, depth function equal.
  3. Draw object above, depth test on, depth write on.
  4. Draw object below again, depth test on, depth write on, color write off.

In the result you will get object below, overlapping object above and valid depth for both objects.

TheComet

This might be of interest: How to control render order?