Make voyages active with dockside orders, crew calls, and ship PA
This commit is contained in:
@@ -3,10 +3,11 @@ Shader "Soundings/Harbor Water"
|
||||
Properties
|
||||
{
|
||||
_Backdrop ("Harbor photograph", 2D) = "black" {}
|
||||
_OceanDetail ("Ocean surface detail", 2D) = "gray" {}
|
||||
_BackdropCrop ("Harbor crop", Vector) = (1,1,0,0)
|
||||
_HullSpan ("Hull length and beam", Vector) = (71,7,0,0)
|
||||
_HullCourse ("Hull heading and wake strength", Vector) = (1,0,0,0)
|
||||
_Underway ("Open water blend", Range(0,1)) = 0
|
||||
_Underway ("Open water", Float) = 0
|
||||
_WeatherSeverity ("Sea conditions", Range(0,1)) = 0
|
||||
}
|
||||
SubShader
|
||||
@@ -17,14 +18,17 @@ Shader "Soundings/Harbor Water"
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
CGPROGRAM
|
||||
#pragma target 3.0
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
#include "OceanWaves.cginc"
|
||||
|
||||
sampler2D _Backdrop;
|
||||
sampler2D _Backdrop, _OceanDetail;
|
||||
float4 _BackdropCrop, _HullSpan, _HullCourse, _ViewSize;
|
||||
float3 _ViewOrigin, _ViewForward, _ViewRight, _ViewUp;
|
||||
float _Underway, _WeatherSeverity, _SeaTime;
|
||||
static const float3 Sun = float3(-.761,.441,-.474);
|
||||
struct Output { float4 clip : SV_POSITION; float2 screen : TEXCOORD0; };
|
||||
|
||||
Output vert(appdata_base input)
|
||||
@@ -36,6 +40,117 @@ Shader "Soundings/Harbor Water"
|
||||
return output;
|
||||
}
|
||||
|
||||
float3 SkyGradient(float3 ray)
|
||||
{
|
||||
float warmth = pow(saturate(.55 + dot(ray.xz, Sun.xz) * .55), 2.3);
|
||||
float3 horizon = lerp(float3(.50,.63,.68), float3(.91,.66,.46), warmth * .88);
|
||||
float elevation = pow(saturate(ray.y), .52);
|
||||
float3 sky = lerp(horizon, float3(.084,.218,.347), elevation);
|
||||
float3 squall = lerp(float3(.39,.48,.53), float3(.102,.156,.202), elevation);
|
||||
return lerp(sky, squall, _WeatherSeverity);
|
||||
}
|
||||
|
||||
float3 Sky(float3 ray, float time)
|
||||
{
|
||||
float2 wind = float2(.0014,-.0010) * time;
|
||||
float2 layers = ray.xz * (.76 / (max(0, ray.y) + .21)) + wind;
|
||||
float cloud = tex2Dlod(_OceanDetail, float4(layers * .19, 0, 2)).b * .68
|
||||
+ tex2Dlod(_OceanDetail, float4(layers * .40 + .38, 0, 2)).b * .32;
|
||||
float coverage = smoothstep(.57 - .15 * _WeatherSeverity, .82, cloud);
|
||||
coverage *= smoothstep(-.015,.16,ray.y) * (1 - smoothstep(.66, 1, ray.y));
|
||||
float facing = pow(saturate(dot(ray, Sun)), 5);
|
||||
float3 color = SkyGradient(ray);
|
||||
float3 vapor = lerp(color * 1.14 + float3(.124,.106,.087) * facing,
|
||||
color * .65 + float3(.038,.048,.056), _WeatherSeverity);
|
||||
return lerp(color, vapor, coverage * (.65 + .3 * _WeatherSeverity));
|
||||
}
|
||||
|
||||
float2 HullPoint(float2 world)
|
||||
{
|
||||
float2 relative = world - _HullSpan.zw;
|
||||
return float2(dot(relative, float2(_HullCourse.x, -_HullCourse.y)), dot(relative, _HullCourse.yx));
|
||||
}
|
||||
|
||||
float HullShade(float2 hullPoint)
|
||||
{
|
||||
float halfLength = _HullSpan.x * .5;
|
||||
float along = abs(hullPoint.x / max(1, halfLength));
|
||||
float beam = _HullSpan.y * lerp(.24, 1, saturate(1 - pow(along, 3.2)));
|
||||
return (1 - smoothstep(.1, 5.8, abs(hullPoint.y) - beam)) * (1 - smoothstep(.91, 1.105, along));
|
||||
}
|
||||
|
||||
float BowWhitewater(float2 hull, float breakup)
|
||||
{
|
||||
float beam = _HullSpan.y;
|
||||
float fromStem = _HullSpan.x * .49 - hull.x;
|
||||
float steer = sqrt(_HullCourse.z);
|
||||
float bandWidth = 1.55 + max(0, fromStem) * .022;
|
||||
float glass = abs(hull.y) - (1 + max(0, fromStem) * .37);
|
||||
float wedge = 1 - smoothstep(.2, bandWidth, abs(glass));
|
||||
float stem = 1 - smoothstep(.4, 2.9 + steer * 2.8, length(float2(fromStem + .9, hull.y * .68)));
|
||||
float flare = smoothstep(-1.9, 7, fromStem) * (1 - smoothstep(_HullSpan.x * .56, _HullSpan.x * 1.16, fromStem));
|
||||
float rip = .75 + .25 * sin(fromStem * 1.45 + hull.y + _SeaTime * 7);
|
||||
float nearBeam = beam * lerp(.22, 1, smoothstep(0, _HullSpan.x * .33, fromStem));
|
||||
float hullWash = 1 - smoothstep(.18, 2.05, abs(abs(hull.y) - nearBeam));
|
||||
hullWash *= smoothstep(0, 8, fromStem) * (1 - smoothstep(_HullSpan.x * .88, _HullSpan.x, fromStem));
|
||||
return saturate((wedge * flare * .81 + stem * .89 + hullWash * .57) * rip * breakup) * (steer * .93);
|
||||
}
|
||||
|
||||
float3 OpenSea(float3 origin, float3 ray, float2 screen)
|
||||
{
|
||||
float skyLine = smoothstep(-.0033, .0010, ray.y);
|
||||
float down = max(.00042, -ray.y);
|
||||
float distance = min(5800, origin.y / down);
|
||||
float2 position = origin.xz + ray.xz * distance;
|
||||
float3 waves = OceanWave(position, _SeaTime, _WeatherSeverity);
|
||||
float intersectionBlend = 1 - smoothstep(180, 600, distance);
|
||||
position -= ray.xz * clamp(waves.x / down, -9, 9) * intersectionBlend;
|
||||
waves = OceanWave(position, _SeaTime, _WeatherSeverity);
|
||||
|
||||
float2 rotated = float2(position.x * .82 - position.y * .57, position.x * .57 + position.y * .82);
|
||||
float mip = clamp(log2(max(1, distance) / 76), 0, 7);
|
||||
float3 chop = tex2Dlod(_OceanDetail, float4(position * .041 + float2(-.022,.013) * _SeaTime, 0, mip)).rgb;
|
||||
float3 ripples = tex2Dlod(_OceanDetail, float4(rotated * .107 + float2(.032,.020) * _SeaTime, 0, mip + .65)).rgb;
|
||||
float detail = 1 - smoothstep(85, 670, distance);
|
||||
float swellDetail = 1 - smoothstep(180, 690, distance);
|
||||
float roughness = lerp(.43, .96, _WeatherSeverity);
|
||||
float2 slope = waves.yz * swellDetail
|
||||
+ ((chop.rg - .5) * .47 + (ripples.rg - .5) * .25) * detail * roughness;
|
||||
float3 normal = normalize(float3(-slope.x, 1, -slope.y));
|
||||
float rough = ((chop.b - .5) * .045 + (ripples.b - .5) * .015) * detail;
|
||||
float light = saturate(dot(normal, Sun));
|
||||
float3 fromBelow = lerp(float3(.031,.159,.220), float3(.064,.205,.274), .23 + .53 * light + rough * 7);
|
||||
fromBelow = lerp(fromBelow, fromBelow * .60 + float3(.019,.028,.030), _WeatherSeverity * .82);
|
||||
float reflection = .19 + .64 * pow(1 - saturate(dot(-ray, normal)), 4);
|
||||
float3 reflected = reflect(ray, normal);
|
||||
float3 color = lerp(fromBelow, SkyGradient(reflected) * .75, reflection);
|
||||
float glint = pow(saturate(dot(reflected, Sun)), lerp(78, 29, _WeatherSeverity));
|
||||
color += glint * float3(.48,.38,.24) * (1 - .86 * _WeatherSeverity);
|
||||
float nightFoam = smoothstep(.74,.96, chop.b * .67 + ripples.b * .33 + slope.x * .39);
|
||||
color = lerp(color, float3(.53,.67,.69), nightFoam * detail * (.22 + _WeatherSeverity * .57));
|
||||
|
||||
if (_HullSpan.x > 1)
|
||||
{
|
||||
float2 hull = HullPoint(position);
|
||||
color *= 1 - HullShade(hull) * .35;
|
||||
float breakup = .63 + smoothstep(.28,.73, chop.b + ripples.b * .33) * .55;
|
||||
float foam = BowWhitewater(hull, breakup);
|
||||
color = lerp(color, float3(.79,.89,.89), foam);
|
||||
}
|
||||
|
||||
float mist = 1 - exp(-distance * (.00040 + .00077 * _WeatherSeverity));
|
||||
color = lerp(color, SkyGradient(float3(ray.x, 0, ray.z)) * .90, mist * .80);
|
||||
if (skyLine > 0)
|
||||
color = lerp(color, Sky(ray, _SeaTime), skyLine);
|
||||
if (_WeatherSeverity > .75)
|
||||
{
|
||||
float2 grid = float2(screen.x * 165 + screen.y * 42, screen.y * 23 + _SeaTime * 17);
|
||||
float rain = step(.978, frac(grid.x + floor(grid.y) * .381)) * smoothstep(.56, .68, frac(grid.y));
|
||||
color += rain * float3(.095,.133,.15);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
fixed4 frag(Output input) : SV_Target
|
||||
{
|
||||
float2 screen = input.screen;
|
||||
@@ -43,67 +158,22 @@ Shader "Soundings/Harbor Water"
|
||||
float3 viewOffset = offsetOnFilm.x * _ViewRight + offsetOnFilm.y * _ViewUp;
|
||||
float3 origin = _ViewOrigin + viewOffset * _ViewSize.z;
|
||||
float3 ray = normalize(_ViewForward + viewOffset * (1 - _ViewSize.z));
|
||||
float distanceToWater = min(2600, max(0, -origin.y / min(ray.y, -.0001)));
|
||||
float2 world = origin.xz + ray.xz * distanceToWater;
|
||||
if (_Underway > .5)
|
||||
{
|
||||
if (ray.y >= .0010)
|
||||
return fixed4(Sky(ray, _SeaTime), 1);
|
||||
return fixed4(OpenSea(origin, ray, screen), 1);
|
||||
}
|
||||
|
||||
float2 uv = (screen - .5) * _BackdropCrop.xy + .5 + _BackdropCrop.zw;
|
||||
float waterMask = 1 - smoothstep(.55,.69,uv.y);
|
||||
float2 relative = world - _HullSpan.zw;
|
||||
float2 p = float2(dot(relative, float2(_HullCourse.x, -_HullCourse.y)),
|
||||
dot(relative, _HullCourse.yx));
|
||||
float t = lerp(_Time.y, _SeaTime, _Underway);
|
||||
float textureWave = sin(world.y * 1.94 + world.x * .30 + sin(world.x * .44 - t * (.30 + 1.2 * _WeatherSeverity)))
|
||||
* (.0015 + .003 * _WeatherSeverity);
|
||||
float waterMask = 1 - smoothstep(.55, .69, uv.y);
|
||||
float distance = min(2600, max(0, -origin.y / min(ray.y, -.0001)));
|
||||
float2 world = origin.xz + ray.xz * distance;
|
||||
float textureWave = sin(world.y * 1.94 + world.x * .30 + sin(world.x * .44 - _Time.y * .30)) * .0015;
|
||||
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 = lerp(smoothstep(-.006, .004, ray.y), smoothstep(.67, .70, screen.y), _ViewSize.z);
|
||||
float twilight = lerp(saturate(ray.y * 2.8), saturate((screen.y - .70) * 3.8), _ViewSize.z);
|
||||
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(world.y * .83 + world.x * .45 - t * 2.4) * sin(world.x * .48 + world.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 * _HullCourse.z);
|
||||
}
|
||||
if (_HullSpan.x > 1)
|
||||
color *= 1 - HullShade(HullPoint(world)) * .33 * waterMask;
|
||||
return fixed4(color, 1);
|
||||
}
|
||||
ENDCG
|
||||
|
||||
Reference in New Issue
Block a user