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

@@ -30,9 +30,10 @@ Shader "Soundings/Harbor Reflection"
float time = lerp(_Time.y, _SoundingsSeaTime, _SoundingsSeaSailing);
float3 wave = OceanWave(worldPosition.xz, time, _SoundingsSeaWeather) * _SoundingsSeaSailing;
worldPosition.y = -worldPosition.y * .59;
worldPosition.y += wave.x * 1.5;
worldPosition.z += sin(worldPosition.x * .53 + worldPosition.y * 2.14 + time * 1.55) * .27 + wave.z * 4;
worldPosition.x += sin(worldPosition.y * .88 - time) * .29 + wave.y * 4;
float spread = smoothstep(0, 5, -worldPosition.y);
worldPosition.y += wave.x * .80;
worldPosition.z += (sin(worldPosition.x * .53 + worldPosition.y * 2.14 + time * 1.55) * .27 + wave.z * 3.5) * spread;
worldPosition.x += (sin(worldPosition.y * .88 - time) * .29 + wave.y * 3.5) * spread;
output.clip = UnityWorldToClipPos(worldPosition.xyz);
output.world = worldPosition.xyz;
return output;
@@ -42,9 +43,18 @@ Shader "Soundings/Harbor Reflection"
{
clip(-input.world.y);
float time = lerp(_Time.y, _SoundingsSeaTime, _SoundingsSeaSailing);
float breakup = .48 + .38 * sin(input.world.y * 14 + input.world.x * .62 - time * 1.02);
float alpha = saturate(1 + input.world.y / 7.5) * breakup * lerp(.34, .24 - .11 * _SoundingsSeaWeather, _SoundingsSeaSailing);
return fixed4(_Color.rgb * float3(.51,.60,.64), alpha);
float3 view = lerp(normalize(_WorldSpaceCameraPos - input.world), UNITY_MATRIX_V[2].xyz, unity_OrthoParams.w);
float depth = -input.world.y;
float2 surface = input.world.xz + view.xz * depth / max(.10, view.y);
float primary = sin(dot(surface, float2(.58, 2.83)) + depth * 1.40 - time * 2.22);
float crossing = sin(dot(surface, float2(-1.19, 1.62)) + depth * 2.71 + time * 1.43);
float breakup = .58 + .26 * primary + .16 * crossing;
float closeReflection = lerp(.43, breakup, smoothstep(0, 1.5, depth));
float grazing = 1 - saturate(view.y);
float strength = lerp(.36, .25 - .10 * _SoundingsSeaWeather, _SoundingsSeaSailing);
float fade = exp(-depth * lerp(.24, .43, _SoundingsSeaSailing)) * (1 - smoothstep(6, 10, depth));
float alpha = fade * closeReflection * strength * (.66 + .34 * grazing);
return fixed4(_Color.rgb * float3(.55,.65,.68), alpha);
}
ENDCG
}

View File

