Guest User

Here is an example of a basic water shader for Unity

a guest
Jan 16th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/Water" {
  2.     Properties {
  3.         _MainTex ("Water Texture", 2D) = "white" {}
  4.         _BumpMap ("Normal Map", 2D) = "bump" {}
  5.         _ReflectionTex ("Reflection Texture", 2D) = "white" {}
  6.         _RefractionTex ("Refraction Texture", 2D) = "white" {}
  7.         _WaterColor ("Water Color", Color) = (0.1, 0.3, 0.5, 1.0)
  8.         _Specular ("Specular", Range(0, 1)) = 0.5
  9.         _Shininess ("Shininess", Range(0, 1)) = 0.07
  10.         _WaveSpeed ("Wave Speed", Range(0, 10)) = 1
  11.         _WaveSize ("Wave Size", Range(0, 1)) = 0.03
  12.     }
  13.  
  14.     SubShader {
  15.         Tags {"Queue"="Transparent"}
  16.         LOD 200
  17.  
  18.         CGPROGRAM
  19.         #pragma surface surf Lambert
  20.  
  21.         sampler2D _MainTex;
  22.         sampler2D _BumpMap;
  23.         sampler2D _ReflectionTex;
  24.         sampler2D _RefractionTex;
  25.         fixed4 _WaterColor;
  26.         float _Specular;
  27.         float _Shininess;
  28.         float _WaveSpeed;
  29.         float _WaveSize;
  30.  
  31.         struct Input {
  32.             float2 uv_MainTex;
  33.             float2 uv_BumpMap;
  34.             float3 viewDir;
  35.         };
  36.  
  37.         void surf (Input IN, inout SurfaceOutput o) {
  38.             fixed4 tex = tex2D (_MainTex, IN.uv_MainTex);
  39.             o.Albedo = tex.rgb * _WaterColor.rgb;
  40.             o.Alpha = tex.a;
  41.             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  42.             o.Specular = _Specular;
  43.             o.Gloss = _Shininess;
  44.             o.Emission = tex.rgb * _WaterColor.rgb;
  45.             o.Reflection = texCUBE(_ReflectionTex, IN.viewDir).rgb;
  46.             o.Refraction = texCUBE(_RefractionTex, IN.viewDir).rgb;
  47.         }
  48.         ENDCG
  49.     }
  50.     FallBack "Diffuse"
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment