mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 06:35:21 +01:00
Rain windscreen: the glass fills up to full in any rain, more slowly in a lighter one
The game now counts the rain the glass meets (more at speed) and how wet the glass is (scene_ubs.rain_state: it fills with the rain and dries when the rain stops), and the rain fallen when each blade was at the end of its sweep (wiper_rain_out/return). The glass with rain gets as many drops, droplets, rivulets and as much haze as the heaviest rain gives, scaled by how wet it is; where a blade went over it they come back with the rain fallen since. A lighter rain only takes longer: 95% full in 10 s of the heaviest rain standing still, 20 s at cloud cover 1.5, 2.5x as fast at 100 km/h; half dry in 3 minutes standing still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BqfRrTiBDaAyQ2gT6ZrnZD
This commit is contained in:
@@ -206,9 +206,17 @@ namespace gl
|
||||
// world with them, inv_view and its modelview (the moment of its animation from its place)
|
||||
glm::vec4 camera_hi;
|
||||
glm::vec4 camera_lo;
|
||||
// the rain the glass meets (mat_rain_windscreen): x the rain fallen so far, in seconds of the heaviest rain standing still (more
|
||||
// at speed: the glass runs into it); y how wet the glass is, 0 dry .. 1 as full of drops as it gets (it fills with the rain,
|
||||
// dries when it stops); z how fast the glass fills: the share left to fill goes down as exp(-z x the rain fallen); w unused
|
||||
glm::vec4 rain_state;
|
||||
// the rain fallen (rain_state.x) when the blades were at the ends of their sweep, as wiper_timer_out and wiper_timer_return
|
||||
// (the drops come back with the rain fallen since); -1 not known
|
||||
glm::vec4 wiper_rain_out;
|
||||
glm::vec4 wiper_rain_return;
|
||||
};
|
||||
|
||||
static_assert(sizeof(scene_ubs) == 992 + 80 * MAX_HEADLIGHT_SHADOWS + 96 * MAX_CAB_PROBE_LAMPS, "bad size of ubs");
|
||||
static_assert(sizeof(scene_ubs) == 1040 + 80 * MAX_HEADLIGHT_SHADOWS + 96 * MAX_CAB_PROBE_LAMPS, "bad size of ubs");
|
||||
|
||||
// the camera of a pass in the world for the scene block (scene_ubs::camera_hi, camera_lo)
|
||||
inline void set_camera_place(scene_ubs &Ubs, glm::dvec3 const &Place)
|
||||
|
||||
@@ -1651,6 +1651,8 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
|
||||
scene_ubs.wiper_bugs_out = glm::vec4{-1.};
|
||||
scene_ubs.wiper_bugs_return = glm::vec4{-1.};
|
||||
scene_ubs.wiper_rain_out = glm::vec4{-1.};
|
||||
scene_ubs.wiper_rain_return = glm::vec4{-1.};
|
||||
m_wiperbugs = 0.0;
|
||||
}
|
||||
// the insects the vehicle meets (mat_bugs_windscreen): none below 20 km/h, above it the more the faster, counted in seconds of
|
||||
@@ -1658,6 +1660,23 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
if (owner != nullptr)
|
||||
m_wiperbugs += Timer::GetDeltaTime() * std::max(std::abs(owner->MoverParameters->V) * 3.6 - 20.0, 0.0) / 80.0;
|
||||
scene_ubs.rain_wind.w = static_cast<float>(m_wiperbugs);
|
||||
// the rain the glass meets (mat_rain_windscreen): counted in seconds of the heaviest rain standing still, more at speed (the
|
||||
// glass runs into it). the glass fills with it up to as many drops as it gets (a lighter rain only fills it more slowly), and
|
||||
// dries when it stops (by half in dry_halflife standing still, faster at speed)
|
||||
{
|
||||
constexpr double fill_rate{0.3}; // per second of the heaviest rain: 95% full in 10 s (20 s at cloud cover 1.5)
|
||||
constexpr double fill_speed{1.5}; // at 100 km/h and more the glass meets x (1 + fill_speed) as much rain
|
||||
constexpr double dry_halflife{180.0}; // seconds standing still
|
||||
auto const dt{Timer::GetDeltaTime()};
|
||||
auto const speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0};
|
||||
auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)};
|
||||
m_wiperrain += dt * meet;
|
||||
if (percipitation_intensity > 0.f)
|
||||
m_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet));
|
||||
else
|
||||
m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed));
|
||||
scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), 0.f};
|
||||
}
|
||||
if (owner != nullptr)
|
||||
{
|
||||
auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1};
|
||||
@@ -1675,11 +1694,13 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
{
|
||||
scene_ubs.wiper_timer_out[i] = scene_ubs.time;
|
||||
scene_ubs.wiper_bugs_out[i] = static_cast<float>(m_wiperbugs);
|
||||
scene_ubs.wiper_rain_out[i] = static_cast<float>(m_wiperrain);
|
||||
}
|
||||
if (owner->dWiperPos[index] > .975)
|
||||
{
|
||||
scene_ubs.wiper_timer_return[i] = scene_ubs.time;
|
||||
scene_ubs.wiper_bugs_return[i] = static_cast<float>(m_wiperbugs);
|
||||
scene_ubs.wiper_rain_return[i] = static_cast<float>(m_wiperrain);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1689,6 +1710,8 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
scene_ubs.wiper_timer_return[i] = -1000.;
|
||||
scene_ubs.wiper_bugs_out[i] = -1.;
|
||||
scene_ubs.wiper_bugs_return[i] = -1.;
|
||||
scene_ubs.wiper_rain_out[i] = -1.;
|
||||
scene_ubs.wiper_rain_return[i] = -1.;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1713,7 +1736,8 @@ void opengl46_renderer::Render_pass(viewport_config &vp, rendermode const Mode)
|
||||
{
|
||||
m_windscreenwater.update(Timer::GetDeltaTime());
|
||||
// the drops and the rivulets of the glasses with rain, for the time of the block of the scene
|
||||
m_windscreenwater.update_rain_cells(scene_ubs.time, scene_ubs.rain_params.x);
|
||||
// (the drops a cell may hold: as many as the glass is wet)
|
||||
m_windscreenwater.update_rain_cells(scene_ubs.time, (scene_ubs.rain_state.y > 0.001f) ? std::min(scene_ubs.rain_state.y + 0.01f, 1.f) : 0.f);
|
||||
}
|
||||
m_windscreenwater.bind();
|
||||
|
||||
|
||||
@@ -855,6 +855,9 @@ class opengl46_renderer : public gfx_renderer, public gfx::scene_walk {
|
||||
TDynamicObject const *m_wipervehicle{nullptr};
|
||||
// the insects that vehicle met so far: seconds of driving at 100 km/h (scene_ubs.rain_wind.w)
|
||||
double m_wiperbugs{0.0};
|
||||
// the rain the glass met so far and how wet it is (scene_ubs::rain_state)
|
||||
double m_wiperrain{0.0};
|
||||
double m_glasswet{0.0};
|
||||
gl::light_data light_data;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<gl::program>> m_shaders;
|
||||
|
||||
@@ -1047,7 +1047,8 @@ void vulkan14_renderer::render_scene()
|
||||
// the water on the windscreens of the cab: a step of its simulation once a frame, before the passes which draw the glasses
|
||||
scene.water.update(Timer::GetDeltaTime());
|
||||
// the drops and the rivulets of the glasses with rain, for the time the block of the scene gets (scene_ubs.time)
|
||||
scene.water.update_rain_cells(static_cast<float>(Timer::GetTime()), glm::saturate(Global.Overcast - 1.f));
|
||||
// (the drops a cell may hold: as many as the glass is wet, a little more, since it's the wetness of the frame before)
|
||||
scene.water.update_rain_cells(static_cast<float>(Timer::GetTime()), (m_glasswet > 0.001) ? static_cast<float>(std::min(m_glasswet + 0.01, 1.0)) : 0.f);
|
||||
if (scene.targets.size() < m_viewports.size())
|
||||
{
|
||||
scene.targets.resize(m_viewports.size());
|
||||
@@ -1505,6 +1506,8 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
scene_ubs.wiper_timer_return = glm::vec4{-1000.};
|
||||
scene_ubs.wiper_bugs_out = glm::vec4{-1.};
|
||||
scene_ubs.wiper_bugs_return = glm::vec4{-1.};
|
||||
scene_ubs.wiper_rain_out = glm::vec4{-1.};
|
||||
scene_ubs.wiper_rain_return = glm::vec4{-1.};
|
||||
m_wiperbugs = 0.0;
|
||||
}
|
||||
// the insects the vehicle meets (mat_bugs_windscreen): none below 20 km/h, above it the more the faster, counted in seconds of
|
||||
@@ -1512,6 +1515,23 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
if (owner != nullptr)
|
||||
m_wiperbugs += Timer::GetDeltaTime() * std::max(std::abs(owner->MoverParameters->V) * 3.6 - 20.0, 0.0) / 80.0;
|
||||
scene_ubs.rain_wind.w = static_cast<float>(m_wiperbugs);
|
||||
// the rain the glass meets (mat_rain_windscreen): counted in seconds of the heaviest rain standing still, more at speed (the
|
||||
// glass runs into it). the glass fills with it up to as many drops as it gets (a lighter rain only fills it more slowly), and
|
||||
// dries when it stops (by half in dry_halflife standing still, faster at speed)
|
||||
{
|
||||
constexpr double fill_rate{0.3}; // per second of the heaviest rain: 95% full in 10 s (20 s at cloud cover 1.5)
|
||||
constexpr double fill_speed{1.5}; // at 100 km/h and more the glass meets x (1 + fill_speed) as much rain
|
||||
constexpr double dry_halflife{180.0}; // seconds standing still
|
||||
auto const dt{Timer::GetDeltaTime()};
|
||||
auto const speed{(owner != nullptr) ? std::min(std::abs(owner->MoverParameters->V) * 3.6 / 100.0, 1.0) : 0.0};
|
||||
auto const meet{static_cast<double>(percipitation_intensity) * (1.0 + fill_speed * speed)};
|
||||
m_wiperrain += dt * meet;
|
||||
if (percipitation_intensity > 0.f)
|
||||
m_glasswet += (1.0 - m_glasswet) * (1.0 - std::exp(-fill_rate * dt * meet));
|
||||
else
|
||||
m_glasswet *= std::exp(-dt * std::log(2.0) / dry_halflife * (1.0 + 2.0 * speed));
|
||||
scene_ubs.rain_state = glm::vec4{static_cast<float>(m_wiperrain), static_cast<float>(m_glasswet), static_cast<float>(fill_rate), 0.f};
|
||||
}
|
||||
if (owner != nullptr)
|
||||
{
|
||||
auto const cabactive{owner->MoverParameters->CabActive != 0 ? owner->MoverParameters->CabActive : 1};
|
||||
@@ -1529,11 +1549,13 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
{
|
||||
scene_ubs.wiper_timer_out[i] = scene_ubs.time;
|
||||
scene_ubs.wiper_bugs_out[i] = static_cast<float>(m_wiperbugs);
|
||||
scene_ubs.wiper_rain_out[i] = static_cast<float>(m_wiperrain);
|
||||
}
|
||||
if (owner->dWiperPos[index] > .975)
|
||||
{
|
||||
scene_ubs.wiper_timer_return[i] = scene_ubs.time;
|
||||
scene_ubs.wiper_bugs_return[i] = static_cast<float>(m_wiperbugs);
|
||||
scene_ubs.wiper_rain_return[i] = static_cast<float>(m_wiperrain);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1543,6 +1565,8 @@ void vulkan14_renderer::render_viewport(std::size_t const Index)
|
||||
scene_ubs.wiper_timer_return[i] = -1000.;
|
||||
scene_ubs.wiper_bugs_out[i] = -1.;
|
||||
scene_ubs.wiper_bugs_return[i] = -1.;
|
||||
scene_ubs.wiper_rain_out[i] = -1.;
|
||||
scene_ubs.wiper_rain_return[i] = -1.;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -556,6 +556,9 @@ class vulkan14_renderer : public gfx_renderer, public gfx::scene_walk
|
||||
TDynamicObject const *m_wipervehicle{nullptr};
|
||||
// the insects that vehicle met so far: seconds of driving at 100 km/h (scene_ubs.rain_wind.w)
|
||||
double m_wiperbugs{0.0};
|
||||
// the rain the glass met so far and how wet it is (scene_ubs::rain_state)
|
||||
double m_wiperrain{0.0};
|
||||
double m_glasswet{0.0};
|
||||
gl::light_data light_data{};
|
||||
std::uint32_t m_lightcount{1}; // lights written to light_data
|
||||
// the copies of the light buffer in the ring of the frame since the lights were last written, by the header and the sun
|
||||
|
||||
@@ -375,6 +375,11 @@ layout(std140, binding = SCENE_UBO_BINDING) uniform scene_ubo
|
||||
// the place of the camera of the pass in the world (whole 64 m, the rest), see gl::scene_ubs
|
||||
vec4 camera_hi;
|
||||
vec4 camera_lo;
|
||||
// the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills (mat_rain_windscreen), see gl::scene_ubs
|
||||
vec4 rain_state;
|
||||
// the rain fallen when the blades were at the ends of their sweep, see gl::scene_ubs
|
||||
vec4 wiper_rain_out;
|
||||
vec4 wiper_rain_return;
|
||||
};
|
||||
|
||||
#ifdef STAGE_VERTEX
|
||||
|
||||
@@ -78,20 +78,26 @@ layout(binding = 3) uniform sampler2D normalmap;
|
||||
// --- Haze of the wet glass (blur) ------------------------------------------------
|
||||
// The haze follows the rain and is wiped away by the wipers, as before (fully blurred from a quarter of the haze on).
|
||||
const float blur_amount = 1.0; // strength of the haze: 0 = off, 1 = full
|
||||
// after the wiper the haze grows with the rain fallen on the glass since (intensity x seconds) from nothing up to its full
|
||||
// strength, which is the intensity of the rain (cloud cover 1.5 -> 0.5). where no wiper reaches it is as always
|
||||
const float haze_fill = 12.0; // rain to mist the glass up fully: seconds of the heaviest rain (2x as long at 1.5)
|
||||
// after the wiper the haze grows with the rain fallen on the glass since (intensity x seconds, more at speed) from nothing up to
|
||||
// its full strength, in any rain (a lighter rain takes longer). where no wiper reaches it is full
|
||||
const float haze_fill = 12.0; // rain fallen since the blade to mist the glass up fully: seconds of the heaviest
|
||||
// rain standing still (2x as long at 1.5; the speed counted in by the game)
|
||||
const float haze_curve = 1.0; // > 1: slow at first, then more and more
|
||||
const float haze_speed = 1.0; // at speed the haze grows: x (1 + haze_speed) at full speed (see wind_drag_gain)
|
||||
const float WS_BEND_ENC = 60.0; // the drop request in the velocity target; must match rain_windscreen_haze.glsl
|
||||
const float WS_DROP_BIAS = 192.0;
|
||||
const float WS_ENC = 64.0; // the haze request in the velocity target; must match rain_windscreen_haze.glsl
|
||||
|
||||
// --- How the water gathers on the glass ------------------------------------------------------------------
|
||||
// the game counts the rain the glass meets (rain_state, gl::scene_ubs; more at speed) and how wet the glass is (0 dry .. 1 as full
|
||||
// of drops as it gets): the glass fills up to the full in any rain, a lighter one only takes longer, and dries when the rain stops.
|
||||
// the times are in the game (fill_rate, fill_speed, dry_halflife in the setup of the scene block). where a blade went over the glass
|
||||
// the drops come back with the rain fallen since
|
||||
|
||||
// --- Drops (atlas tiles) ------------------------------------------------------
|
||||
// (how long they live: rain_cells.glsl; the cells of the drops and of the rivulets are worked out once a frame by rain_cells.comp)
|
||||
|
||||
// --- Micro droplets -------------------------------------------------------------
|
||||
const float micro_density = 0.45; // share of micro cells holding a droplet at full rain, 0 = off
|
||||
const float micro_density = 0.45; // share of micro cells holding a droplet on a full glass, 0 = off
|
||||
const float micro_scale = 3.0; // micro grid = raindrop_grid_size * micro_scale
|
||||
const float micro_size_min = 0.12; // droplet radius in micro cells
|
||||
const float micro_size_max = 0.40;
|
||||
@@ -361,7 +367,7 @@ Riv getRiv(vec2 sCell, float sCW, float sCH, float gridSize)
|
||||
{
|
||||
Riv r;
|
||||
uvec4 d = rain_cells[rain_riv_index(wsLayerIndex, ivec2(sCell))];
|
||||
r.on = ((float(d.x & 65535u) + 0.5) * (1.0 / 65536.0) < rain_params.x * streak_density * wsLayerDensity);
|
||||
r.on = ((float(d.x & 65535u) + 0.5) * (1.0 / 65536.0) < streak_density * wsLayerDensity * rain_state.y); // as wet as the glass is
|
||||
r.life = float((d.x >> 16) & 255u) * (1.0 / 255.0);
|
||||
float wr = rain_byte(d.y, 16u);
|
||||
r.width = streak_head * wsLayerHead / gridSize
|
||||
@@ -554,9 +560,8 @@ float wsKept(vec2 cg, float rad, float sCW, float sCH, float gridSize)
|
||||
return kept;
|
||||
}
|
||||
|
||||
// seconds since a wiper blade last went over Co (texture UV), from the timers of its strokes as GetMixFactor takes them;
|
||||
// -1 where no wiper reaches
|
||||
float wsWipeAge(vec2 co)
|
||||
// the rain fallen (rain_state.x) since a blade last went over this place (texture UV); -1 where no blade goes or not known
|
||||
float wsWipeRain(vec2 co)
|
||||
{
|
||||
vec4 movePhase = wiper_pos;
|
||||
bvec4 is_out = lessThanEqual(movePhase, vec4(1.));
|
||||
@@ -565,12 +570,12 @@ float wsWipeAge(vec2 co)
|
||||
vec4 maskVal = mix(1. - mask, mask, is_out);
|
||||
vec4 passed = step(maskVal, movePhase);
|
||||
vec4 sideV = mix(passed, vec4(1.) - passed, is_out);
|
||||
vec4 ages = vec4(time) - mix(wiper_timer_out, wiper_timer_return, sideV);
|
||||
float age = -1.0;
|
||||
vec4 at = mix(wiper_rain_out, wiper_rain_return, sideV);
|
||||
float fallen = -1.0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
if ((mask[i] > 0.001) && ((age < 0.0) || (ages[i] < age)))
|
||||
age = max(ages[i], 0.0);
|
||||
return age;
|
||||
if ((mask[i] > 0.001) && (at[i] >= 0.0))
|
||||
fallen = (fallen < 0.0) ? max(rain_state.x - at[i], 0.0) : min(fallen, max(rain_state.x - at[i], 0.0));
|
||||
return fallen;
|
||||
}
|
||||
|
||||
// the tangent frame of the glass (the directions of u and v on it, view space) from the screen-space change of the place and the uv
|
||||
@@ -628,10 +633,6 @@ void main()
|
||||
float wsNight = smoothstep(0.0, drop_dark_lum, sceneLum); // 0 dark night .. 1 daylight
|
||||
dynBright *= wsNight;
|
||||
|
||||
// wiper state of this pixel (blur, micro droplets)
|
||||
float hazeSide;
|
||||
float wipeVis = GetMixFactor(f_coord, hazeSide);
|
||||
|
||||
Hit hit;
|
||||
hit.score = 0.0; hit.cov = 0.0; hit.colA = 0.0; hit.n = vec3(0.0, 0.0, 1.0);
|
||||
hit.offUV = vec2(0.0); hit.radUV = 1.0; hit.isDrop = 1.0;
|
||||
@@ -678,6 +679,10 @@ void main()
|
||||
wsPushT = vec2(dot(wsPush, Tgl), dot(wsPush, Bgl));
|
||||
wsPushT = (dot(wsPushT, wsPushT) > 1e-10) ? normalize(wsPushT) : vec2(0.0, -1.0);
|
||||
}
|
||||
|
||||
// the wiper state of this pixel (blur, micro droplets)
|
||||
float hazeSide;
|
||||
float wipeVis = GetMixFactor(f_coord, hazeSide);
|
||||
// the change of the glass UV (v up) per screen pixel, for the rivulets
|
||||
vec2 wsRd1 = vec2(duv1.x, flipS * duv1.y);
|
||||
vec2 wsRd2 = vec2(duv2.x, flipS * duv2.y);
|
||||
@@ -690,7 +695,7 @@ void main()
|
||||
vec2 sCell = floor(sUVg / vec2(sCW, sCH));
|
||||
bool sweepOn = streak_sweep > 0.0 && streak_density > 0.0 && (wind_streaks > 0.0 || wsWindShare < 1.0) && (WS_PROFILE != 2);
|
||||
|
||||
if ((rain_params.x > 0.001) && (WS_PROFILE != 5))
|
||||
if ((rain_state.y > 0.001) && (WS_PROFILE != 5))
|
||||
{
|
||||
// ===================================================================
|
||||
// 1. drops from the atlas: this cell and its 8 neighbours
|
||||
@@ -708,6 +713,9 @@ void main()
|
||||
reach &= reach - 1u;
|
||||
vec2 nc = cell + vec2(float(bit % 3 - 1), float(bit / 3 - 1));
|
||||
uvec4 d = rain_cells[rain_drop_index(ivec2(nc))];
|
||||
// as many drops as the glass is wet (the cells were sorted out with a little more)
|
||||
if (rain_byte(d.y, 24u) > min(rain_state.y * drop_density, 0.95))
|
||||
continue;
|
||||
float vis = float(d.w >> 24) * (1.0 / 255.0);
|
||||
float spreadF = mix(0.8, 1.0, float((d.y >> 19) & 31u) * (1.0 / 31.0));
|
||||
// a drop the blades miss: the same drop before and after the stroke, left where it is
|
||||
@@ -781,7 +789,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) < min(rain_params.x * micro_density, 0.95))
|
||||
if (RandF(m1) < min(micro_density * rain_state.y, 0.95))
|
||||
{
|
||||
uint m2 = Hash(uvec3(mk, mep * 4u + 2u + uint(hazeSide) * 2u));
|
||||
if (wipeVis >= RandF(m2))
|
||||
@@ -991,10 +999,11 @@ void main()
|
||||
// What is seen through the wet glass: the image of the last frame, blurred by the haze, bent by the drops
|
||||
// -----------------------------------------------------------------------
|
||||
// the haze after the wiper: grows with the rain fallen since, up to the intensity of the rain (as it always was where no wiper reaches)
|
||||
float wipeAge = wsWipeAge(f_coord);
|
||||
float hazeBack = (wipeAge < 0.0) ? 1.0
|
||||
: min(wipeVis, pow(clamp(wipeAge * rain_params.x / haze_fill, 0.0, 1.0), haze_curve));
|
||||
float hazeWeight = min(rain_params.x * hazeBack * (1.0 + haze_speed * wsSpeed), 1.0) * (1.0 - max(alphaOut, coverA));
|
||||
float wipeRain = wsWipeRain(f_coord);
|
||||
float hazeBack = (wipeRain < 0.0) ? rain_state.y
|
||||
: min(rain_state.y, pow(clamp(wipeRain / haze_fill, 0.0, 1.0), haze_curve));
|
||||
// up to the full haze in any rain, as the glass gets wet (a lighter rain only mists it up more slowly), less as it dries
|
||||
float hazeWeight = hazeBack * (1.0 - max(alphaOut, coverA));
|
||||
float glassClear = 1.0 - smoothstep(0.5, 0.95, glassA);
|
||||
bool image = ssr_params.x >= 1.0;
|
||||
float background = 0.0; // distance to the scene behind, along the view (0: far / not known)
|
||||
@@ -1094,7 +1103,12 @@ float GetMixFactor(in vec2 co, out float side) {
|
||||
side_v = mix(side_v, vec4(1.) - side_v, is_out);
|
||||
|
||||
// "regeneration", raindrops gradually returning after wiper pass:
|
||||
vec4 regenPhase = clamp((vec4(time) - mix(wiper_timer_out, wiper_timer_return, side_v) - vec4(.2)) / vec4(rain_params.y), vec4(0.), vec4(1.));
|
||||
// the share of the drops back: the glass fills with the rain fallen since the blade (rain_state), up to as wet as the glass is
|
||||
// where no blade goes (the drops of a cell are there only up to that share, so the share of those back is the fill over it)
|
||||
vec4 fallen = vec4(rain_state.x) - mix(wiper_rain_out, wiper_rain_return, side_v);
|
||||
vec4 known = step(vec4(0.), mix(wiper_rain_out, wiper_rain_return, side_v));
|
||||
vec4 filled = mix(vec4(1.), vec4(1.) - exp(-max(fallen, vec4(0.)) * rain_state.z), known);
|
||||
vec4 regenPhase = clamp(filled / max(rain_state.y, 1e-4), vec4(0.), vec4(1.));
|
||||
|
||||
side_v = mix(vec4(0.), vec4(1.) - side_v, areaMask);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "common.glsl"
|
||||
|
||||
layout(location = 0) uniform float rain_time; // the time of the block of the scene (scene_ubs.time)
|
||||
layout(location = 1) uniform float rain_amount; // how hard it rains (scene_ubs.rain_params.x)
|
||||
layout(location = 1) uniform float rain_amount; // how wet the glass is (scene_ubs.rain_state.y, a little more)
|
||||
layout(location = 2) uniform int rain_pass; // 0 the cells, 1 the reach of the drops
|
||||
|
||||
#include "random.glsl"
|
||||
@@ -125,6 +125,7 @@ float drop_reach(uint A, uint B, float Spread)
|
||||
uvec4 drop_masks(ivec2 Cell)
|
||||
{
|
||||
uvec4 result = uvec4(0u);
|
||||
// as many drops as the glass is wet (rain_amount: the wetness of the glass, scene_ubs.rain_state.y)
|
||||
float most = min(rain_amount * drop_density, 0.95);
|
||||
for (int dy = -1; dy <= 1; ++dy)
|
||||
for (int dx = -1; dx <= 1; ++dx)
|
||||
|
||||
@@ -337,6 +337,11 @@ layout(std140, set = PASS_SET, binding = SCENE_UBO) uniform scene_ubo
|
||||
// the place of the camera of the pass in the world (whole 64 m, the rest), see gl::scene_ubs
|
||||
vec4 camera_hi;
|
||||
vec4 camera_lo;
|
||||
// the rain the glass meets: x fallen so far, y how wet the glass is, z how fast it fills (mat_rain_windscreen), see gl::scene_ubs
|
||||
vec4 rain_state;
|
||||
// the rain fallen when the blades were at the ends of their sweep, see gl::scene_ubs
|
||||
vec4 wiper_rain_out;
|
||||
vec4 wiper_rain_return;
|
||||
};
|
||||
|
||||
#ifndef LAYOUT_COMPUTE
|
||||
|
||||
@@ -83,20 +83,26 @@ layout(set = MATERIAL_SET, binding = MATERIAL_TEXTURE_FIRST + 3) uniform sampler
|
||||
// --- Haze of the wet glass (blur) ------------------------------------------------
|
||||
// The haze follows the rain and is wiped away by the wipers, as before (fully blurred from a quarter of the haze on).
|
||||
const float blur_amount = 1.0; // strength of the haze: 0 = off, 1 = full
|
||||
// after the wiper the haze grows with the rain fallen on the glass since (intensity x seconds) from nothing up to its full
|
||||
// strength, which is the intensity of the rain (cloud cover 1.5 -> 0.5). where no wiper reaches it is as always
|
||||
const float haze_fill = 12.0; // rain to mist the glass up fully: seconds of the heaviest rain (2x as long at 1.5)
|
||||
// after the wiper the haze grows with the rain fallen on the glass since (intensity x seconds, more at speed) from nothing up to
|
||||
// its full strength, in any rain (a lighter rain takes longer). where no wiper reaches it is full
|
||||
const float haze_fill = 12.0; // rain fallen since the blade to mist the glass up fully: seconds of the heaviest
|
||||
// rain standing still (2x as long at 1.5; the speed counted in by the game)
|
||||
const float haze_curve = 1.0; // > 1: slow at first, then more and more
|
||||
const float haze_speed = 1.0; // at speed the haze grows: x (1 + haze_speed) at full speed (see wind_drag_gain)
|
||||
const float WS_BEND_ENC = 60.0; // the drop request in the velocity target; must match rain_windscreen_haze.glsl
|
||||
const float WS_DROP_BIAS = 192.0;
|
||||
const float WS_ENC = 64.0; // the haze request in the velocity target; must match rain_windscreen_haze.glsl
|
||||
|
||||
// --- How the water gathers on the glass ------------------------------------------------------------------
|
||||
// the game counts the rain the glass meets (rain_state, gl::scene_ubs; more at speed) and how wet the glass is (0 dry .. 1 as full
|
||||
// of drops as it gets): the glass fills up to the full in any rain, a lighter one only takes longer, and dries when the rain stops.
|
||||
// the times are in the game (fill_rate, fill_speed, dry_halflife in the setup of the scene block). where a blade went over the glass
|
||||
// the drops come back with the rain fallen since
|
||||
|
||||
// --- Drops (atlas tiles) ------------------------------------------------------
|
||||
// (how long they live: rain_cells.glsl; the cells of the drops and of the rivulets are worked out once a frame by rain_cells.comp)
|
||||
|
||||
// --- Micro droplets -------------------------------------------------------------
|
||||
const float micro_density = 0.45; // share of micro cells holding a droplet at full rain, 0 = off
|
||||
const float micro_density = 0.45; // share of micro cells holding a droplet on a full glass, 0 = off
|
||||
const float micro_scale = 3.0; // micro grid = raindrop_grid_size * micro_scale
|
||||
const float micro_size_min = 0.12; // droplet radius in micro cells
|
||||
const float micro_size_max = 0.40;
|
||||
@@ -366,7 +372,7 @@ Riv getRiv(vec2 sCell, float sCW, float sCH, float gridSize)
|
||||
{
|
||||
Riv r;
|
||||
uvec4 d = rain_cells[rain_riv_index(wsLayerIndex, ivec2(sCell))];
|
||||
r.on = ((float(d.x & 65535u) + 0.5) * (1.0 / 65536.0) < rain_params.x * streak_density * wsLayerDensity);
|
||||
r.on = ((float(d.x & 65535u) + 0.5) * (1.0 / 65536.0) < streak_density * wsLayerDensity * rain_state.y); // as wet as the glass is
|
||||
r.life = float((d.x >> 16) & 255u) * (1.0 / 255.0);
|
||||
float wr = rain_byte(d.y, 16u);
|
||||
r.width = streak_head * wsLayerHead / gridSize
|
||||
@@ -559,9 +565,8 @@ float wsKept(vec2 cg, float rad, float sCW, float sCH, float gridSize)
|
||||
return kept;
|
||||
}
|
||||
|
||||
// seconds since a wiper blade last went over Co (texture UV), from the timers of its strokes as GetMixFactor takes them;
|
||||
// -1 where no wiper reaches
|
||||
float wsWipeAge(vec2 co)
|
||||
// the rain fallen (rain_state.x) since a blade last went over this place (texture UV); -1 where no blade goes or not known
|
||||
float wsWipeRain(vec2 co)
|
||||
{
|
||||
vec4 movePhase = wiper_pos;
|
||||
bvec4 is_out = lessThanEqual(movePhase, vec4(1.));
|
||||
@@ -570,12 +575,12 @@ float wsWipeAge(vec2 co)
|
||||
vec4 maskVal = mix(1. - mask, mask, is_out);
|
||||
vec4 passed = step(maskVal, movePhase);
|
||||
vec4 sideV = mix(passed, vec4(1.) - passed, is_out);
|
||||
vec4 ages = vec4(time) - mix(wiper_timer_out, wiper_timer_return, sideV);
|
||||
float age = -1.0;
|
||||
vec4 at = mix(wiper_rain_out, wiper_rain_return, sideV);
|
||||
float fallen = -1.0;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
if ((mask[i] > 0.001) && ((age < 0.0) || (ages[i] < age)))
|
||||
age = max(ages[i], 0.0);
|
||||
return age;
|
||||
if ((mask[i] > 0.001) && (at[i] >= 0.0))
|
||||
fallen = (fallen < 0.0) ? max(rain_state.x - at[i], 0.0) : min(fallen, max(rain_state.x - at[i], 0.0));
|
||||
return fallen;
|
||||
}
|
||||
|
||||
// the tangent frame of the glass (the directions of u and v on it, view space) from the screen-space change of the place and the uv
|
||||
@@ -633,10 +638,6 @@ void main()
|
||||
float wsNight = smoothstep(0.0, drop_dark_lum, sceneLum); // 0 dark night .. 1 daylight
|
||||
dynBright *= wsNight;
|
||||
|
||||
// wiper state of this pixel (blur, micro droplets)
|
||||
float hazeSide;
|
||||
float wipeVis = GetMixFactor(f_coord, hazeSide);
|
||||
|
||||
Hit hit;
|
||||
hit.score = 0.0; hit.cov = 0.0; hit.colA = 0.0; hit.n = vec3(0.0, 0.0, 1.0);
|
||||
hit.offUV = vec2(0.0); hit.radUV = 1.0; hit.isDrop = 1.0;
|
||||
@@ -683,6 +684,10 @@ void main()
|
||||
wsPushT = vec2(dot(wsPush, Tgl), dot(wsPush, Bgl));
|
||||
wsPushT = (dot(wsPushT, wsPushT) > 1e-10) ? normalize(wsPushT) : vec2(0.0, -1.0);
|
||||
}
|
||||
|
||||
// the wiper state of this pixel (blur, micro droplets)
|
||||
float hazeSide;
|
||||
float wipeVis = GetMixFactor(f_coord, hazeSide);
|
||||
// the change of the glass UV (v up) per screen pixel, for the rivulets
|
||||
vec2 wsRd1 = vec2(duv1.x, flipS * duv1.y);
|
||||
vec2 wsRd2 = vec2(duv2.x, flipS * duv2.y);
|
||||
@@ -695,7 +700,7 @@ void main()
|
||||
vec2 sCell = floor(sUVg / vec2(sCW, sCH));
|
||||
bool sweepOn = streak_sweep > 0.0 && streak_density > 0.0 && (wind_streaks > 0.0 || wsWindShare < 1.0) && (WS_PROFILE != 2);
|
||||
|
||||
if ((rain_params.x > 0.001) && (WS_PROFILE != 5))
|
||||
if ((rain_state.y > 0.001) && (WS_PROFILE != 5))
|
||||
{
|
||||
// ===================================================================
|
||||
// 1. drops from the atlas: this cell and its 8 neighbours
|
||||
@@ -713,6 +718,9 @@ void main()
|
||||
reach &= reach - 1u;
|
||||
vec2 nc = cell + vec2(float(bit % 3 - 1), float(bit / 3 - 1));
|
||||
uvec4 d = rain_cells[rain_drop_index(ivec2(nc))];
|
||||
// as many drops as the glass is wet (the cells were sorted out with a little more)
|
||||
if (rain_byte(d.y, 24u) > min(rain_state.y * drop_density, 0.95))
|
||||
continue;
|
||||
float vis = float(d.w >> 24) * (1.0 / 255.0);
|
||||
float spreadF = mix(0.8, 1.0, float((d.y >> 19) & 31u) * (1.0 / 31.0));
|
||||
// a drop the blades miss: the same drop before and after the stroke, left where it is
|
||||
@@ -786,7 +794,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) < min(rain_params.x * micro_density, 0.95))
|
||||
if (RandF(m1) < min(micro_density * rain_state.y, 0.95))
|
||||
{
|
||||
uint m2 = Hash(uvec3(mk, mep * 4u + 2u + uint(hazeSide) * 2u));
|
||||
if (wipeVis >= RandF(m2))
|
||||
@@ -996,10 +1004,11 @@ void main()
|
||||
// What is seen through the wet glass: the image of the last frame, blurred by the haze, bent by the drops
|
||||
// -----------------------------------------------------------------------
|
||||
// the haze after the wiper: grows with the rain fallen since, up to the intensity of the rain (as it always was where no wiper reaches)
|
||||
float wipeAge = wsWipeAge(f_coord);
|
||||
float hazeBack = (wipeAge < 0.0) ? 1.0
|
||||
: min(wipeVis, pow(clamp(wipeAge * rain_params.x / haze_fill, 0.0, 1.0), haze_curve));
|
||||
float hazeWeight = min(rain_params.x * hazeBack * (1.0 + haze_speed * wsSpeed), 1.0) * (1.0 - max(alphaOut, coverA));
|
||||
float wipeRain = wsWipeRain(f_coord);
|
||||
float hazeBack = (wipeRain < 0.0) ? rain_state.y
|
||||
: min(rain_state.y, pow(clamp(wipeRain / haze_fill, 0.0, 1.0), haze_curve));
|
||||
// up to the full haze in any rain, as the glass gets wet (a lighter rain only mists it up more slowly), less as it dries
|
||||
float hazeWeight = hazeBack * (1.0 - max(alphaOut, coverA));
|
||||
float glassClear = 1.0 - smoothstep(0.5, 0.95, glassA);
|
||||
bool image = ssr_params.x >= 1.0;
|
||||
float background = 0.0; // distance to the scene behind, along the view (0: far / not known)
|
||||
@@ -1099,7 +1108,12 @@ float GetMixFactor(in vec2 co, out float side) {
|
||||
side_v = mix(side_v, vec4(1.) - side_v, is_out);
|
||||
|
||||
// "regeneration", raindrops gradually returning after wiper pass:
|
||||
vec4 regenPhase = clamp((vec4(time) - mix(wiper_timer_out, wiper_timer_return, side_v) - vec4(.2)) / vec4(rain_params.y), vec4(0.), vec4(1.));
|
||||
// the share of the drops back: the glass fills with the rain fallen since the blade (rain_state), up to as wet as the glass is
|
||||
// where no blade goes (the drops of a cell are there only up to that share, so the share of those back is the fill over it)
|
||||
vec4 fallen = vec4(rain_state.x) - mix(wiper_rain_out, wiper_rain_return, side_v);
|
||||
vec4 known = step(vec4(0.), mix(wiper_rain_out, wiper_rain_return, side_v));
|
||||
vec4 filled = mix(vec4(1.), vec4(1.) - exp(-max(fallen, vec4(0.)) * rain_state.z), known);
|
||||
vec4 regenPhase = clamp(filled / max(rain_state.y, 1e-4), vec4(0.), vec4(1.));
|
||||
|
||||
side_v = mix(vec4(0.), vec4(1.) - side_v, areaMask);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
layout(push_constant) uniform kernel_constants
|
||||
{
|
||||
float rain_time; // the time of the block of the scene (scene_ubs.time)
|
||||
float rain_amount; // how hard it rains (scene_ubs.rain_params.x)
|
||||
float rain_amount; // how wet the glass is (scene_ubs.rain_state.y, a little more)
|
||||
int rain_pass; // 0 the cells, 1 the reach of the drops
|
||||
};
|
||||
|
||||
@@ -130,6 +130,7 @@ float drop_reach(uint A, uint B, float Spread)
|
||||
uvec4 drop_masks(ivec2 Cell)
|
||||
{
|
||||
uvec4 result = uvec4(0u);
|
||||
// as many drops as the glass is wet (rain_amount: the wetness of the glass, scene_ubs.rain_state.y)
|
||||
float most = min(rain_amount * drop_density, 0.95);
|
||||
for (int dy = -1; dy <= 1; ++dy)
|
||||
for (int dx = -1; dx <= 1; ++dx)
|
||||
|
||||
Reference in New Issue
Block a user