Search Unity

Shader not properly working after Update to 5.5.0f3

Discussion in 'Shaders' started by S0wbear, Dec 2, 2016.

  1. S0wbear

    S0wbear

    Joined:
    Jan 14, 2016
    Posts:
    9
    Hey guys!
    I have a (hopefully trivial) problem with a shader after upgrading to Unity 5.5 - the objects that use this shader are now fully transparent both in the editor and game view.
    In play mode, i can tell by the deforming outline that the vertices are being moved, it's just that all surfaces are transparent as you can see in the image below.

    Here is the code:
    Code (CSharp):
    1. Shader "Custom/PlantSway" {
    2.     Properties{
    3.         _MainTex("Texture", 2D) = "white" {}
    4.         _WaveAmplitude("Wave Amplitude", Range(1, 10)) = 1
    5.         _WaveSpeed("Waves Speed", Range(1, 15)) = 1
    6.         _WaveMulti("Wave Multipiler", Range(0.0,0.005)) = 0.001
    7.         _WaveAmplitudeH("Wave Amplitude horizontal", Range(0.001, 0.02)) = 0.01
    8.         _WaveSpeedH("Waves Speed horizontal", Range(1, 15)) = 1
    9.         //_WaveMultiH("Wave Multiplier horizontal", Range(0.0,0.05)) = 0.001
    10.     }
    11.  
    12.     SubShader{
    13.         Tags{ "RenderType" = "Opaque" }
    14.         CGPROGRAM
    15.         #pragma surface surf Standard vertex:vert addshadow alphatest:_Cutoff
    16.         struct Input {
    17.             float2 uv_MainTex;
    18.         };
    19.  
    20.         half _WaveHeight, _WaveAmplitude, _WaveSpeed, _WaveMulti, _WaveAmplitudeH, _WaveSpeedH;// , _WaveMultiH;
    21.         void vert(inout appdata_full v) {
    22.             fixed _PI2 = 6.28318;
    23.  
    24.             fixed centerDist = abs(v.vertex.x) + abs(v.vertex.z);
    25.             fixed swayAmount = (v.vertex.y + pow(centerDist,2)) * (1 - v.color.r);
    26.             fixed a = sin((_PI2 * (v.vertex.xz + (_Time * _WaveSpeed))) ) * _WaveAmplitude;
    27.             v.vertex.y += swayAmount * _WaveMulti * a;
    28.  
    29.             fixed swayAmountH = pow(centerDist, 2) * (1 - v.color.r);
    30.             fixed hx = sin((_PI2 * (v.vertex.xz + (_Time * _WaveSpeedH))) * 0.93) * _WaveAmplitudeH;
    31.             v.vertex.x += swayAmountH * hx;
    32.  
    33.             fixed hz = sin((_PI2 * (v.vertex.xz + (_Time * _WaveSpeedH))) * 0.33) * _WaveAmplitudeH;
    34.             v.vertex.z += swayAmountH * hz;
    35.         }
    36.  
    37.         sampler2D _MainTex;
    38.         void surf(Input IN, inout SurfaceOutputStandard o) {
    39.             o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
    40.         }
    41.  
    42.         fixed4 LightingLambertDoubleSided(SurfaceOutputStandard s, fixed3 lightDir, fixed atten)
    43.         {
    44.             fixed diff = abs(dot(s.Normal, lightDir));
    45.  
    46.             fixed4 c;
    47.             c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
    48.             c.a = s.Alpha;
    49.             return c;
    50.         }
    51.  
    52.         ENDCG
    53.     }
    54.     Fallback "Diffuse"
    55. }
    And here is an example image:



    Any help is appreciated!
     
  2. S0wbear

    S0wbear

    Joined:
    Jan 14, 2016
    Posts:
    9
    I found the problem:
    alphatest:_Cutoff is apparently what caused the pixles to not be rendered.
    I wonder how this could even have worked before, but nvm.

    So i guess this is what happens when you blindly copy code found somewhere on the web without knowing what it actually does ;)