diff --git a/shaders/ogl46/mat_bugs_windscreen.frag b/shaders/ogl46/mat_bugs_windscreen.frag index 93f6a4032..081d81c7d 100644 --- a/shaders/ogl46/mat_bugs_windscreen.frag +++ b/shaders/ogl46/mat_bugs_windscreen.frag @@ -102,7 +102,8 @@ const float bugs_unknown_level = 1.0; // upper limit of the dirt where the wipe const float bugs_wiper_clean = 1.0; // 1 = wipers wipe the bugs off (uses wipermask), 0 = wipers ignore them const float bugs_gloss = 0.45; // shininess of the wet splats (sun / headlight glints on the bumps), 0 = matt const float bugs_bump = 1.0; // strength of the 3D relief from the normal map, 0 = flat -const float bugs_halo_blur = 0.45; // blur of the scene in a ring around every bug (0 = off, 1 = full); done in the post-processing (rain_windscreen_haze.glsl) +const float bugs_halo_blur = 0.8; // blur of the scene seen through the see-through parts of a bug (its texture half transparent: wings, + // the thin smear of the splat), none around it (0 = off, 1 = full); done in the post-processing const float bugs_halo_size = 1.15; // ring radius = bug half-size * this (1 = only under the splat, max 1.6) const float bugs_halo_px = 60.0; // a bug this many pixels wide on screen gets the full blur, smaller ones less (the blur radius is fixed in pixels) const float bugs_vertical = 0.0; // -1..1: more dirt at the bottom (<0) or at the top (>0) of the pane, 0 = even @@ -331,13 +332,6 @@ void bugLayer(float gridSize, float density, uint layerSeed, // Blur ring around the splat (greasy smear): strongest next to the bug, fading out // (the post pass blurs with a fixed radius in pixels, so a bug that is small on screen gets less of it) - float haloR = size * 0.5 * clamp(bugs_halo_size, 1.0, 1.6); - float dist = length(d); - if (dist < haloR) - { - float pxScale = clamp(size / max(pixelUV, 1e-6) / max(bugs_halo_px, 1.0), 0.15, 1.0); - smear = max(smear, (1.0 - smoothstep(0.5 * haloR, haloR, dist)) * haloStrength * appear * pxScale); - } float c = cos(ang); float s = sin(ang); @@ -357,6 +351,12 @@ void bugLayer(float gridSize, float density, uint layerSeed, t.rgb = mix(t.rgb, vec3(0.42, 0.34, 0.16), lightMix); float a = clamp(t.a * appear * bugs_opacity * opacityMul, 0.0, 1.0); + // the scene blurred only where the bug is see-through (half transparent), not around it and not where it's opaque + // (the post pass blurs with a fixed radius in pixels, so a bug that is small on screen gets less of it) + float pxScale = clamp(size / max(pixelUV, 1e-6) / max(bugs_halo_px, 1.0), 0.15, 1.0); + float seeThrough = smoothstep(0.03, 0.3, a) * (1.0 - smoothstep(0.75, 0.95, a)); + smear = max(smear, seeThrough * haloStrength * pxScale); + // relief: tangent-space normal of the splat -> glass UV frame (undo the mirror, then the rotation) vec4 nm = textureLod(normalmap, tileOffset(choice) + local * 0.5, lod); vec2 nxy = (nm.rg * 2.0 - 1.0) * bugs_bump * appear; // a splat that is still settling is flatter @@ -493,8 +493,8 @@ void main() if (MOTIONBLUR_ENABLED) { // alpha 0 = blending keeps the scene's own motion vectors - // the bug itself stays sharp (1 - bugA); no blur over opaque parts of the pane (1 - glassA) - float blurMask = clamp(smear * bugs_halo_blur * (1.0 - bugA) * (1.0 - smoothstep(0.5, 0.95, glassA)), 0.0, 1.0); + // only the see-through parts of the bugs (smear); no blur over opaque parts of the pane (1 - glassA) + float blurMask = clamp(smear * bugs_halo_blur * (1.0 - smoothstep(0.5, 0.95, glassA)), 0.0, 1.0); out_motion = (blurMask >= 0.01) ? vec4(WS_ENC * blurMask, 0.0, 0.0, 1.0) : vec4(0.0); } } diff --git a/shaders/ogl46/mat_rain_windscreen.frag b/shaders/ogl46/mat_rain_windscreen.frag index 06a221f89..ec7fdc6a3 100644 --- a/shaders/ogl46/mat_rain_windscreen.frag +++ b/shaders/ogl46/mat_rain_windscreen.frag @@ -146,19 +146,32 @@ const float streak_link = 1.5; // head widths above the head where the tr // (or in a light wind) nothing of it shows: the rain lands, grows and runs down as it always did. const float wind_drag_gain = 4.0; // how strongly the air drives the water (1 = the drag of the stock shader: on a // vertical front glass the water would go up only at ~250 km/h) -const float wind_streaks = 3.0; // density of the rivulets driven by the air, at full drag (x streak_density) -const float wind_cell_scale = 0.36; // the rivulets of the air: their cells this much narrower ... -const float wind_run_scale = 0.28; // ... and shorter than those of gravity: many small drops with short trails -const float wind_head_scale = 0.55; // their heads this much smaller +const float wind_streaks = 1.5; // density of the rivulets driven by the air, at full drag (x streak_density) +const float wind_cell_scale = 0.5; // the rivulets of the air: their cells this much narrower ... +const float wind_run_scale = 1.2; // ... and their runs this long against those of gravity: few drops with long trails +const float wind_head_scale = 0.4; // their heads this much smaller (a small bead at the front of a long trail) const int wind_layers = 4; // layers of them, each with drops of its own (1 .. 4) -const float wind_long_run = 1.6; // the last layer: its trails this much longer than those of gravity (the long ones, a part of all) -const float wind_streak_period = 14.0; // seconds a rivulet driven by the air lives (they run faster than the ones of gravity) +const float wind_long_run = 3.0; // the last layer: its trails this much longer than those of gravity (the long ones, a part of all) +const float wind_streak_period = 18.0; // seconds a rivulet driven by the air lives (they run faster than the ones of gravity) const float drop_wind_stretch = 0.4; // drops are stretched up to this much along the push of the air (0 = off) const float WS_DRAG_SPEED = 24.0; // speed of the air along the glass at which its drag equals the weight of a drop, m/s const float WS_HEAD_ON = 0.35; // share of the air meeting the glass head on which turns up along it const float WS_WIND_STEP = 0.1309; // the direction of the rivulets of the air in steps of 7.5 degrees (no seams on a // curved glass, where every triangle would turn them a little) +// --- The rivulets of the air of different thickness: the width of every one is drawn from this range (x streak_head, x +// wind_head_scale), most of them thin, a few thick (never wider than their cell) ------------------------------------------------- +const float streak_thin = 0.5; // the thinnest +const float streak_thick = 2.0; // the thickest +const float streak_thick_bias = 2.0; // > 1: more thin ones +// --- What the blades leave: they don't take every drop (a few stay where they were), and the water they push lies along the edge +// of their sweep, just outside it, as a row of beads (where the blades went lately) ------------------------------------------------ +const float wiper_miss = 0.05; // share of the drops a blade goes over without taking them +const float wiper_edge_boost = 0.0; // along the edge of the sweep this many times more drops (and droplets) (0 = off) ... +const float wiper_edge_size = 0.65; // ... this much smaller: a row of beads +const float wiper_edge_reach = 4.0; // how wide the row is: the mip level of the mask read (4: ~16 texels of the mask out) +const float wiper_edge_keep = 180.0; // seconds after the last stroke the water at the edge keeps (then it's like the rest of the glass) + #ifndef STREAK_FLIP_Y #define STREAK_FLIP_Y 0 // set to 1 if the rivulets run UP the glass (head on top) #endif @@ -301,6 +314,7 @@ uint wsLayerSalt = 91u; float wsLayerHead = 1.0; // x streak_head float wsLayerCos = 1.0; // the layer is turned by this angle (its "down" is the way its water runs on the glass) float wsLayerSin = 0.0; +bool wsLayerVaried = false; // the widths of its rivulets from streak_thin .. streak_thick (the air) // glass UV (v up) -> coordinates of the layer, where the rivulets run down (-v) vec2 wsToLayerDir(vec2 v) @@ -335,6 +349,7 @@ void wsSetLayer(int layer) wsLayerHead = 1.0; wsLayerCos = 1.0; wsLayerSin = 0.0; + wsLayerVaried = false; } else { @@ -344,6 +359,7 @@ void wsSetLayer(int layer) wsLayerHead = wind_head_scale; wsLayerCos = wsWindCos; wsLayerSin = wsWindSin; + wsLayerVaried = true; } } @@ -355,7 +371,11 @@ Riv getRiv(vec2 sCell, float sCW, float sCH, float gridSize) float sPeriod = wsLayerPeriod * mix(0.6, 1.6, RandF(sSeed)); float sPhase = fract(time / sPeriod + RandF(sSeed)); r.life = smoothstep(0.0, 0.05, sPhase) * (1.0 - smoothstep(0.86, 1.0, sPhase)); - r.width = streak_head * wsLayerHead / gridSize * mix(0.75, 1.25, RandF(sSeed)); + float wr = RandF(sSeed); + r.width = streak_head * wsLayerHead / gridSize + * (wsLayerVaried ? mix(streak_thin, streak_thick, pow(wr, streak_thick_bias)) : mix(0.75, 1.25, wr)); + if (wsLayerVaried) + r.width = min(r.width, sCW / 2.6); // the trail with its swing (sMargin) stays in its cell r.headH = r.width * 0.88 * streak_uv_aspect; float sSpan = max(sCH * mix(0.35, 0.70, RandF(sSeed)), r.headH * 3.0); // stick-slip: the drop waits, then lurches forward; N waits on the way down @@ -565,6 +585,20 @@ float wsWipeAge(vec2 co) return age; } +// how much the place Co (texture UV) lies along the edge of the sweep of the blades, just outside it: 0 .. 1. the mask is 0 there and +// a coarse level of it isn't (the sweep is near). times wsWiperRecent: only where the blades went lately +float wsWiperRecent = 0.0; +float wsWiperEdge(vec2 co) +{ + if ((wiper_edge_boost <= 0.0) || (wsWiperRecent <= 0.0)) + return 0.0; + vec4 m = textureLod(wipermask, co, 0.0); + if (max(max(m.r, m.g), max(m.b, m.a)) > 0.001) + return 0.0; + vec4 c = textureLod(wipermask, co, wiper_edge_reach); + return smoothstep(0.01, 0.12, max(max(c.r, c.g), max(c.b, c.a))) * wsWiperRecent; +} + void main() { // ---- screen-space derivatives (before any non-uniform flow) ---- @@ -609,6 +643,13 @@ void main() // wiper state of this pixel (blur, micro droplets) float hazeSide; float wipeVis = GetMixFactor(f_coord, hazeSide); + // the blades went over the glass lately (the water they pushed still lies along the edge of the sweep) + for (int i = 0; i < 4; ++i) + { + float t = max(wiper_timer_out[i], wiper_timer_return[i]); + if ((t > -500.0) && (t <= time)) + wsWiperRecent = max(wsWiperRecent, 1.0 - smoothstep(0.5 * wiper_edge_keep, wiper_edge_keep, time - t)); + } Hit hit; hit.score = 0.0; hit.cov = 0.0; hit.colA = 0.0; hit.n = vec3(0.0, 0.0, 1.0); @@ -683,16 +724,20 @@ void main() uint ep = uint(mod(epoch, 65521.0)); // activation first (cheap), the wiper texture only for live drops uint s1 = Hash(uvec3(key, ep * 4u + 1u)); - if (RandF(s1) > rain_params.x * drop_density) + float edge = wsWiperEdge((nc + 0.5) / gridSize); + if (RandF(s1) > min(rain_params.x * drop_density * (1.0 + wiper_edge_boost * edge), 0.95)) continue; + // a drop the blades miss: the same drop before and after the stroke, left where it is + bool missed = RandF(s1) < wiper_miss; float side; - float mixF = GetMixFactor((nc + 0.5) / gridSize, side); + float mixF = missed ? 1.0 : GetMixFactor((nc + 0.5) / gridSize, side); + if (missed) side = 0.0; uint s2 = Hash(uvec3(key, ep * 4u + 2u + uint(side) * 2u)); if (mixF < RandF(s2)) continue; vec2 center = (nc + vec2(RandF(s2), RandF(s2))) / gridSize; - float size = mix(drop_size_min, drop_size_max, pow(RandF(s2), drop_size_bias)) / gridSize; + float size = mix(drop_size_min, drop_size_max, pow(RandF(s2), drop_size_bias)) / gridSize * mix(1.0, wiper_edge_size, edge); float sag = 1.0 + drop_sag * RandF(s2); float flipX = (RandF(s2) < 0.5) ? 1.0 : 0.0; float choice = RandF(s2); @@ -754,7 +799,7 @@ void main() float mph = fract(mtt); uint mep = uint(mod(floor(mtt), 65521.0)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); - if (RandF(m1) < rain_params.x * micro_density) + if (RandF(m1) < min(rain_params.x * micro_density * (1.0 + wiper_edge_boost * wsWiperEdge((mc + 0.5) / mg)), 0.95)) { uint m2 = Hash(uvec3(mk, mep * 4u + 2u + uint(hazeSide) * 2u)); if (wipeVis >= RandF(m2)) diff --git a/shaders/ogl46/postfx_motionblur.frag b/shaders/ogl46/postfx_motionblur.frag index de4984eb4..4b2da1629 100644 --- a/shaders/ogl46/postfx_motionblur.frag +++ b/shaders/ogl46/postfx_motionblur.frag @@ -22,7 +22,7 @@ void main() if (wsIsDrop(rawv)) { vec4 picture = texture(color_tex, f_coords); - out_color = vec4((picture.a > 0.5 * (1.0 + WS_HAZED)) ? picture.rgb + out_color = vec4(wsWasHazed(picture.a) ? picture.rgb : wsDropRefraction(color_tex, velocity_tex, depth_tex, f_coords, rawv), 1.0); return; } @@ -30,7 +30,7 @@ void main() if (blurAmt > 0.0) { vec4 picture = texture(color_tex, f_coords); - out_color = vec4((picture.a > 0.5 * (1.0 + WS_HAZED)) ? picture.rgb : wsHaze(color_tex, velocity_tex, f_coords, blurAmt), 1.0); + out_color = vec4(wsWasHazed(picture.a) ? picture.rgb : wsHaze(color_tex, velocity_tex, f_coords, blurAmt), 1.0); return; } diff --git a/shaders/ogl46/postfx_taa.frag b/shaders/ogl46/postfx_taa.frag index a4e9566d4..c06a03fcb 100644 --- a/shaders/ogl46/postfx_taa.frag +++ b/shaders/ogl46/postfx_taa.frag @@ -42,7 +42,7 @@ vec3 wsStabilize(vec3 current, ivec2 pixel) if (false == TAA_HISTORY_VALID) return current; vec4 last = texelFetch(history_tex, pixel, 0); - if (any(isnan(last)) || (last.a < 0.5 * (1.0 + WS_HAZED))) // not a drop or haze pixel in the last frame + if (any(isnan(last)) || (false == wsWasHazed(last.a))) // not a drop or haze pixel in the last frame return current; vec2 size = vec2(textureSize(color_tex, 0)); float depth = texelFetch(depth_tex, pixel, 0).r; diff --git a/shaders/ogl46/rain_windscreen_haze.glsl b/shaders/ogl46/rain_windscreen_haze.glsl index 6dd9a4cde..73be4b573 100644 --- a/shaders/ogl46/rain_windscreen_haze.glsl +++ b/shaders/ogl46/rain_windscreen_haze.glsl @@ -10,7 +10,15 @@ const float WS_ENC = 64.0; // must match mat_rain_windscreen.frag const float WS_FLOOR = 0.004; // = 0.256 in raw velocity units: everything below is real motion -const float WS_HAZED = 2.0; // alpha of the picture the taa already blurred +const float WS_HAZED = -4.0; // alpha of the picture the taa already blurred: below anything a scene writes (additive + // particles took the alpha of the image above 1.5, and the motion blur then left the haze of a + // bug or of the glass out on some frames: a flicker). negative, so the lock of the taa takes 0 + +// whether the picture was blurred by the taa already (WS_HAZED in its alpha) +bool wsWasHazed(float alpha) +{ + return alpha < -3.0; +} // blur of hazy glass const float WS_RADIUS = 0.014; // max blur radius, fraction of screen height @@ -20,7 +28,10 @@ const float WS_HAZE_LIGHT_CAP = 12.0; // the most a light adds to the haze aro // strength of the blur request, 0 for pixels that are not blur pixels float wsBlur(vec2 raw) { - if (raw.x > 100.0 || raw.y > 100.0) // a blended edge with something else: not a blur pixel + // a blended edge with something else: not a blur pixel. the haze is asked with y = 0; with msaa the samples of a pixel are + // averaged, and the edge of a drop (y half of a drop's) came out as a full haze request: a ring blurred around the drop which + // flickered as the edges moved over the samples + if (raw.x > 100.0 || raw.y > 1.0) return 0.0; float m = clamp(raw.x / WS_ENC, 0.0, 1.0); return clamp((m - WS_FLOOR) / (1.0 - WS_FLOOR), 0.0, 1.0); @@ -139,7 +150,9 @@ float wsLum(vec3 c) // a drop pixel (drop, rivulet): both values in 132..252 bool wsIsDrop(vec2 raw) { - return raw.x > 120.0 && raw.y > 120.0; + // 132 .. 252 exactly: with msaa the edge of a drop averaged with the scene behind (half the values, up to 126) isn't a drop, + // else its decoded bend was nonsense, pulling the picture from far away for a frame (a drop flashing) + return raw.x > 131.5 && raw.y > 131.5; } vec2 wsBend(vec2 raw) @@ -148,19 +161,43 @@ vec2 wsBend(vec2 raw) } #ifndef LAYOUT_POST +// the image of the reflections around Uv as blurred as its mip level Lod, but round: a level of the mipmaps is a grid of squares +// (2^Lod pixels each), and a light read from it alone lit the drops in a square around it. a ring of taps of the finer level +// around the place, weighed as a soft disc, gives the same blur without the squares +vec3 wsHistoryRound(vec2 uv, float lod) +{ + float level = min(lod, ssr_params2.x); + float finer = max(level - 1.0, 0.0); + vec2 pixel = 1.0 / vec2(textureSize(ws_light_history, 0)); + float radius = 0.6 * exp2(level); // pixels of the image + vec3 sum = wsSafe(textureLod(ws_light_history, uv, finer).rgb) * 0.2; + for (int i = 0; i < 8; ++i) + { + float a = (float(i) + 0.5) * 0.7853982; + sum += wsSafe(textureLod(ws_light_history, uv + vec2(cos(a), sin(a)) * radius * pixel, finer).rgb) * 0.06; + sum += wsSafe(textureLod(ws_light_history, uv + vec2(cos(a + 0.3927), sin(a + 0.3927)) * (2.0 * radius) * pixel, finer).rgb) * 0.04; + } + return sum; +} + vec3 wsLightExcess(vec2 uv, float lod, vec3 wide) { - vec3 c = wsSafe(textureLod(ws_light_history, uv, min(lod, ssr_params2.x)).rgb); + vec3 c = wsHistoryRound(uv, lod); vec3 excess = max(c - wide * WS_LIGHT_CONTRAST, vec3(0.0)); - return excess * smoothstep(0.5 * WS_LIGHT_MIN_LUM, WS_LIGHT_MIN_LUM, wsLum(excess)); + // no threshold with an edge: a light dims away from it (the drops right by a lamp the brightest, then less and less); full + // from twice WS_LIGHT_MIN_LUM above the place around, as much as before there + return excess * clamp(wsLum(excess) / (2.0 * WS_LIGHT_MIN_LUM), 0.0, 1.0); } vec3 wsLightGlow(vec2 uv) { if ((ssr_params.x < 1.0) || (textureSize(ws_light_history, 0).x < 16)) return vec3(0.0); - vec3 wide = wsSafe(textureLod(ws_light_history, uv, min(WS_LIGHT_WIDE, ssr_params2.x)).rgb); - vec3 glow = wsLightExcess(uv, WS_LIGHT_FINE, wide) + WS_LIGHT_MID_SHARE * wsLightExcess(uv, WS_LIGHT_MID, wide); + vec3 wide = wsHistoryRound(uv, WS_LIGHT_WIDE); + // the near light in full, the one a little further away fading with it squared: the farther the drop, the less + vec3 mid = wsLightExcess(uv, WS_LIGHT_MID, wide); + float midF = clamp(wsLum(mid) / (2.0 * WS_LIGHT_MIN_LUM), 0.0, 1.0); + vec3 glow = wsLightExcess(uv, WS_LIGHT_FINE, wide) + WS_LIGHT_MID_SHARE * mid * midF; glow *= WS_LIGHT_GAIN; // a light close by is kept to the brightness of one light return glow * min(1.0, WS_LIGHT_CAP / max(wsLum(glow), 1e-4)); diff --git a/shaders/vk14/mat_bugs_windscreen.frag b/shaders/vk14/mat_bugs_windscreen.frag index 8037ddff6..fc0396286 100644 --- a/shaders/vk14/mat_bugs_windscreen.frag +++ b/shaders/vk14/mat_bugs_windscreen.frag @@ -107,7 +107,8 @@ const float bugs_unknown_level = 1.0; // upper limit of the dirt where the wipe const float bugs_wiper_clean = 1.0; // 1 = wipers wipe the bugs off (uses wipermask), 0 = wipers ignore them const float bugs_gloss = 0.45; // shininess of the wet splats (sun / headlight glints on the bumps), 0 = matt const float bugs_bump = 1.0; // strength of the 3D relief from the normal map, 0 = flat -const float bugs_halo_blur = 0.45; // blur of the scene in a ring around every bug (0 = off, 1 = full); done in the post-processing (rain_windscreen_haze.glsl) +const float bugs_halo_blur = 0.8; // blur of the scene seen through the see-through parts of a bug (its texture half transparent: wings, + // the thin smear of the splat), none around it (0 = off, 1 = full); done in the post-processing const float bugs_halo_size = 1.15; // ring radius = bug half-size * this (1 = only under the splat, max 1.6) const float bugs_halo_px = 60.0; // a bug this many pixels wide on screen gets the full blur, smaller ones less (the blur radius is fixed in pixels) const float bugs_vertical = 0.0; // -1..1: more dirt at the bottom (<0) or at the top (>0) of the pane, 0 = even @@ -336,13 +337,6 @@ void bugLayer(float gridSize, float density, uint layerSeed, // Blur ring around the splat (greasy smear): strongest next to the bug, fading out // (the post pass blurs with a fixed radius in pixels, so a bug that is small on screen gets less of it) - float haloR = size * 0.5 * clamp(bugs_halo_size, 1.0, 1.6); - float dist = length(d); - if (dist < haloR) - { - float pxScale = clamp(size / max(pixelUV, 1e-6) / max(bugs_halo_px, 1.0), 0.15, 1.0); - smear = max(smear, (1.0 - smoothstep(0.5 * haloR, haloR, dist)) * haloStrength * appear * pxScale); - } float c = cos(ang); float s = sin(ang); @@ -362,6 +356,12 @@ void bugLayer(float gridSize, float density, uint layerSeed, t.rgb = mix(t.rgb, vec3(0.42, 0.34, 0.16), lightMix); float a = clamp(t.a * appear * bugs_opacity * opacityMul, 0.0, 1.0); + // the scene blurred only where the bug is see-through (half transparent), not around it and not where it's opaque + // (the post pass blurs with a fixed radius in pixels, so a bug that is small on screen gets less of it) + float pxScale = clamp(size / max(pixelUV, 1e-6) / max(bugs_halo_px, 1.0), 0.15, 1.0); + float seeThrough = smoothstep(0.03, 0.3, a) * (1.0 - smoothstep(0.75, 0.95, a)); + smear = max(smear, seeThrough * haloStrength * pxScale); + // relief: tangent-space normal of the splat -> glass UV frame (undo the mirror, then the rotation) vec4 nm = textureLod(normalmap, tileOffset(choice) + local * 0.5, lod); vec2 nxy = (nm.rg * 2.0 - 1.0) * bugs_bump * appear; // a splat that is still settling is flatter @@ -498,8 +498,8 @@ void main() if (MOTIONBLUR_ENABLED) { // alpha 0 = blending keeps the scene's own motion vectors - // the bug itself stays sharp (1 - bugA); no blur over opaque parts of the pane (1 - glassA) - float blurMask = clamp(smear * bugs_halo_blur * (1.0 - bugA) * (1.0 - smoothstep(0.5, 0.95, glassA)), 0.0, 1.0); + // only the see-through parts of the bugs (smear); no blur over opaque parts of the pane (1 - glassA) + float blurMask = clamp(smear * bugs_halo_blur * (1.0 - smoothstep(0.5, 0.95, glassA)), 0.0, 1.0); out_motion = (blurMask >= 0.01) ? vec4(WS_ENC * blurMask, 0.0, 0.0, 1.0) : vec4(0.0); } } diff --git a/shaders/vk14/mat_rain_windscreen.frag b/shaders/vk14/mat_rain_windscreen.frag index fa76bc95e..975fd3eb8 100644 --- a/shaders/vk14/mat_rain_windscreen.frag +++ b/shaders/vk14/mat_rain_windscreen.frag @@ -151,19 +151,32 @@ const float streak_link = 1.5; // head widths above the head where the tr // (or in a light wind) nothing of it shows: the rain lands, grows and runs down as it always did. const float wind_drag_gain = 4.0; // how strongly the air drives the water (1 = the drag of the stock shader: on a // vertical front glass the water would go up only at ~250 km/h) -const float wind_streaks = 3.0; // density of the rivulets driven by the air, at full drag (x streak_density) -const float wind_cell_scale = 0.36; // the rivulets of the air: their cells this much narrower ... -const float wind_run_scale = 0.28; // ... and shorter than those of gravity: many small drops with short trails -const float wind_head_scale = 0.55; // their heads this much smaller +const float wind_streaks = 1.5; // density of the rivulets driven by the air, at full drag (x streak_density) +const float wind_cell_scale = 0.5; // the rivulets of the air: their cells this much narrower ... +const float wind_run_scale = 1.2; // ... and their runs this long against those of gravity: few drops with long trails +const float wind_head_scale = 0.4; // their heads this much smaller (a small bead at the front of a long trail) const int wind_layers = 4; // layers of them, each with drops of its own (1 .. 4) -const float wind_long_run = 1.6; // the last layer: its trails this much longer than those of gravity (the long ones, a part of all) -const float wind_streak_period = 14.0; // seconds a rivulet driven by the air lives (they run faster than the ones of gravity) +const float wind_long_run = 3.0; // the last layer: its trails this much longer than those of gravity (the long ones, a part of all) +const float wind_streak_period = 18.0; // seconds a rivulet driven by the air lives (they run faster than the ones of gravity) const float drop_wind_stretch = 0.4; // drops are stretched up to this much along the push of the air (0 = off) const float WS_DRAG_SPEED = 24.0; // speed of the air along the glass at which its drag equals the weight of a drop, m/s const float WS_HEAD_ON = 0.35; // share of the air meeting the glass head on which turns up along it const float WS_WIND_STEP = 0.1309; // the direction of the rivulets of the air in steps of 7.5 degrees (no seams on a // curved glass, where every triangle would turn them a little) +// --- The rivulets of the air of different thickness: the width of every one is drawn from this range (x streak_head, x +// wind_head_scale), most of them thin, a few thick (never wider than their cell) ------------------------------------------------- +const float streak_thin = 0.5; // the thinnest +const float streak_thick = 2.0; // the thickest +const float streak_thick_bias = 2.0; // > 1: more thin ones +// --- What the blades leave: they don't take every drop (a few stay where they were), and the water they push lies along the edge +// of their sweep, just outside it, as a row of beads (where the blades went lately) ------------------------------------------------ +const float wiper_miss = 0.05; // share of the drops a blade goes over without taking them +const float wiper_edge_boost = 0.0; // along the edge of the sweep this many times more drops (and droplets) (0 = off) ... +const float wiper_edge_size = 0.65; // ... this much smaller: a row of beads +const float wiper_edge_reach = 4.0; // how wide the row is: the mip level of the mask read (4: ~16 texels of the mask out) +const float wiper_edge_keep = 180.0; // seconds after the last stroke the water at the edge keeps (then it's like the rest of the glass) + #ifndef STREAK_FLIP_Y #define STREAK_FLIP_Y 0 // set to 1 if the rivulets run UP the glass (head on top) #endif @@ -306,6 +319,7 @@ uint wsLayerSalt = 91u; float wsLayerHead = 1.0; // x streak_head float wsLayerCos = 1.0; // the layer is turned by this angle (its "down" is the way its water runs on the glass) float wsLayerSin = 0.0; +bool wsLayerVaried = false; // the widths of its rivulets from streak_thin .. streak_thick (the air) // glass UV (v up) -> coordinates of the layer, where the rivulets run down (-v) vec2 wsToLayerDir(vec2 v) @@ -340,6 +354,7 @@ void wsSetLayer(int layer) wsLayerHead = 1.0; wsLayerCos = 1.0; wsLayerSin = 0.0; + wsLayerVaried = false; } else { @@ -349,6 +364,7 @@ void wsSetLayer(int layer) wsLayerHead = wind_head_scale; wsLayerCos = wsWindCos; wsLayerSin = wsWindSin; + wsLayerVaried = true; } } @@ -360,7 +376,11 @@ Riv getRiv(vec2 sCell, float sCW, float sCH, float gridSize) float sPeriod = wsLayerPeriod * mix(0.6, 1.6, RandF(sSeed)); float sPhase = fract(time / sPeriod + RandF(sSeed)); r.life = smoothstep(0.0, 0.05, sPhase) * (1.0 - smoothstep(0.86, 1.0, sPhase)); - r.width = streak_head * wsLayerHead / gridSize * mix(0.75, 1.25, RandF(sSeed)); + float wr = RandF(sSeed); + r.width = streak_head * wsLayerHead / gridSize + * (wsLayerVaried ? mix(streak_thin, streak_thick, pow(wr, streak_thick_bias)) : mix(0.75, 1.25, wr)); + if (wsLayerVaried) + r.width = min(r.width, sCW / 2.6); // the trail with its swing (sMargin) stays in its cell r.headH = r.width * 0.88 * streak_uv_aspect; float sSpan = max(sCH * mix(0.35, 0.70, RandF(sSeed)), r.headH * 3.0); // stick-slip: the drop waits, then lurches forward; N waits on the way down @@ -570,6 +590,20 @@ float wsWipeAge(vec2 co) return age; } +// how much the place Co (texture UV) lies along the edge of the sweep of the blades, just outside it: 0 .. 1. the mask is 0 there and +// a coarse level of it isn't (the sweep is near). times wsWiperRecent: only where the blades went lately +float wsWiperRecent = 0.0; +float wsWiperEdge(vec2 co) +{ + if ((wiper_edge_boost <= 0.0) || (wsWiperRecent <= 0.0)) + return 0.0; + vec4 m = textureLod(wipermask, co, 0.0); + if (max(max(m.r, m.g), max(m.b, m.a)) > 0.001) + return 0.0; + vec4 c = textureLod(wipermask, co, wiper_edge_reach); + return smoothstep(0.01, 0.12, max(max(c.r, c.g), max(c.b, c.a))) * wsWiperRecent; +} + void main() { // ---- screen-space derivatives (before any non-uniform flow) ---- @@ -614,6 +648,13 @@ void main() // wiper state of this pixel (blur, micro droplets) float hazeSide; float wipeVis = GetMixFactor(f_coord, hazeSide); + // the blades went over the glass lately (the water they pushed still lies along the edge of the sweep) + for (int i = 0; i < 4; ++i) + { + float t = max(wiper_timer_out[i], wiper_timer_return[i]); + if ((t > -500.0) && (t <= time)) + wsWiperRecent = max(wsWiperRecent, 1.0 - smoothstep(0.5 * wiper_edge_keep, wiper_edge_keep, time - t)); + } Hit hit; hit.score = 0.0; hit.cov = 0.0; hit.colA = 0.0; hit.n = vec3(0.0, 0.0, 1.0); @@ -688,16 +729,20 @@ void main() uint ep = uint(mod(epoch, 65521.0)); // activation first (cheap), the wiper texture only for live drops uint s1 = Hash(uvec3(key, ep * 4u + 1u)); - if (RandF(s1) > rain_params.x * drop_density) + float edge = wsWiperEdge((nc + 0.5) / gridSize); + if (RandF(s1) > min(rain_params.x * drop_density * (1.0 + wiper_edge_boost * edge), 0.95)) continue; + // a drop the blades miss: the same drop before and after the stroke, left where it is + bool missed = RandF(s1) < wiper_miss; float side; - float mixF = GetMixFactor((nc + 0.5) / gridSize, side); + float mixF = missed ? 1.0 : GetMixFactor((nc + 0.5) / gridSize, side); + if (missed) side = 0.0; uint s2 = Hash(uvec3(key, ep * 4u + 2u + uint(side) * 2u)); if (mixF < RandF(s2)) continue; vec2 center = (nc + vec2(RandF(s2), RandF(s2))) / gridSize; - float size = mix(drop_size_min, drop_size_max, pow(RandF(s2), drop_size_bias)) / gridSize; + float size = mix(drop_size_min, drop_size_max, pow(RandF(s2), drop_size_bias)) / gridSize * mix(1.0, wiper_edge_size, edge); float sag = 1.0 + drop_sag * RandF(s2); float flipX = (RandF(s2) < 0.5) ? 1.0 : 0.0; float choice = RandF(s2); @@ -759,7 +804,7 @@ void main() float mph = fract(mtt); uint mep = uint(mod(floor(mtt), 65521.0)); uint m1 = Hash(uvec3(mk, mep * 4u + 1u)); - if (RandF(m1) < rain_params.x * micro_density) + if (RandF(m1) < min(rain_params.x * micro_density * (1.0 + wiper_edge_boost * wsWiperEdge((mc + 0.5) / mg)), 0.95)) { uint m2 = Hash(uvec3(mk, mep * 4u + 2u + uint(hazeSide) * 2u)); if (wipeVis >= RandF(m2)) diff --git a/shaders/vk14/postfx_dlss_motion.frag b/shaders/vk14/postfx_dlss_motion.frag index dcb91e498..e94ed8d20 100644 --- a/shaders/vk14/postfx_dlss_motion.frag +++ b/shaders/vk14/postfx_dlss_motion.frag @@ -20,6 +20,12 @@ void main() ivec2 pixel = ivec2(gl_FragCoord.xy); vec2 velocity = texelFetch(velocity_tex, pixel, 0).xy; float depth = texelFetch(depth_tex, pixel, 0).r; + // the windscreens (mat_rain_windscreen, mat_bugs_windscreen) send the post-processing their drops and haze as large values + // (real motion is far below a quarter of the screen per frame): no motion for dlss there, the glass goes with the camera + if (any(greaterThan(abs(velocity), vec2(0.25)))) + { + velocity = vec2(0.0); + } if (depth <= 0.0) { vec4 world = mat4(param[2], param[3], param[4], param[5]) * vec4(f_coords * 2.0 - 1.0, depth, 1.0); diff --git a/shaders/vk14/postfx_motionblur.frag b/shaders/vk14/postfx_motionblur.frag index 495114304..cb26aa1cc 100644 --- a/shaders/vk14/postfx_motionblur.frag +++ b/shaders/vk14/postfx_motionblur.frag @@ -26,7 +26,7 @@ void main() if (wsIsDrop(rawv)) { vec4 picture = texture(color_tex, f_coords); - out_color = vec4((picture.a > 0.5 * (1.0 + WS_HAZED)) ? picture.rgb + out_color = vec4(wsWasHazed(picture.a) ? picture.rgb : wsDropRefraction(color_tex, velocity_tex, depth_tex, f_coords, rawv), 1.0); return; } @@ -34,7 +34,7 @@ void main() if (blurAmt > 0.0) { vec4 picture = texture(color_tex, f_coords); - out_color = vec4((picture.a > 0.5 * (1.0 + WS_HAZED)) ? picture.rgb : wsHaze(color_tex, velocity_tex, f_coords, blurAmt), 1.0); + out_color = vec4(wsWasHazed(picture.a) ? picture.rgb : wsHaze(color_tex, velocity_tex, f_coords, blurAmt), 1.0); return; } diff --git a/shaders/vk14/postfx_taa.frag b/shaders/vk14/postfx_taa.frag index 6e01a3b25..281c6b07b 100644 --- a/shaders/vk14/postfx_taa.frag +++ b/shaders/vk14/postfx_taa.frag @@ -44,7 +44,7 @@ vec3 wsStabilize(vec3 current, ivec2 pixel) if (false == TAA_HISTORY_VALID) return current; vec4 last = texelFetch(history_tex, pixel, 0); - if (any(isnan(last)) || (last.a < 0.5 * (1.0 + WS_HAZED))) // not a drop or haze pixel in the last frame + if (any(isnan(last)) || (false == wsWasHazed(last.a))) // not a drop or haze pixel in the last frame return current; vec2 size = vec2(textureSize(color_tex, 0)); float depth = texelFetch(depth_tex, pixel, 0).r; diff --git a/shaders/vk14/rain_windscreen_haze.glsl b/shaders/vk14/rain_windscreen_haze.glsl index 6dd9a4cde..73be4b573 100644 --- a/shaders/vk14/rain_windscreen_haze.glsl +++ b/shaders/vk14/rain_windscreen_haze.glsl @@ -10,7 +10,15 @@ const float WS_ENC = 64.0; // must match mat_rain_windscreen.frag const float WS_FLOOR = 0.004; // = 0.256 in raw velocity units: everything below is real motion -const float WS_HAZED = 2.0; // alpha of the picture the taa already blurred +const float WS_HAZED = -4.0; // alpha of the picture the taa already blurred: below anything a scene writes (additive + // particles took the alpha of the image above 1.5, and the motion blur then left the haze of a + // bug or of the glass out on some frames: a flicker). negative, so the lock of the taa takes 0 + +// whether the picture was blurred by the taa already (WS_HAZED in its alpha) +bool wsWasHazed(float alpha) +{ + return alpha < -3.0; +} // blur of hazy glass const float WS_RADIUS = 0.014; // max blur radius, fraction of screen height @@ -20,7 +28,10 @@ const float WS_HAZE_LIGHT_CAP = 12.0; // the most a light adds to the haze aro // strength of the blur request, 0 for pixels that are not blur pixels float wsBlur(vec2 raw) { - if (raw.x > 100.0 || raw.y > 100.0) // a blended edge with something else: not a blur pixel + // a blended edge with something else: not a blur pixel. the haze is asked with y = 0; with msaa the samples of a pixel are + // averaged, and the edge of a drop (y half of a drop's) came out as a full haze request: a ring blurred around the drop which + // flickered as the edges moved over the samples + if (raw.x > 100.0 || raw.y > 1.0) return 0.0; float m = clamp(raw.x / WS_ENC, 0.0, 1.0); return clamp((m - WS_FLOOR) / (1.0 - WS_FLOOR), 0.0, 1.0); @@ -139,7 +150,9 @@ float wsLum(vec3 c) // a drop pixel (drop, rivulet): both values in 132..252 bool wsIsDrop(vec2 raw) { - return raw.x > 120.0 && raw.y > 120.0; + // 132 .. 252 exactly: with msaa the edge of a drop averaged with the scene behind (half the values, up to 126) isn't a drop, + // else its decoded bend was nonsense, pulling the picture from far away for a frame (a drop flashing) + return raw.x > 131.5 && raw.y > 131.5; } vec2 wsBend(vec2 raw) @@ -148,19 +161,43 @@ vec2 wsBend(vec2 raw) } #ifndef LAYOUT_POST +// the image of the reflections around Uv as blurred as its mip level Lod, but round: a level of the mipmaps is a grid of squares +// (2^Lod pixels each), and a light read from it alone lit the drops in a square around it. a ring of taps of the finer level +// around the place, weighed as a soft disc, gives the same blur without the squares +vec3 wsHistoryRound(vec2 uv, float lod) +{ + float level = min(lod, ssr_params2.x); + float finer = max(level - 1.0, 0.0); + vec2 pixel = 1.0 / vec2(textureSize(ws_light_history, 0)); + float radius = 0.6 * exp2(level); // pixels of the image + vec3 sum = wsSafe(textureLod(ws_light_history, uv, finer).rgb) * 0.2; + for (int i = 0; i < 8; ++i) + { + float a = (float(i) + 0.5) * 0.7853982; + sum += wsSafe(textureLod(ws_light_history, uv + vec2(cos(a), sin(a)) * radius * pixel, finer).rgb) * 0.06; + sum += wsSafe(textureLod(ws_light_history, uv + vec2(cos(a + 0.3927), sin(a + 0.3927)) * (2.0 * radius) * pixel, finer).rgb) * 0.04; + } + return sum; +} + vec3 wsLightExcess(vec2 uv, float lod, vec3 wide) { - vec3 c = wsSafe(textureLod(ws_light_history, uv, min(lod, ssr_params2.x)).rgb); + vec3 c = wsHistoryRound(uv, lod); vec3 excess = max(c - wide * WS_LIGHT_CONTRAST, vec3(0.0)); - return excess * smoothstep(0.5 * WS_LIGHT_MIN_LUM, WS_LIGHT_MIN_LUM, wsLum(excess)); + // no threshold with an edge: a light dims away from it (the drops right by a lamp the brightest, then less and less); full + // from twice WS_LIGHT_MIN_LUM above the place around, as much as before there + return excess * clamp(wsLum(excess) / (2.0 * WS_LIGHT_MIN_LUM), 0.0, 1.0); } vec3 wsLightGlow(vec2 uv) { if ((ssr_params.x < 1.0) || (textureSize(ws_light_history, 0).x < 16)) return vec3(0.0); - vec3 wide = wsSafe(textureLod(ws_light_history, uv, min(WS_LIGHT_WIDE, ssr_params2.x)).rgb); - vec3 glow = wsLightExcess(uv, WS_LIGHT_FINE, wide) + WS_LIGHT_MID_SHARE * wsLightExcess(uv, WS_LIGHT_MID, wide); + vec3 wide = wsHistoryRound(uv, WS_LIGHT_WIDE); + // the near light in full, the one a little further away fading with it squared: the farther the drop, the less + vec3 mid = wsLightExcess(uv, WS_LIGHT_MID, wide); + float midF = clamp(wsLum(mid) / (2.0 * WS_LIGHT_MIN_LUM), 0.0, 1.0); + vec3 glow = wsLightExcess(uv, WS_LIGHT_FINE, wide) + WS_LIGHT_MID_SHARE * mid * midF; glow *= WS_LIGHT_GAIN; // a light close by is kept to the brightness of one light return glow * min(1.0, WS_LIGHT_CAP / max(wsLum(glow), 1e-4));