103 lines
5.2 KiB
GLSL
103 lines
5.2 KiB
GLSL
Shader "Soundings/Harbor Water"
|
|
{
|
|
Properties
|
|
{
|
|
_Backdrop ("Harbor photograph", 2D) = "black" {}
|
|
_BackdropCrop ("Harbor crop", Vector) = (1,1,0,0)
|
|
_HullSpan ("Hull length and beam", Vector) = (71,7,0,0)
|
|
_Underway ("Open water blend", Range(0,1)) = 0
|
|
_WeatherSeverity ("Sea conditions", Range(0,1)) = 0
|
|
}
|
|
SubShader
|
|
{
|
|
Tags { "Queue"="Background" "RenderType"="Opaque" }
|
|
Pass
|
|
{
|
|
Cull Off
|
|
ZWrite Off
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
|
|
sampler2D _Backdrop;
|
|
float4 _BackdropCrop, _HullSpan;
|
|
float _Underway, _WeatherSeverity;
|
|
struct Output { float4 clip : SV_POSITION; float4 screen : TEXCOORD0; float2 world : TEXCOORD1; };
|
|
|
|
Output vert(appdata_base input)
|
|
{
|
|
Output output;
|
|
output.clip = UnityObjectToClipPos(input.vertex);
|
|
output.screen = ComputeScreenPos(output.clip);
|
|
output.world = mul(unity_ObjectToWorld, input.vertex).xz;
|
|
return output;
|
|
}
|
|
|
|
fixed4 frag(Output input) : SV_Target
|
|
{
|
|
float2 screen = input.screen.xy / input.screen.w;
|
|
float2 uv = (screen - .5) * _BackdropCrop.xy + .5 + _BackdropCrop.zw;
|
|
float waterMask = 1 - smoothstep(.55,.69,uv.y);
|
|
float2 p = input.world - _HullSpan.zw;
|
|
float t = _Time.y;
|
|
float textureWave = sin(p.y * 1.94 + p.x * .30 + sin(p.x * .44 - t * (.30 + 1.2 * _WeatherSeverity)))
|
|
* (.0015 + .003 * _WeatherSeverity);
|
|
uv += waterMask * float2(textureWave, textureWave * .14);
|
|
float3 color = tex2D(_Backdrop, uv).rgb;
|
|
if (_Underway > 0)
|
|
{
|
|
float seaHeight = clamp(uv.y * .59 + .056, .055, .49);
|
|
float drift = sin(p.y * .166 + t * .19) * .017;
|
|
float3 openWater = tex2D(_Backdrop, float2(saturate(uv.x + drift), seaHeight)).rgb;
|
|
float skyBand = smoothstep(.67, .70, screen.y);
|
|
float twilight = saturate((screen.y - .70) * 3.8);
|
|
float west = pow(1 - screen.x, 1.65);
|
|
float3 horizon = lerp(float3(.45,.53,.59), float3(.83,.60,.46), west);
|
|
float3 sky = lerp(horizon, float3(.13,.24,.38), twilight);
|
|
float cloud = .76 + .24 * sin(screen.x * 18 + screen.y * 8 + sin(screen.x * 41 - t * .2));
|
|
float3 stormSky = lerp(float3(.37,.45,.49), float3(.10,.15,.20), twilight) * cloud;
|
|
sky = lerp(sky, stormSky, _WeatherSeverity);
|
|
float chop = sin(p.y * .83 + p.x * .45 - t * 2.4) * sin(p.x * .48 + p.y * 2.2 + t * 1.6);
|
|
openWater = lerp(openWater, openWater * .56 + float3(.055,.082,.09), _WeatherSeverity);
|
|
openWater += max(0, chop - .70) * .19 * _WeatherSeverity;
|
|
color = lerp(color, lerp(openWater, sky, skyBand), _Underway);
|
|
if (_WeatherSeverity > .75)
|
|
{
|
|
float2 rainGrid = float2(screen.x * 160 + screen.y * 42, screen.y * 22 + t * 15);
|
|
float rain = step(.973, frac(rainGrid.x + floor(rainGrid.y) * .381)) * step(.58, frac(rainGrid.y));
|
|
color += rain * .22 * _Underway * float3(.55,.69,.77);
|
|
}
|
|
waterMask = lerp(waterMask, 1 - skyBand, _Underway);
|
|
}
|
|
|
|
if (_HullSpan.x < 1)
|
|
return fixed4(color, 1);
|
|
|
|
float halfLength = _HullSpan.x * .5;
|
|
float along = abs((p.x + halfLength * .022) / halfLength);
|
|
float shaft = saturate(1 - pow(max(0,along), 3.2));
|
|
float waterline = _HullSpan.y * lerp(.28, 1, shaft);
|
|
float offset = abs(p.y + .5) - waterline;
|
|
float shadow = (1 - smoothstep(-.8, 5.1, offset)) * (1 - smoothstep(.90,1.12,along));
|
|
color *= 1 - .39 * shadow * waterMask;
|
|
float edgeWave = sin(p.x * 1.46 + p.y * 1.88 + t * .65) + .36 * sin(p.x * 3.3 + p.y * 2.42 - t * .50);
|
|
float foam = saturate(edgeWave - .55) * (1 - smoothstep(.12, 1.3, abs(offset - .25))) * (1 - smoothstep(.81,1.06,along));
|
|
color += float3(.19,.23,.24) * foam * waterMask;
|
|
if (_Underway > 0)
|
|
{
|
|
float trail = max(0, -p.x - halfLength * .88);
|
|
float v = abs(p.y) - (2.2 + trail * .19);
|
|
float turbulence = .5 + .28 * sin(p.x * 1.5 + p.y * 5.6 + t * 4)
|
|
+ .22 * sin(p.y * 13.7 - p.x * .37 - t * 2.2);
|
|
float wake = smoothstep(.05, 2, trail) * (1 - smoothstep(1, 5 + trail * .062, abs(v)))
|
|
* (1 - smoothstep(12, 89, trail)) * turbulence;
|
|
color = lerp(color, float3(.72,.84,.84), wake * waterMask * .43 * _Underway);
|
|
}
|
|
return fixed4(color, 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|