Search Unity

Why does this simple additive shader draw as non-additive?

Discussion in 'Shaders' started by Damocles, Sep 21, 2013.

  1. Damocles

    Damocles

    Joined:
    Jul 21, 2012
    Posts:
    46
    I have this simple shader:

    Code (csharp):
    1.  
    2. Shader "Swirly Glow Outline"
    3. {
    4.     Properties
    5.     {
    6.         _Color ("Main Color", Color) = (1,1,1,1)
    7.         _MainTex ("Base (RGB)", 2D) = "white" {}
    8.     }
    9.    
    10.     SubShader
    11.     {
    12.         Tags
    13.         {
    14.             "RenderType" = "Transparent"
    15.             "Queue" = "Transparent"
    16.         }
    17.         Lighting Off
    18.         ZWrite Off
    19.         Cull Off
    20.         Blend One One
    21.        
    22.         CGPROGRAM
    23.             #pragma target 3.0
    24.             #pragma surface surf BlinnPhong vertex:vert alpha
    25.             #include "UnityCG.cginc"
    26.            
    27.             sampler2D _MainTex;
    28.             float4 _Color;
    29.            
    30.             void vert (inout appdata_full v)
    31.             {
    32.                 v.texcoord = float4(sin(_Time.x), _Time.x, 0, 0)*1.5;
    33.              }
    34.            
    35.             struct Input
    36.             {
    37.                 float2 uv_MainTex;
    38.                 float4 color:COLOR;
    39.                 float4 screenPos;
    40.             };
    41.            
    42.             void surf (Input IN, inout SurfaceOutput o)
    43.             {  
    44.                 IN.uv_MainTex += IN.screenPos*4;
    45.                 half tex = tex2D(_MainTex, IN.uv_MainTex).r;
    46.                 o.Albedo = _Color.rgb;
    47.                 o.Alpha = 1;
    48.             }
    49.         ENDCG
    50.     }
    51.     Fallback "Particles/Additive"
    52. }
    which should result in additive blended, but for some reason shows up as normal blending, like so:



    The yellow outline shape should be additive, but it's not. I'm probably missing something really obvious, but I'm damned if I can see it. Can anyone shed some light on this?
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
  3. Damocles

    Damocles

    Joined:
    Jul 21, 2012
    Posts:
    46
    Ah, thanks Imaginary Human. It seems the alpha pragma specifically overrides the blending mode. That's a bit of a nuisance.
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Try decal:add. I'm not sure how decal:blend differs from the alpha directive, but the result of decal:add is an additively blended surface shader.