Improve close-up ship cameras and marine rendering

This commit is contained in:
josh
2026-11-28 00:16:51 -05:00
parent 4722db6456
commit 384f140b92
15 changed files with 875 additions and 230 deletions

View File

@@ -43,26 +43,27 @@ Shader "Soundings/Harbor Water"
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);
float3 horizon = lerp(float3(.55,.69,.75), float3(.92,.71,.51), warmth * .84);
float elevation = sqrt(saturate(ray.y));
float3 sky = lerp(horizon, float3(.081,.242,.408), elevation);
float3 squall = lerp(float3(.41,.50,.56), float3(.112,.174,.230), 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);
float2 wind = float2(.00095,-.00068) * time;
float2 layers = ray.xz * (.73 / (max(0, ray.y) + .18));
float cloud = tex2Dlod(_OceanDetail, float4(layers * float2(.14,.22) + wind, 0, 2)).b * .74
+ tex2Dlod(_OceanDetail, float4(layers * .31 + wind * 1.41 + .38, 0, 2)).b * .26;
float coverage = smoothstep(.52 - .13 * _WeatherSeverity, .76, cloud);
coverage *= smoothstep(-.010,.097,ray.y) * (1 - smoothstep(.61, 1, ray.y));
float sunlight = saturate(dot(ray, Sun));
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));
float3 vapor = lerp(color * 1.08 + float3(.134,.115,.095) * (.44 + .56 * pow(sunlight, 5)),
color * .63 + float3(.044,.056,.069), _WeatherSeverity);
float glow = .12 * pow(sunlight, 23) + .37 * smoothstep(.9989, .9997, sunlight);
return lerp(color, vapor, coverage) + float3(1,.85,.69) * glow * (1 - _WeatherSeverity) * (1 - coverage);
}
float2 HullPoint(float2 world)
@@ -71,71 +72,105 @@ Shader "Soundings/Harbor Water"
return float2(dot(relative, float2(_HullCourse.x, -_HullCourse.y)), dot(relative, _HullCourse.yx));
}
float HullShade(float2 hullPoint)
float HullEdge(float2 hull)
{
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));
// Match the outline near the waterline, where the stern stays wider than the bow.
float station = saturate(hull.x / _HullSpan.x + .5);
float stern = lerp(.52, 1, sin(saturate(station / .16) * 1.570796));
float bow = cos(saturate((station - .69) / .31) * 1.570796);
float side = abs(hull.y) - .95 * _HullSpan.y * stern * bow;
float cap = abs(hull.x) - .495 * _HullSpan.x;
return length(max(float2(side, cap), 0));
}
float BowWhitewater(float2 hull, float breakup)
float2 BowWhitewater(float2 hull, float gap, float eddies, float grain)
{
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);
float length = _HullSpan.x;
float speed = sqrt(_HullCourse.z);
float behind = length * .494 - hull.x;
float distance = max(0, behind);
float current = eddies - .5;
float wedge = abs(hull.y) - (1.1 + distance * .35 + current * (1 + distance * .04));
float width = .85 + distance * .032;
float bowWave = 1 - smoothstep(.05, width, abs(wedge));
bowWave *= smoothstep(-2.3, 5.2, behind) * (1 - smoothstep(length * .48, length * .93, behind));
float stem = 1 - smoothstep(.1, 1.9 + speed * 2.1, abs(behind + .6) + abs(hull.y) * .80);
float wash = (1 - smoothstep(.16, 1.05 + speed + .75 * eddies, gap)) *
smoothstep(-1.0, 7, behind) * (1 - smoothstep(length * .78, length * .99, behind));
float froth = saturate(.75 * bowWave + .98 * stem + .55 * wash);
float foamCells = smoothstep(.31, .75, eddies * .66 + grain * .34 + froth * .17);
return speed * float2(saturate(.64 * froth + .37 * wash), froth * (.15 + .78 * foamCells));
}
float2 WindSlope(float2 position, float eddies, float time)
{
// Short cross-seas add structure between the long swells and the texture ripples.
float2 wind = float2(.45, .89);
float2 swell = float2(-1.08, .67);
float drift = (eddies - .5) * 4.6;
float a = cos(dot(position, wind) - time * 2.15 + drift);
float b = cos(dot(position, swell) - time * 2.76 - drift * .9);
return wind * (.069 * a) + swell * (.043 * b);
}
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);
float distance = clamp(origin.y / down, 0, 5800);
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;
float approach = max(down * .5, down + dot(waves.yz, ray.xz));
distance = max(0, distance - clamp(waves.x / approach, -9, 9) * intersectionBlend);
position = origin.xz + ray.xz * distance;
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;
float2 rotated = float2(dot(position, float2(.835, -.550)), dot(position, float2(.550, .835)));
float2 crossed = float2(dot(position, float2(.939, .344)), dot(position, float2(-.344, .939)));
float3 chop = tex2D(_OceanDetail, position * .028 + float2(-.018,.012) * _SeaTime).rgb;
float3 ripples = tex2D(_OceanDetail, rotated * .076 + float2(.026,.019) * _SeaTime).rgb;
float3 surface = tex2D(_OceanDetail, crossed * .179 + float2(-.042,.036) * _SeaTime).rgb;
float2 rippleSlope = ripples.rg - .5;
rippleSlope = float2(dot(rippleSlope, float2(.835, .550)), dot(rippleSlope, float2(-.550, .835)));
float2 surfaceSlope = surface.rg - .5;
surfaceSlope = float2(dot(surfaceSlope, float2(.939, -.344)), dot(surfaceSlope, float2(.344, .939)));
float swellDetail = 1 - smoothstep(175, 700, distance);
float textureDetail = 1 - smoothstep(68, 525, distance);
float surfaceDetail = 1 - smoothstep(23, 175, distance);
float roughness = lerp(.60, 1.18, _WeatherSeverity);
float2 slope = waves.yz * swellDetail + WindSlope(position, chop.b, _SeaTime) * textureDetail * roughness
+ ((chop.rg - .5) * .34 + rippleSlope * .29) * textureDetail * roughness
+ surfaceSlope * (.115 * surfaceDetail * 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));
float facing = 1 - saturate(dot(-ray, normal));
float reflection = .095 + .81 * facing * facing * facing * facing * facing;
float cap = saturate(dot(normal, Sun) * .84 + (chop.b - .5) * textureDetail * .63 + .35);
float3 fromBelow = lerp(float3(.028,.125,.192), float3(.078,.250,.294), cap);
fromBelow = lerp(fromBelow, fromBelow * .57 + float3(.022,.032,.036), _WeatherSeverity);
float3 color = lerp(fromBelow, SkyGradient(reflected) * .83, reflection);
float sunHit = saturate(dot(reflected, Sun));
float nearSun = pow(sunHit, lerp(162, 60, _WeatherSeverity));
float reflectedLight = pow(sunHit, lerp(28, 15, _WeatherSeverity));
color += (nearSun * .43 + reflectedLight * .13) * float3(1,.86,.65) * (1 - _WeatherSeverity * .88);
float crest = waves.x / lerp(.35, 1.46, _WeatherSeverity * _WeatherSeverity);
float churn = .55 * chop.b + .28 * ripples.b + .17 * surface.b;
float capFoam = smoothstep(.65, .85, churn + crest * .19 + length(slope) * .17);
color = lerp(color, float3(.64,.74,.76), capFoam * textureDetail * (.035 + _WeatherSeverity * .58));
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);
if (abs(hull.x) < _HullSpan.x * .5 + 6 && abs(hull.y) < _HullSpan.x * .34 + 6)
{
float gap = HullEdge(hull);
color *= 1 - (1 - smoothstep(.18, 5.3, gap)) * .31;
float2 foam = BowWhitewater(hull, gap, .67 * ripples.b + .33 * chop.b, surface.b);
color = lerp(color, float3(.32,.57,.61), foam.x * .52);
color = lerp(color, float3(.88,.94,.94), foam.y);
}
}
float mist = 1 - exp(-distance * (.00040 + .00077 * _WeatherSeverity));
@@ -169,11 +204,15 @@ Shader "Soundings/Harbor Water"
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);
float wave = sin(dot(world, float2(.52,1.27)) - _Time.y * 1.3);
float crossWave = sin(dot(world, float2(-.85,.41)) - _Time.y * 1.6);
uv += waterMask * float2(.00089 * wave + .00045 * crossWave, .00028 * crossWave);
float3 color = tex2D(_Backdrop, uv).rgb;
float3 harborRipples = tex2D(_OceanDetail, world * .072 + float2(.009,-.014) * _Time.y).rgb;
float glimmer = (harborRipples.r - .5) * (.63 + .37 * wave) + (harborRipples.b - .5) * .22;
color += waterMask * (1 - smoothstep(28, 200, distance)) * glimmer * float3(.019,.028,.035);
if (_HullSpan.x > 1)
color *= 1 - HullShade(HullPoint(world)) * .33 * waterMask;
color *= 1 - (1 - smoothstep(.18, 5.3, HullEdge(HullPoint(world)))) * .29 * waterMask;
return fixed4(color, 1);
}
ENDCG