mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-09 03:29:43 -10:00
(D3D) Fix XMB snow shader degradation over long sessions
The D3D HLSL snow shaders (snow_sm4.hlsl.h, simple_snow_sm4.hlsl.h)
had unbounded linear scroll offsets in the gravity calculation:
pos += time * scale * float2(-0.5, 1.0) * 4.0;
Over long sessions, these offsets grow large enough that the
random_dots grid lookup — which uses floor(co / 0.05) as a hash
seed — produces grid indices in the thousands. The sin()-based
hash function loses meaningful variation at these magnitudes,
causing snowflakes to stretch into vertical columns.
The Vulkan and GL versions of these shaders were already fixed
(Vulkan in f0649a9, GL previously). This applies the same fix
to the D3D HLSL versions.
Fix: wrap the scroll offset to one tile period using frac():
float2 scroll = time * scale * float2(-0.5, 1.0) * 4.0;
pos += frac(scroll / 0.05) * 0.05;
The dot pattern tiles every 0.05 units, so frac() preserves the
exact visual position while keeping coordinates small. The wobble
term (cos-based) is inherently bounded and needs no fix.
Bokeh and Snowflake HLSL shaders are not affected — Bokeh already
uses frac() in its position calculation, and Snowflake uses fmod()
for the fall position.
This commit is contained in:
1 parent
f0649a9555
commit
11a424ebce
2 files changed
+8
-2
No files matched your search
@@ -61,7 +61,10 @@ float snow(float2 pos, float time, float scale)
|
||||
// add wobble
|
||||
pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0;
|
||||
// add gravity
|
||||
pos += time * scale * float2(-0.5, 1.0) * 4.0;
|
||||
// add gravity — use frac to keep position offsets small and prevent
|
||||
// precision loss in the random_dots grid lookup over long sessions
|
||||
float2 scroll = time * scale * float2(-0.5, 1.0) * 4.0;
|
||||
pos += frac(scroll / 0.05) * 0.05;
|
||||
return random_dots(pos / scale) * (scale * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ float snow(float2 pos, float time, float scale)
|
||||
// add wobble
|
||||
pos.x += cos(pos.y * 1.2 + time * 3.14159 * 2.0 + 1.0 / scale) / (8.0 / scale) * 4.0;
|
||||
// add gravity
|
||||
pos += time * scale * float2(-0.5, 1.0) * 4.0;
|
||||
// add gravity — use frac to keep position offsets small and prevent
|
||||
// precision loss in the random_dots grid lookup over long sessions
|
||||
float2 scroll = time * scale * float2(-0.5, 1.0) * 4.0;
|
||||
pos += frac(scroll / 0.05) * 0.05;
|
||||
return random_dots(pos / scale) * (scale * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user