@@ -7,6 +7,8 @@ Shader "Soundings/Harbor Surface"
_Metal ("Metal", Range(0,1)) = 0
_Emissive ("Emission", Range(0,1)) = 0
_Weather ("Weathering", Range(0,1)) = .1
_Finish ("Surface finish", Float) = 0
_Waterline ("Opaque hull at the waterline", Float) = 0
}
SubShader
{
@@ -14,14 +16,24 @@ Shader "Soundings/Harbor Surface"
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "OceanWaves.cginc"
fixed4 _Color;
float _Roughness, _Metal, _Emissive, _Weather;
float _Roughness, _Metal, _Emissive, _Weather, _Finish, _Waterline;
float _SoundingsSeaWeather, _SoundingsSeaSailing, _SoundingsSeaTime;
struct Input { float4 vertex : POSITION; float3 normal : NORMAL; };
struct Output { float4 clip : SV_POSITION; float3 normal : TEXCOORD0; float3 world : TEXCOORD1; };
struct Output
{
float4 clip : SV_POSITION;
float3 normal : TEXCOORD0;
float3 world : TEXCOORD1;
float3 local : TEXCOORD2;
float3 localNormal : TEXCOORD3;
};
Output vert(Input input)
{
@@ -29,33 +41,122 @@ Shader "Soundings/Harbor Surface"
output.clip = UnityObjectToClipPos(input.vertex);
output.normal = UnityObjectToWorldNormal(input.normal);
output.world = mul(unity_ObjectToWorld, input.vertex).xyz;
output.local = input.vertex.xyz;
output.localNormal = input.normal;
return output;
}
float PanelShade(float2 cell)
{
float3 p = frac(cell.xyx * .1031);
p += dot(p, p.yzx + 33.33);
return frac((p.x + p.y) * p.z);
}
// Fade details whose period falls beneath a pixel, especially around the railings.
float Detail(float phase)
{
return 1 - smoothstep(.25, .86, fwidth(phase));
}
float Groove(float phase, float width)
{
float edge = abs(frac(phase + .5) - .5);
float feather = max(.002, fwidth(phase) * .56);
return (1 - smoothstep(width, width + feather, edge)) * Detail(phase);
}
float SurfaceTone(float3 p, float3 normal)
{
float paint = sin(p.x * .82 + p.z * 1.7) * sin(p.y * 3.5 + p.z * 4.8);
float tone = 1 + paint * _Weather * .16;
if (_Finish == 1)
{
float horizontal = step(.6, abs(normal.y));
float crossGrain = lerp(p.y, p.z, horizontal);
float across = crossGrain / .215;
float row = floor(across);
float along = p.x * .383 + row * .381966;
float plank = PanelShade(float2(floor(along), row)) - .5;
float fibre = crossGrain * 53 + .73 * sin(p.x * 2.8 + crossGrain * 32);
float grain = sin(fibre) * Detail(crossGrain * 8.4);
float seams = Groove(across, .014) + Groove(p.x * .383 + frac(row * .381966), .0026);
tone = 1 + plank * .16 * Detail(across) + grain * .052 - seams * lerp(.12, .27, horizontal);
}
else if (_Finish == 3)
{
float crossFibre = abs(normal.y) > .55 ? p.z : p.y;
float weave = cos(p.x * 142) * cos(crossFibre * 153) * Detail(crossFibre * 24.4) * Detail(p.x * 22.6);
float mottling = sin(p.x * 11 + crossFibre * 16) * sin(p.x * 23 - crossFibre * 13);
tone = 1 + .037 * weave + .028 * mottling * Detail(p.x * 3.7);
}
else if (_Finish == 4)
{
float brush = abs(normal.y) > .55 ? p.z : p.y;
float scratches = sin(brush * 82 + sin(p.x * 1.25)) * Detail(brush * 13);
tone = 1 + scratches * .04 + paint * .025;
}
else if (_Finish == 5)
{
float along = p.x + p.z * .42;
float runoff = sin(along * 9.1 + sin(along * 2.1)) * sin(along * 2.9 - .2 * p.y);
float plates = Groove(p.y * .86, .005) + Groove(along * .23 + floor(p.y * .86) * .5, .0038);
float salt = 1 - smoothstep(-.04, .82, p.y);
tone = 1 + salt * .11 + (paint * .1 + runoff * .18 * Detail(along * 1.45) - plates * .16) * _Weather;
}
return tone;
}
fixed4 frag(Output input) : SV_Target
{
float3 p = input.world;
float3 normal = normalize(input.normal);
float3 eye = normalize(_WorldSpaceCameraPos.xyz - p);
if (_Finish == 6)
{
float2 p = input.local.xz;
float rippleX = p.x * 5.7 + p.y * 2.2 - _Time.y * 2.7;
float rippleZ = p.y * 8.3 - p.x * 1.3 + _Time.y * 3.1;
float3 ripple = float3(sin(rippleX) * Detail(p.x * .91), 0, sin(rippleZ) * Detail(p.y * 1.32));
normal = normalize(normal + mul((float3x3)unity_ObjectToWorld, ripple) * .085);
}
float3 eye = unity_OrthoParams.w > .5 ? UNITY_MATRIX_V[2].xyz
: normalize(_WorldSpaceCameraPos.xyz - input.world);
float3 sun = normalize(float3(-.69,.40,-.43));
float3 halfVector = normalize(sun + eye);
float sunlight = saturate(dot(normal,sun));
float sky = saturate(normal.y * .5 + .5);
float fresnel = pow(1 - saturate(dot(eye,normal)), 3.5);
float roughExponent = lerp(220, 9, _Roughness);
float specular = pow(saturate(dot(normal,halfVector)), roughExponent) * (1 - _Roughness * .65);
float roughExponent = lerp(280, 6, _Roughness * _Roughness);
float specular = pow(saturate(dot(normal,halfVector)), roughExponent) * (1 - _Roughness * .68);
float3 reflected = reflect(-eye,normal);
float sunsetStripe = smoothstep(-.08,.13,reflected.y) * (1 - smoothstep(.13,.42,reflected.y));
float3 skyReflection = lerp(float3(.11,.19,.27), float3(.39,.48,.60), saturate(reflected.y))
+ sunsetStripe * float3(.20,.12,.061);
float3 light = lerp(float3(.25,.34,.46),float3(.61,.68,.77),sky) + sunlight * float3(.62,.44,.30);
float micro = sin(p.x * 13.7 + p.y * 19.3) * sin(p.z * 15.4 - p.x * 8);
float abrasion = sin(p.x * .82 + p.z * 1.7) * sin(p.y * 3.5 + p.z * 4.8);
float surfaceGrain = 1 + _Weather * (.055 * micro + .10 * abrasion);
float3 diffuse = _Color.rgb * light * surfaceGrain;
float3 shine = skyReflection * (.07 + fresnel * .24 + _Metal * .21) * (1 - _Roughness * .48)
+ specular * float3(.72,.51,.34) * (.14 + .59 * _Metal);
return fixed4(saturate(diffuse + shine + _Color.rgb * _Emissive * .60), 1);
float overcast = _SoundingsSeaWeather * _SoundingsSeaSailing;
float3 direct = lerp(float3(.58,.46,.34), float3(.20,.24,.28), overcast);
float3 light = lerp(float3(.26,.34,.43), float3(.62,.69,.75), sky) + sunlight * direct;
float3 diffuse = _Color.rgb * light * SurfaceTone(input.local, normalize(input.localNormal));
if (_Waterline > .5 && input.world.y < 2.15)
{
// The ocean is drawn as a screen-wide pass, so mask submerged paint against the same wave field.
float level = _SoundingsSeaSailing > .5
? OceanWave(input.world.xz, _SoundingsSeaTime, _SoundingsSeaWeather).x : 0;
float aboveWater = input.world.y - level;
clip(aboveWater);
diffuse *= lerp(.73, 1, smoothstep(0, .62, aboveWater));
}
if (_Finish == 2)
{
float horizon = 1 - smoothstep(.005, .067 + _Roughness * .12, abs(reflected.y - .025));
float3 glazing = skyReflection * (.30 + fresnel * .62) + float3(.21,.32,.36) * horizon * .28;
float facing = smoothstep(-.12, .49, reflected.y);
float3 glass = diffuse * (.47 + facing * .30) + glazing + specular * float3(.65,.55,.41) * .33;
return fixed4(saturate(lerp(glass, diffuse + glazing * .32 + _Color.rgb * .22, _Emissive)), 1);
}
if (_Finish == 6)
return fixed4(saturate(diffuse * .81 + skyReflection * (.24 + fresnel * .61) + specular * .44), 1);
float3 shine = skyReflection * (.045 + fresnel * .21 + _Metal * .16) * (1 - _Roughness * .56)
+ specular * float3(.73,.60,.43) * (.10 + .47 * _Metal) * saturate(3 * sunlight);
return fixed4(saturate(diffuse + shine + _Color.rgb * _Emissive * .53), 1);
}
ENDCG
}

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

