Search Unity

Question UI cutoff shader not resetting cutoff on Transform change

Discussion in 'Shaders' started by Only4gamers, Jul 12, 2022.

  1. Only4gamers

    Only4gamers

    Joined:
    Nov 8, 2019
    Posts:
    327
    Hello everyone,
    I am using a UI cutoff shader from here:
    https://medium.com/@cuilongchang/un...i-object-behind-a-transparent-ui-2700c12372c1

    Here is a video about what is happening.:


    I am updating the transform from inspector in the video. But as you can see previous cutoffs are not removing. I want to remove previous cutoffs and only keep the cutoff based on current transform.

    This is the shader for cutoff:
    Code (CSharp):
    1. Shader "Custom/TransparentCoverShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Base (RGB) Alpha (A)", 2D) = "white" {}
    6.         _Cutoff("Base Alpha cutoff", Range(0,.9)) = .5
    7.     }
    8.  
    9.     SubShader
    10.     {
    11.         Tags{ "Queue" = "Transparent+1" }
    12.         Offset 0, -1
    13.         ColorMask 0
    14.         ZWrite On
    15.  
    16.         Pass
    17.         {
    18.             AlphaTest Greater[_Cutoff]
    19.  
    20.             SetTexture[_MainTex]
    21.             {
    22.                 combine texture * primary, texture
    23.             }
    24.         }
    25.     }
    26. }