Search Unity

water shader 2D

Discussion in 'Shaders' started by JustMaulik007, Dec 26, 2019.

  1. JustMaulik007

    JustMaulik007

    Joined:
    Oct 3, 2018
    Posts:
    11
    I don't know much about shader :( if someone could help

    I am using this free 2d water asset it contains a water shader. I want to edit that shader so look more like 2.5d or 3d.

    Currently, it looks like this


    I want to make it look like




    Adding a foam type thing on top and make it little reflective

    shader used in the asset to make 2d water
    Code (CSharp):
    1.  
    2.  
    3. Shader "Water2D/Metaballs_Simple" {
    4. Properties {  
    5.     _MainTex ("Texture", 2D) = "white" { }  
    6.     _Color ("Main color", Color) = (1,1,1,1)
    7.     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    8.  
    9.     _Stroke ("Stroke alpha", Range(0,1)) = 0.1
    10.     _StrokeColor ("Stroke color", Color) = (1,1,1,1)
    11.  
    12. }
    13. /// <summary>
    14. /// Multiple metaball shader.
    15.  
    16. /// </summary>
    17. SubShader {
    18.     Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    19.     GrabPass{}
    20.     Pass {
    21.     Blend SrcAlpha OneMinusSrcAlpha  
    22.   // Blend One One // Additive
    23.   // Blend One OneMinusSrcAlpha
    24.     CGPROGRAM
    25.     #pragma vertex vert
    26.     #pragma fragment frag  
    27.     #include "UnityCG.cginc"  
    28.     float4 _Color;
    29.     sampler2D _MainTex;  
    30.     fixed _Cutoff;
    31.     fixed _Stroke;
    32.     half4 _StrokeColor;
    33.     float2 _screenPos;
    34.  
    35.  
    36.  
    37.     float4 _CameraDepthTexture_TexelSize;
    38.  
    39.  
    40.     struct v2f {
    41.         float4  pos : SV_POSITION;
    42.         float2  uv : TEXCOORD0;
    43.     };  
    44.  
    45.     float4 _MainTex_ST;      
    46.     v2f vert (appdata_base v){
    47.         v2f o;
    48.         o.pos = UnityObjectToClipPos (v.vertex);
    49.         o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
    50.         return o;
    51.     };
    52.  
    53.  
    54.  
    55.  
    56.     half4 frag (v2f i) : COLOR{      
    57.         half4 texcol= tex2D (_MainTex, i.uv);
    58.         //half4 finalColor = texcol;
    59.  
    60.  
    61.         clip(texcol.a - _Cutoff);
    62.  
    63.         if (texcol.a < _Stroke) {
    64.             texcol = _StrokeColor;
    65.         } else {
    66.             texcol = _Color;
    67.         }
    68.                  
    69.  
    70.      
    71.          return texcol;
    72.        
    73.      
    74.     }
    75.  
    76.  
    77.  
    78.  
    79.     ENDCG
    80.  
    81.     }
    82. }
    83. Fallback "VertexLit"
    84. }