View File

@@ -17,7 +17,7 @@ Shader "Soundings/Passage Wake"
#include "OceanWaves.cginc"
sampler2D _OceanDetail;
float _SeaTime, _WeatherSeverity;
float _SeaTime, _WeatherSeverity, _TrailLength;
struct Input { float4 vertex : POSITION; float4 trace : TEXCOORD0; };
struct Output { float4 clip : SV_POSITION; float4 trace : TEXCOORD0; float2 water : TEXCOORD1; };
@@ -34,23 +34,30 @@ Shader "Soundings/Passage Wake"
fixed4 frag(Output input) : SV_Target
{
float across = abs(input.trace.x);
float across = input.trace.x;
float age = input.trace.y;
float thrust = input.trace.z;
float distance = input.trace.w;
float2 water = input.water;
float eddies = tex2D(_OceanDetail, water * .118 + float2(-.016,.016) * _SeaTime).b;
float flecks = tex2D(_OceanDetail, water * .285 + float2(.008,-.011) * _SeaTime).b;
float disturbed = 1 - smoothstep(.28,.47, across + .065 * (eddies - .5));
float stripes = sin(across * 22 + eddies * 5 + distance * .055);
float churn = smoothstep(.36,.78, eddies * .57 + flecks * .43 + stripes * .14);
float kelvin = 1 - smoothstep(.044,.155, abs(across - .76 + .08 * (eddies - .5)));
float ripples = .41 + .59 * sin(distance * .47 + across * 16 - _SeaTime * 2.8);
float whitewater = disturbed * (.54 + .45 * churn) + kelvin * saturate(ripples) * (.33 + .42 * eddies);
float lifetime = (1 - smoothstep(4, 34, age));
float alpha = whitewater * thrust * lifetime * (.89 - _WeatherSeverity * .13);
float3 foam = lerp(float3(.47,.68,.71), float3(.87,.94,.93), churn * .84 + .15);
return fixed4(foam, saturate(alpha));
float2 cross = float2(dot(water, float2(.85,-.53)), dot(water, float2(.53,.85)));
float eddies = tex2D(_OceanDetail, water * .055 + float2(-.016,.016) * _SeaTime).b;
float bubbles = tex2D(_OceanDetail, cross * .168 + float2(.026,-.011) * _SeaTime).b;
float flecks = tex2D(_OceanDetail, water * .35 + float2(.008,.028) * _SeaTime).b;
float billow = (eddies - .5) * .18 + (bubbles - .5) * .074;
float churn = smoothstep(.31,.73, eddies * .50 + bubbles * .34 + flecks * .16);
float sternMix = smoothstep(2, 26, distance);
float propellers = 1 - smoothstep(.03,.24, abs(abs(across + billow) - .23));
float turbulence = 1 - smoothstep(.19,.56, abs(across + billow));
float core = lerp(propellers, turbulence, sternMix);
float shoulder = abs(across + billow * .45);
float kelvin = 1 - smoothstep(.035,.165, abs(shoulder - .76));
float crests = smoothstep(.18, .91, .5 + .5 * sin(distance * .36 + shoulder * 12.6 - _SeaTime * 1.56 + eddies * 4.3));
float wake = turbulence * .14 + core * (.17 + .69 * churn) + kelvin * crests * (.16 + .35 * eddies);
float endFade = smoothstep(0, min(_TrailLength * .38, 32), _TrailLength - distance);
float lifetime = (1 - smoothstep(2, 34, age)) * endFade;
float alpha = wake * thrust * lifetime * (.90 - _WeatherSeverity * .20);
float3 foam = lerp(float3(.29,.50,.55), float3(.90,.96,.95), churn * .83 + .08);
return fixed4(foam, alpha);
}
ENDCG
}