Search Unity

Question Rendering dynamic transparency to show occluded objects (Shader)

Discussion in 'Universal Render Pipeline' started by TheJetstream, Jul 9, 2020.

  1. TheJetstream

    TheJetstream

    Joined:
    Jan 7, 2019
    Posts:
    4
    Hello everyone,

    I am currently trying to implement something like an X-Ray Shader. I want to "cut holes" into surfaces that are occluding the view on one (ore more) target objects.

    I found the work of Niklas Elmqvist who worked on that problem: http://users.umiacs.umd.edu/~elm/projects/dyntrans/dyntrans.pdf
    This gave me the idea to generate an alpha mask, that contains information on the position of the target objects, the basic principle is this:
    1. Generate a alpha mask for target objects: at the pixels of the target object this alpha mask (texture) contains the value "0", else "1"
    2. Apply this alpha mask on all objects that are not target objects (and are in front of the target object)
    I know that Unity supports these Masks, but how would I go about rendering this alpha texture and passing it to the shader for the distracting objects?
    Or is this approach completely "wrong" (too slow, not possible in Unity, ...).

    I know that I can achieve something similar using ZTest, but I want to habe some extra space around the actual object to be visible as well so that the context of the object in the scene is still clear.

    The end result should look something like this: