Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question X-ray effect with multiple cameras

Discussion in 'Shaders' started by maezir, May 2, 2021.

  1. maezir

    maezir

    Joined:
    Sep 30, 2018
    Posts:
    1
    I have 2 cameras in my game, one rendering in orthographic (the main camera), and a second one rendering in perspective. Each camera targets different layers, and the perspective camera is set to "Don't clear" to allow the two views to render on one another.

    The game is primarily orthographic, however some parts of the game require 3D objects to pass over the orthographic sprites and render an altered / x-rayed version of the sprite. Here's an example of what I'm trying to achieve:



    In all cases the 3D object will be rendered in front of the orthographic sprites, if that matters.

    I'm struggling to get this to work. I can get it to function with a stencil shader if the x-ray sprite is rendered on the same culling layer as the 3D object, but this of course warps the sprite due to the perspective projection. No matter what I do, I can't get the stencil shader to work if they are on different layers.

    Can anyone offer any guidance on achieving this, or whether I'm even on the right track? Is there a different way to do this altogether?