Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Modify depth buffer between camera passes

Discussion in 'General Graphics' started by Simon-O, Jun 16, 2016.

  1. Simon-O

    Simon-O

    Joined:
    Jan 22, 2014
    Posts:
    51
    I'm using two cameras One FP, the other an "Eye in the sky". Their movement is tied together, with the sky camera's movement being scaled. The sky camera has a depth higher than the FP camera so the result is superimposed.

    This allows me to create a "virtual model" of the scene which appears to be scaled-down and on a table. As the player makes changes to the world, the table model shows the changes.

    This works perfectly except that some of the FP geometry which should occlude the virtual model doesn't.

    My first thought was to mask in some way, but after some thought, it seems like the easiest thing to do would be to modify the depth buffer between camera passes.

    If the Sky camera is rendering everything at 1/20th scale, instead of clearing the depth buffer, I should be able to just scale the values by 20 before the sky camera renders.

    I'm aware there might be some funkiness in terms of handling the different near/far clip plane values, and I'd probably need to use doubles to do the transformation without losing too much accuracy, but I have no idea how to approach this.

    In short... How can I read and modify the depth buffer between camera passes, instead of clearing the depth buffer entirely?