Search Unity

Alpha blending Shader - Use property in ConstantColor (?)

Discussion in 'Shaders' started by Cjreek, Sep 16, 2013.

  1. Cjreek

    Cjreek

    Joined:
    Apr 23, 2013
    Posts:
    33
    Hi,

    I am a total shader noob and started looking at some shaderlab reference pages and tutorials a view minutes ago.
    I wanted a simple (?) alpha blending shader for my 2D game (it's going to be applied to planes).

    That's what I got:

    Code (csharp):
    1. Shader "Custom/Diffuse Alpha" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _Alpha ("Alpha Value", Range (0.00, 1.00)) = 1.00
    5.     }
    6.    
    7.     SubShader
    8.     {
    9.         Tags { Queue = Transparent }
    10.        
    11.         Blend SrcAlpha OneMinusSrcAlpha
    12.        
    13.         Pass
    14.         {
    15.             SetTexture[_MainTex]
    16.             {
    17.                 constantColor(1.0,1.0,1.0,_Alpha)
    18.                 combine texture, texture * constant
    19.             }
    20.         }
    21.     }
    22.    
    23.     FallBack "Diffuse"
    24. }
    25.  
    This works great, BUT it won't let me use the _Alpha property to specify the constant color :-(
    Why? :-(

    It feels like I'm THIS close to the solution. Is it just a little syntax thing?

    Edit: OK I got it.

    It's just

    Code (csharp):
    1. constantColor(1.0,1.0,1.0, [_Alpha])
     
    Last edited: Sep 17, 2013