Draw a centred image background at its pixel size

An image background not fitted to the screen keeps its own pixel size
(times its scale), centred on the viewport and moved by its offset, as
the reference draws it; tiling repeats it from there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-12 12:04:52 +03:00
1 parent bd4029fb50
commit 7a0e08129f
2 files changed
+10 -4

No files matched your search

+6 -2
View File
@@ -81,8 +81,12 @@ fn equirect_uv(ndc: vec2<f32>, rotation: f32) -> vec2<f32> {
fn image_uv(source_uv: vec2<f32>) -> vec2<f32> {
var uv = source_uv;
if u.background_image_params.x < 0.5 {
uv = (source_uv - u.background_image_transform.xy)
/ max(abs(u.background_image_transform.zw), vec2<f32>(1e-6));
// Not fitted: the image at its own pixel size (times its scale),
// centred on the viewport and moved by its offset.
let pixel = (source_uv - vec2<f32>(0.5)) * max(u.viewport_size, vec2<f32>(1.0));
uv = pixel / max(abs(u.background_image_transform.zw), vec2<f32>(1e-6))
+ vec2<f32>(0.5) - u.background_image_transform.xy;
return select(uv, fract(uv), u.background_image_params.z > 0.5);
}
if u.background_image_params.y > 0.5 {
let image_aspect = max(u.background_image_params.w, 1e-6);