Search Unity

Extremely basic shader modification

Discussion in 'Shaders' started by StarManta, Apr 21, 2014.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I'm awful at writing shaders, but alas, I need this one. ShaderLab has just never made the slightest bit of sense to me, so even the simplest shader (whose logic I understand fully), I just cannot figure out how to make ShaderLab work.

    It's incredibly basic - essentially all I need is a shader that is unlit, transparent, takes the RGB values from the main color, and multiplies the A value from the main color with the A value from the provided texture (I'm ignoring its RGB data entirely).

    The following shader is what I've come up with so far (it's a one-line change from the wiki's AlphaSelfIllum shader), and it does most of those things, except that the transparency comes entirely from the texture, and adjusting the main color has no effect. So what am I missing?

    Code (csharp):
    1.  
    2. Shader "Pet/PatternShader" {
    3.     Properties {
    4.         _Color ("Color Tint", Color) = (1,1,1,1)
    5.         _MainTex ("Alpha (A)", 2D) = "white"
    6.     }
    7.     Category {
    8.        Lighting On
    9.        ZWrite Off
    10.        Cull Back
    11.        Blend SrcAlpha OneMinusSrcAlpha
    12.        Tags {Queue=Transparent}
    13.        SubShader {
    14.             Material {
    15.                Emission [_Color]
    16.             }
    17.             Pass {
    18.                SetTexture [_MainTex] {
    19.                       Combine Primary, Texture * Primary
    20.                }
    21.             }
    22.         }
    23.     }
    24. }
    25.  
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I guess something like this should work:
    Code (csharp):
    1.  
    2.     Shader "Pet/PatternShader" {
    3.         Properties {
    4.             _Color ("Color Tint", Color) = (1,1,1,1)
    5.             _MainTex ("Alpha (A)", 2D) = "white"
    6.         }
    7.         Category {
    8.            Lighting On
    9.            ZWrite Off
    10.            Cull Back
    11.            Blend SrcAlpha OneMinusSrcAlpha
    12.            Tags {Queue=Transparent}
    13.            SubShader {
    14.                 Pass {
    15.                    SetTexture [_MainTex] {
    16.                           constantColor [_Color]
    17.                           Combine constant, texture * constant
    18.                    }
    19.                 }
    20.             }
    21.         }
    22.     }
    23.  
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That worked! Thanks for the help :)