Newer
Older
Shader "Custom/WaterShader"
{
Properties
{
_DeepColor ("Deep Color", Color) = (1,1,1,1)
_ShallowColor("Shallow Color", Color) = (1,1,1,1)
_CausticsTex ("Caustics Texture", 2D) = "white" {}
_WavesTex("Waves Texture", 2D) = "white" {}
_WaveSize("Wave Size", Range(-5,5)) = 0.5
_WaveSpeed("Wave Speed", Vector) = (0.5, 0.5, 0 ,0)
_WaveSpeed2("Wave Speed 2", Vector) = (0.5, 0.5, 0 ,0)
[HideInInspector]_ReflectionTex("Reflection", 2D) = "white" {}
}
Tags { "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 2
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows vertex:vert alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
fixed4 _DeepColor;
fixed4 _ShallowColor;
sampler2D _CausticsTex;
sampler2D _WavesTex;
sampler2D _ReflectionTex;
float _WaveSize;
fixed2 _WaveSpeed;
fixed4 _WaveSpeed2;
//surf input
struct Input
{
float2 uv_CausticsTex;
float4 screenPos;
float4 screenPosition : TEXCOORD2;
void vert (inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
float4 texUV = v.texcoord;
texUV.xy = (texUV.xy + _WaveSpeed * _Time.y);
float4 texUV2 = v.texcoord;
texUV.xy = (texUV.xy + _WaveSpeed2.xy * _Time.y);
float height = min(tex2Dlod(_WavesTex, texUV).r, tex2Dlod(_WavesTex, texUV2).r);
v.vertex.xyz += v.normal * (_WaveSize * height) - (_WaveSize / 2) + 0.02;
o.screenPosition = ComputeScreenPos(UnityObjectToClipPos(v.vertex));
}
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
//fixed4 albC = _DeepColor;
//o.Albedo = albC.rgb;
float2 texUV = IN.uv_CausticsTex;
float2 texUV2 = IN.uv_CausticsTex;
fixed2 uv = IN.uv_CausticsTex * _WaveSpeed * _Time.y;
texUV2.xy = (texUV2.xy + _WaveSpeed2 * _Time.y);
fixed3 caustic1 = tex2D(_CausticsTex, texUV).rgb;
fixed3 caustic2 = tex2D(_CausticsTex, texUV2).rgb;;
// Metallic and smoothness come from slider variables
o.Metallic = 0;
o.Smoothness = 1;
float2 screenUV = IN.screenPos.xy / IN.screenPos.w;
screenUV.x = 1 - screenUV.x;
float existingDepth01 = tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPosition)).r;
float existingDepthLinear = LinearEyeDepth(existingDepth01);
float depthDifference = existingDepthLinear - IN.screenPosition.w;
fixed3 causticrgb = caustic1 * caustic2 * depthDifference;
o.Albedo = (_DeepColor + causticrgb)/2;
o.Alpha = .6;
//o.Albedo *= (tex2D(_ReflectionTex, screenUV).rgb);