Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Alpha Emissive Shader breaks going from Unity 4.6 -> Unity 5

Discussion in 'Shaders' started by BrodyB, May 14, 2015.

  1. BrodyB

    BrodyB

    Joined:
    Dec 17, 2014
    Posts:
    10
    Hey there!

    I'm working on upgrading a project from Unity 4.6 into Unity 5, which has gone pretty smoothly! The one issue I'm having trouble getting around is this one simplistic shader that was working fine before, but now doesn't work as intended. No console errors, though!



    As you can see above, we have a surface with a repeating texture that the shader colors with a ramp texture. In Unity 4.6 (left), totally as expected, but in Unity 5 (right) the alpha information is almost completely lost. If I remove the o.Emission = c.rgb... line, the object has alpha, but is completely unlit.

    Here's the shader in question:

    Code (CSharp):
    1. Shader "BloodFlow" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
    5.         _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    6.     }
    7.  
    8.     SubShader {
    9.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    10.         LOD 200
    11.  
    12.         CGPROGRAM
    13.         #pragma surface surf Lambert alpha
    14.  
    15.         sampler2D _MainTex;
    16.         sampler2D _LightMap;
    17.         fixed4 _Color;
    18.  
    19.         struct Input {
    20.             float2 uv_MainTex;
    21.             float2 uv2_LightMap;
    22.         };
    23.  
    24.         void surf (Input IN, inout SurfaceOutput o) {
    25.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
    26.             half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
    27.             o.Emission = c.rgb * lm.rgb * 2;
    28.            
    29.             o.Alpha = c.a;
    30.         }
    31.         ENDCG
    32.     }
    33. }
    I don't see anything in the shader upgrade guide that tells me alpha on transparent Lambert has changed. Is there something obvious I'm missing?

    Thanks for any help!