Search Unity

How to use my AlphaTest value in my surface shader ?

Discussion in 'Shaders' started by kev42100, Oct 10, 2011.

  1. kev42100

    kev42100

    Joined:
    Apr 17, 2010
    Posts:
    61
    Hi all,

    I wanna use my variable _Cutoff in my surfaceshader, but how i can fix these issues ?


    Code (csharp):
    1.  
    2. Properties
    3. {
    4.    ....
    5.     _Cutoff ("Alpha cutoff", Range (0,1)) = 0
    6.    ....
    7. }
    8.  
    9. SubShader
    10.     {
    11.       Tags { "Queue" = "Geometry" }
    12.    
    13.    
    14.       CGPROGRAM
    15.       #pragma target 3.0
    16.       #pragma surface surf SimpleSpecular vertex:vert alphatest:_Cutoff
    17.  
    18.      uniform float _Cutoff;
    19.      ....
    20.   }
    21.  
    The compiler displays :

    "Program 'vert_surf', declaration of "_Cutoff" conflicts with previous declaration at (45) at line 197"
    "Program 'frag_surf', declaration of "_Cutoff" conflicts with previous declaration at (45) at line 197"
    "GLSL vertex shader: ERROR: 0:467: '_Cutoff' : redefinition at line 23"

    If I remove this line : uniform float _Cutoff;
    The compiler doesn't know this variable ...


    Thus what's wrong in my code ?

    Thanks in advance !
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Strange.

    In your surface shader surf function, try using...
    Code (csharp):
    1. clip(s.Alpha - _Cutoff);
    ...and removing the alphatest:_Cutoff argument.

    As far as I can tell it does exactly the same thing.
     
  3. Waffle1434

    Waffle1434

    Joined:
    Jun 1, 2016
    Posts:
    5
    It appears the compiler is complaining because _Cutoff is defined by the surface shader pragma as well.
    Remove "uniform float _Cutoff;" and it should work.