Search Unity

What's the right way to draw these things in very specific order?

Discussion in 'Universal Render Pipeline' started by JoeStrout, Jun 3, 2019.

  1. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm working on a portal system, which may involve a bunch of things that have to happen in very specific order:
    1. "local" scene geometry needs to draw as usual
    2. portal needs to draw with a shader that draws into the stencil buffer
    3. a distant plane needs to draw with a Z-write shader that essentially clears the depth buffer
    4. finally, "remote" (through the portal) scene geometry needs to draw with a stencil-test shader (that also clips by world position, though that's not important)
    Or, possibly, I rearrange things a bit like this:
    1. portal renders with a shader that draws into the stencil buffer
    2. "local" scene geometry draws with a stencil-test shader that avoids the stenciled area
    3. "remote" scene geometry draws with a stencil-test shader that limits drawing to the stenciled area (and by world position)
    Now that I look at it, that second one seems better. :) But either way, I have to render things in very specific order, and this order changes a bit during the game (as what's "local" vs. "remote" changes, etc.).

    Right now I'm doing this just by monkeying with the render queue in the materials. Is that the best way to do it? Or should I be looking at Command Buffers, or one of those new-fangled render pipelines (LWRP)? This will be on Oculus Go, where minimizing draw calls is important (and LWRP seems to have mixed success).