Search Unity

Shader not working anymore in Unity5

Discussion in 'Shaders' started by Crax, Mar 25, 2015.

  1. Crax

    Crax

    Joined:
    Apr 11, 2013
    Posts:
    13
    I switched to Unity5 and after some issues with some animation controllers, i found a problem with a shader:

    Code (csharp):
    1. Shader "Custom/CameraNoise" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _alpha ("Transparency", Range(-2, 1)) =0.2
    5.     }
    6.     SubShader {
    7.         Tags { "RenderType"="AlphaTest " }
    8.         LOD 200
    9.        
    10.         CGPROGRAM
    11.          #pragma surface surf Lambert alpha
    12.  
    13.         sampler2D _MainTex;
    14.  
    15.         struct Input {
    16.             float2 uv_MainTex;
    17.         };
    18.         half _alpha;
    19.         void surf (Input IN, inout SurfaceOutput o) {
    20.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    21.             o.Albedo = c.rgb;
    22.             o.Alpha = _alpha;
    23.             o.Emission = 0.1;
    24.         }
    25.         ENDCG
    26.     }
    27.     FallBack "Diffuse"
    28. }
    29.  
    It has an alpha value and a MainTexture, both setted by code with an array of Texture2D and a float.

    The problem is that back in Unity4 it had no problems, but now the Alpha value doesn't change anything.
     
  2. UnityGuillaume

    UnityGuillaume

    Unity Technologies

    Joined:
    Mar 16, 2015
    Posts:
    123
    alpha in Unity5 is premultiplied. Mean that the engine expect the albedo (rgb) to be already mutiplied by the alpha in the texture.

    If you want Unity 4 behaviour, change alpha by alpha:fade

    Code (CSharp):
    1. #pragma surface surf Lambert alpha
    by

    Code (CSharp):
    1. #pragma surface surf Lambert alpha:fade