Search Unity

Combine simple blend zero one render-nothing shader into another shader?

Discussion in 'Shaders' started by JeffersonTD, Jun 12, 2020.

  1. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    I have a very simple shader:

    Code (csharp):
    1.     SubShader
    2.     {
    3.         Tags { "RenderType" = "Opaque" "Queue"="Geometry-1" }
    4.         LOD 100
    5.  
    6.         Blend Zero One
    7.  
    8.         Pass
    9.         {
    10.  
    11.         }
    12.     }
    And it does its job : it renders nothing, as I want it to. I've thus far used this together with another shader, that's set to another object, whereby the object with this simple shader is behind the object that has the other shader, that's doing more complex things.

    This combination works pretty nicely, but ideally I'd like to have the two in the same object (one reason being that one effect in the other one causes artifacts I don't want, if the "render nothing" mesh is too close). So my question is: can I somehow combine this with another shader? By eg. having multiple passes, first simply blending Zero One this and then the other one doing its own thing? I've been trying, but it doesn't seem to work. There probably is a way to do that though, or is there?

    One alternative I suppose could be to modify the mesh a bit (it's always the same simple procedurally created mesh so not a problem in this case) and make it have two materials, and that way I could potentially be able to reduce that extra object away, but that wouldn't necessarily get rid of the artifact issue.
     
  2. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Any ideas? Is there some way to combine this with other effects in a single shader? I want it to clear whatever would be rendered by this camera, but still do other effects on whatever was on the screen. This works with separate objects, but trying to get them in the same material is apparently really problematic.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,339
    I'm not sure I fully understand what you're trying to accomplish.

    The short version to your basic question is copy
    Pass { Blend Zero One ZWrite On }
    into the
    SubShader
    of your shader and you're done. The longer answer is "it depends on exactly what you're trying to do."

    And the answer may be that it's not possible to do what you're wanting to do because the order of operations you're trying to do it in won't do what you want.
     
    JeffersonTD likes this.
  4. JeffersonTD

    JeffersonTD

    Joined:
    Feb 5, 2013
    Posts:
    268
    Thanks for the comment. Yeah, I can easily imagine my goal here isn't necessarily the most clear.

    I've wanted to do an intersection effect like in this video:

    and combine that (and some distortions too) with the Blend Zero One object, both residing on simple planes (plain Zero One on a simple quad, the other one having more tris). Now while these have worked, the intersection effect has caused artifacts, if I put the Blend Zero One object too close to the other plane and that's been my problem.

    Well, with some help I've now found a solution that gets rid of the problem. The key here seems to be using Offset on the main shader. Currently the system uses three passes (2 in the main shader + 1 in the simple one), so I'll still investigate further to maybe get it down to 2, and also to get my head around better as to how these things work.