Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ZWrite mask shader with mesh border blending (is possible?)

Discussion in 'Shaders' started by tucano, Jun 7, 2017.

  1. tucano

    tucano

    Joined:
    Nov 9, 2011
    Posts:
    30
    Hello, I have a Mesh Filter generated dynamically that I use to create a light effect in a 2D game:

    Screen Shot 2017-06-07 at 15.02.39.png

    Screen Shot 2017-06-07 at 15.08.29.png

    Here I have the Mesh attached to the light at Z=1.0 and a Black sprite (the shadow) at Z=1.01

    The shader is super-simple:

    Code (CSharp):
    1. Shader "UselessMachine/Masked/MaskBlend" {
    2.  
    3.     SubShader {
    4.         // Render the mask after regular geometry, but before masked geometry and
    5.         // transparent things.
    6.    
    7.         Tags {"Queue" = "Geometry+10" }
    8.    
    9.         // Don't draw in the RGBA channels; just the depth buffer    
    10.         // Writing ColorMask 0 turns off rendering to all color channels.
    11.         ColorMask 0
    12.         ZWrite On    
    13.    
    14.         // Do nothing specific in the pass:
    15.    
    16.         Pass {}
    17.     }
    18. }
    I would like to add some kind of alpha gradient on the border of the mesh. Is this possible?