Search Unity

Water Shader Problem in Windows Standalone

Discussion in 'Shaders' started by lamplightforest, Oct 20, 2017.

  1. lamplightforest

    lamplightforest

    Joined:
    Aug 23, 2015
    Posts:
    12
    Hey folks,
    I combined a few bits of shader code to make this foam water shader. It works in the editor and as OSX standalone, but in Windows standalone it breaks and the output log says: "Pass ' ' has no fragment shader."

    Can anyone diagnose?


    Code (CSharp):
    1. Shader "FX/Water_al" {
    2. Properties {
    3.     [NoScaleOffset] _ReflectiveColor ("Reflective color (RGB) fresnel (A) ", 2D) = "" {}
    4.     _HorizonColor ("Simple water horizon color", COLOR)  = ( .172, .463, .435, 1)
    5.  
    6.  
    7.     //foam stuff
    8.         [NoScaleOffset] _Foam ("Foam texture", 2D) = "white" {}
    9.     [NoScaleOffset] _FoamGradient ("Foam gradient ", 2D) = "white" {}
    10.     _FoamStrength ("Foam strength", Range (0, 10.0)) = 1.0
    11. }
    12.  
    13.  
    14. // -----------------------------------------------------------
    15. // Fragment program cards
    16.  
    17.  
    18. Subshader {
    19.     Tags { "Queue"="Transparent" "RenderType"="Transparent" }
    20.     Blend SrcAlpha OneMinusSrcAlpha
    21.             ZWrite Off
    22.     Pass {
    23.  
    24. CGPROGRAM
    25. #pragma vertex vert
    26. #pragma fragment frag
    27. #pragma multi_compile_fog
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34. #include "UnityCG.cginc"
    35.  
    36.  
    37.  
    38. uniform float _FoamStrength;
    39.  
    40.  
    41.  
    42. struct appdata {
    43.     float4 vertex : POSITION;
    44. //    float3 normal : NORMAL;
    45. };
    46.  
    47.  
    48. struct v2f {
    49.     float4 pos : SV_POSITION;
    50.  
    51.         float4 ref : TEXCOORD0;
    52.  
    53.  
    54.         float3 viewDir : TEXCOORD3;
    55.         float2 foamuv : TEXCOORD4;
    56.  
    57.     UNITY_FOG_COORDS(4)
    58. };
    59.  
    60.  
    61.  
    62.  
    63. v2f vert(appdata v)
    64. {
    65.     v2f o;
    66.     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    67.  
    68.  
    69.  
    70.     // scroll bump waves
    71.     float4 temp;
    72.     float4 wpos = mul (unity_ObjectToWorld, v.vertex);
    73.  
    74.  
    75.     //foam stuff
    76.     o.foamuv = 7.0f * wpos.xz + 0.05 * float2(_SinTime.w, _SinTime.w);
    77.     o.ref = ComputeScreenPos(o.pos);
    78.  
    79.     // object space view direction (will normalize per pixel)
    80.     o.viewDir.xzy = WorldSpaceViewDir(v.vertex);
    81.  
    82.  
    83.  
    84.  
    85.     UNITY_TRANSFER_FOG(o,o.pos);
    86.     return o;
    87. }
    88.  
    89.  
    90. sampler2D _ReflectiveColor;
    91.  
    92. uniform float4 _HorizonColor;
    93.  
    94.  
    95.  
    96.  
    97. //foam stuff
    98. sampler2D _Foam;
    99. sampler2D _FoamGradient;
    100. uniform sampler2D _CameraDepthTexture; //Depth Texture
    101.  
    102. half4 frag( v2f i ) : SV_Target
    103. {
    104.     i.viewDir = normalize(i.viewDir);
    105.  
    106.  
    107.  
    108.  
    109.     // fresnel factor
    110.     half fresnelFac = dot( i.viewDir, 0 );
    111.  
    112.     // perturb reflection/refraction UVs by bumpmap, and lookup colors
    113.  
    114.  
    115.     half4 color;
    116.     half4 water = tex2D( _ReflectiveColor, float2(fresnelFac,fresnelFac) );
    117.     color.rgb = lerp( water.rgb, _HorizonColor.rgb, water.a );
    118.     color.a = _HorizonColor.a;
    119.  
    120.  
    121.  
    122.  
    123. //foam stuff
    124. float sceneZ = LinearEyeDepth (tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.ref)).r);
    125.     float objectZ = i.ref.z;
    126.     float intensityFactor = 1 - saturate((sceneZ - objectZ) / _FoamStrength);  
    127.  
    128.  
    129.     half3 foamGradient = 1 - tex2D(_FoamGradient, float2(intensityFactor - _Time.y*0.2, 0) + 0 * 0.15);
    130.     float2 foamDistortUV = 0 * 0.2;
    131.     half3 foamColor = tex2D(_Foam, i.foamuv + foamDistortUV).rgb;
    132.     color.rgb += foamGradient * intensityFactor * foamColor;
    133.  
    134.  
    135.  
    136.     UNITY_APPLY_FOG(i.fogCoord, color);
    137.     return color;
    138. }
    139. ENDCG
    140.  
    141.     }
    142. }
    143.  
    144. }
    145.  
     
  2. kite3h

    kite3h

    Joined:
    Aug 27, 2012
    Posts:
    197
    Is it compiled? I think ref is not suitable varying variable name.