Search Unity

Resolved A GrabPass that includes objects with transparency behind? Possible?

Discussion in 'Shaders' started by jgmakes, Aug 10, 2020.

  1. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    Can a grab pass ever include visual data from materials behind it that have transparency?

    I'm assuming a grab pass is what the SceneColor node in shader relies on, and I can't seem to use it to include transparent objects either. I'm assuming this has to do with keeping the system efficient, and that transparent content is probably rendered afterwards.

    Is there a way to get around this? Forcing this material/shader with the grab pass to execute last? I haven't found a solution.

    Unfortunately nearly all my objects have some transparency because all of them either fade or build-in (e.g. progressing through a voronoi with an decreasing step limit).

    Has anyone ever dealt with this?

    (FYI using URP)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    Yes.

    Nope.

    The grab pass and URP Scene Color node are fundamentally different. The SRPs do not support grab passes, which is why the Scene Color node requires enabling the Opaque Texture in the pipeline asset. The name of which says something about how it's created.

    First, the grab pass works by making a copy of the current render target at the moment the grab pass is called. For the built in render pipelines, this can be either a generic or named grab pass. The generic grab pass runs every time it's called, meaning you could have a single shader that copies the current state of the rendered frame, render the shader pass using that grab, then captures the output of that for the next pass. And this will happen for every object using that shader. For named grab passes it only runs the first time it's used in the frame, so if multiple objects using the shader only the first one that is drawn does the copy and all subsequent draws reuse that first object's grab texture.

    In contrast the URP & HDRP's Opaque Texture makes a copy of the current state of the rendered frame just before starting to draw the transparent queue range. It always makes a copy at that point if it's enabled in the pipeline asset, even if nothing visible in the view uses the Scene Color node. And it means anything that's transparent will not be visible in the Scene Color node, and there's really nothing you can do about that.
     
    Beloudest, PeterAndrewB and jgmakes like this.
  3. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    Thanks so much bgolus!

    So if I want to create a shader that manipulates the pixel colors of a transparent object behind it (e.g. refraction in glass), the only means is using a GrabPass shader? It sounds like there's no way to do that in ShaderGraph. I can't remember why I moved from writing this as a shader to a shadergraph in the first place (perhaps the convenience of the built in Voronoi node)... but apparently it's time to move back :)

    And thanks a lot for the details on named vs generic grab passes. I imagine the latter must be much more expensive.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,336
    Basically yes. You can use a GrabPass shader, or make your transparent objects render during the opaque queue range (which comes with a ton of headaches, but is possible), or use camera stacking.

    Shader Graph has a lot of advantages ... flexibility is not one of them.
     
    PeterAndrewB and jgmakes like this.
  5. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    You know I'm living in a little mountain town right now with a limited supply of Ibuprofen, so maybe I'll bypass option 2. Didn't realize that was even possible. So that would be setting it to just under 2500? Oh no, I feel a headache coming on...

    So thankful for all the insight!
     
    PeterAndrewB likes this.
  6. chino01

    chino01

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hello I have stumbled upon the same issue, so did you make any progress on that ?
     
  7. yano_123

    yano_123

    Joined:
    Aug 24, 2012
    Posts:
    41