Search Unity

Question How can I create an intersecting x-ray shader??

Discussion in 'Shader Graph' started by adrian-taylor09, Oct 25, 2019.

  1. adrian-taylor09

    adrian-taylor09

    Joined:
    Dec 22, 2016
    Posts:
    63
    Hi all,

    Looking for a way in shader graph to create a shader that can replicate the effect in this video:


    In the video you can see that there is a sphere (or some other shape) attached to the camera, and the geometry that is inside of this sphere is rendered with a transparent color. Also, the effect fades in rather than pops in.

    How would I go about creating this effect?
    Any help is appreciated!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    The way the above effect was accomplished was by rendering the vehicle, as well as some internal geometry, using a depth fading additive shader to a separate full screen render target. When you get close to an object, they fade out the base material and fade in that texture on top, eventually clipping the geometry that's too close.
     
  3. adrian-taylor09

    adrian-taylor09

    Joined:
    Dec 22, 2016
    Posts:
    63
    Thanks @bgolus for the reply.

    I think I understand how that works but I’m not sure how I could implement that into my own project.

    Is there a way, using LWRP and shader graph, to achieve this?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Without writing c# code? Nope. Unity intentionally never implemented support for multi-camera rendering for their SRPs, and don't have an easy to use built in concept of replacement shaders like the built in rendering paths do, at least not one that renders to a separate render texture. It can be done, but you have to write all the code to do it yourself. They added the concept of a custom render pass, and at first that included the option to render to a new render texture, but the latest versions removed that. All examples I know of that show how to do a replacement shader like setup no longer work either as they were written for older versions of the LWRP and the code for that has changed so much that after just a month or two most examples no longer work. Good news is the LWRP is stable now so that won't be a problem going forward. The bad news is that's because Unity abandoned the LWRP and it won't ever be updated again (more accurately, they created a new render pipeline called the Universal Render Pipeline that started as a copy of the LWRP, but has since diverged so much that code written for the LWRP doesn't work in it anymore). Thus is the problem with working on any system that's still in development.
     
  5. adrian-taylor09

    adrian-taylor09

    Joined:
    Dec 22, 2016
    Posts:
    63
    Ok thanks for the explanation, I appreciate your help.

    can you think of any alternative means to approximate this effect using LWRP (or URP) and shader graph?

    my use case is exactly the same as the video: make geometry close to the camera appear transparent, the fading in and out is a bonus