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

WaterFoam SurfaceShader - for Shoreline

Discussion in 'Shaders' started by Syco753, Oct 15, 2017.

  1. Syco753

    Syco753

    Joined:
    Feb 11, 2013
    Posts:
    42
    Hi, I’m desperate. After reading so many documents and testing, I'm not able to add a water foam texture for the shoreline to my shader. I’m new in shaders but not able to do it. Does anybody have a clue?

    Code (CSharp):
    1.  
    2.  
    3.     void vert(inout appdata_full v, out Input o) {
    4.         UNITY_INITIALIZE_OUTPUT(Input,o);
    5.         float phase = _Time * _WaveSpeed;
    6.         float offset = (v.vertex.x * (v.vertex.z * 0.2)) * _WaveCount;
    7.         v.vertex.y = sin(phase + offset) * _WaveHeight;
    8.  
    9.         o.vDir = normalize(ObjSpaceViewDir(v.vertex)).xzy;
    10.     }
    11.  
    12.     void surf(Input IN, inout SurfaceOutput o) {
    13.  
    14.         half4 tex = tex2D(_MainTex, IN.uv_MainTex);
    15.         half4 s_tex = tex2D(_SpecTex, IN.uv_SpecTex -= _Time / 35);
    16.        
    17.        
    18.         half4 s_texHallo = tex2D(_Hallo, IN.uv_Hallo += _Time / _WaveSpeed);
    19.  
    20.         half2 worldRefl = WorldReflectionVector(IN, o.normal);
    21.         half2 R = IN.vDir - (2 * dot(IN.vDir, o.Normal)) * o.Normal;
    22.         half4 reflcol = tex2D(_Cube, R);
    23.  
    24.         o.Albedo = tex.rgb *_Color.rgb * 4;
    25.         o.Albedo = tex2D(_MainTexX, IN.uv_MainTexX);
    26.        
    27.         float d = distance(_Center, IN.worldPos);
    28.        
    29.         float dN = 1 - saturate(d / (2 + _Radius-2.5));
    30.         dN = step(0.25, dN) * step(dN, 0.9);
    31.        
    32.         o.Alpha = reflcol.rgb*_AlphaPower;
    33.        
    34.         o.Gloss = s_tex.rgb*tex.a*_SpecPower*s_texHallo.rgb;
    35.  
    36.         float z = tex2D(_Hallo, IN.uv_Hallo);
    37.        
    38.         o.Emission = (reflcol.rgb*_CubePower)*s_tex.rgb * (s_texHallo.rgb * _CubePower);
    39.  
    40.     }
    41.  
    42.  
     
    Last edited: Oct 15, 2017