Wiper shader improvements

This commit is contained in:
2025-12-23 21:01:29 +01:00
parent 7a2bfcb34a
commit 323b04f542

View File

@@ -25,6 +25,7 @@ layout(location = 1) out vec4 out_motion;
#include <light_common.glsl>
#include <apply_fog.glsl>
#include <tonemapping.glsl>
#include <random.glsl>
uniform sampler2D diffuse;
uniform sampler2D raindropsatlas;
@@ -34,10 +35,6 @@ uniform float specular_intensity = 1.0;
uniform float wobble_strength = 0.002;
uniform float wobble_speed = 30.0;
float hash(vec2 p) {
return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
}
vec4 getDropTex(float choice, vec2 uv) {
vec2 offset;
if (choice < 0.25) offset = vec2(0.0, 0.0);
@@ -54,13 +51,14 @@ void main() {
if (tex_color.a < 0.01) discard;
vec2 rainCoord = f_coord;
float gridSize = ceil(param[2].x);
const float numDrops = 20000.0;
const float cycleDuration = 4.0;
const float squareMin = 0.0035;
const float squareMax = 0.008;
float gridSize = ceil(param[2].x);
float squareMin = 0.5 / gridSize;
float squareMax = 1.2 / gridSize;
vec2 cell = floor(rainCoord * gridSize);
vec3 dropLayer = vec3(0.0);
@@ -76,37 +74,37 @@ void main() {
float side;
float mixFactor = GetMixFactor(neighborCenter, side);
if(mixFactor < hash(neighborCell + vec2(mix(0., .2137, side), 0.))) {
uint seed = Hash(uvec3(neighborCell, side));
if(mixFactor < RandF(seed)) {
continue;
}
float i = neighborCell.x + neighborCell.y * gridSize;
// Show a percentage of droplets given by rain intensity param
float activationSeed = hash(vec2(i, 0.333 + side));
float activationSeed = RandF(seed);
if (activationSeed > rain_params.x)
continue; // kropla nieaktywna
// Randomly modulate droplet center & size
vec2 dropCenter = (neighborCell + vec2(hash(vec2(i, 0.12 + side)), hash(vec2(i, 0.34 + side)))) / gridSize;
float squareSize = mix(squareMin, squareMax, hash(vec2(i, 0.56 + side)));
vec2 dropCenter = (neighborCell + vec2(RandF(seed), RandF(seed))) / gridSize;
float squareSize = mix(squareMin, squareMax, RandF(seed));
float lifeTime = time + hash(vec2(i, 0.78 + side)) * cycleDuration;
float lifeTime = time + RandF(seed) * cycleDuration;
float phase = fract(lifeTime / cycleDuration);
float active = clamp(1.0 - phase, 0.0, 1.0);
float actiwe = clamp(1.0 - phase, 0.0, 1.0);
// Gravity influence (TODO add vehicle speed & wind here!)
float gravityStart = 0.5;
float gravityPhase = smoothstep(gravityStart, 1.0, phase);
float dropMass = mix(0.3, 1.2, hash(vec2(i, 0.21 + side)));
float dropMass = mix(0.3, 1.2, RandF(seed));
float gravitySpeed = 0.15 * dropMass;
vec2 gravityOffset = vec2(0.0, gravityPhase * gravitySpeed * phase);
// Random wobble
bool hasWobble = (hash(vec2(i, 0.91 + side)) < 0.10);
bool hasWobble = (RandF(seed) < 0.10);
vec2 wobbleOffset = vec2(0.0);
if (hasWobble && gravityPhase > 0.0) {
float intensity = sin(time * wobble_speed + i) * wobble_strength * gravityPhase;
float intensity = sin(time * wobble_speed + RandF(seed) * 100.) * wobble_strength * gravityPhase;
wobbleOffset = vec2(intensity, 0.0);
}
@@ -125,7 +123,7 @@ void main() {
if (mask > 0.001) {
vec2 localUV = (diff + squareSize * 0.5) / squareSize;
float choice = hash(vec2(i, 0.99 + side));
float choice = RandF(seed);
vec4 dropTex = getDropTex(choice, localUV);
float sharpAlpha = smoothstep(0.3, 0.9, dropTex.a);
@@ -139,15 +137,15 @@ void main() {
float sparkle = 0.0;
if (hasWobble) {
sparkle = pow(abs(sin(f_coord.x * 8.0 + time * 2.0 + hash(vec2(i, 0.9 + side)) * 6.2831)), 40.0)
sparkle = pow(abs(sin(f_coord.x * 8.0 + time * 2.0 + RandF(seed) * 6.2831)), 40.0)
* mix(0.2, 1.0, sunFactor);
}
vec3 specularColor = vec3(1.0) * specular_intensity * sparkle;
vec3 dropLit = dropTex.rgb * dynBright + specularColor * sharpAlpha;
dropLayer += dropLit * sharpAlpha * active * blackAlpha * mask;
dropMaskSum += sharpAlpha * active * blackAlpha * mask;
dropLayer += dropLit * sharpAlpha * actiwe * blackAlpha * mask;
dropMaskSum += sharpAlpha * actiwe * blackAlpha * mask;
}
}
}