diff --git a/crates/horizon-client/src/screen.wgsl b/crates/horizon-client/src/screen.wgsl index a82b0f890..f32274bc8 100644 --- a/crates/horizon-client/src/screen.wgsl +++ b/crates/horizon-client/src/screen.wgsl @@ -23,9 +23,11 @@ struct Out { } const SAMPLE_BLUR: u32 = 1u; const SAMPLE_CLAMP: u32 = 2u; -// A texel of the sprite, addressed by repeat or clamp-to-edge. +// A texel of the sprite, addressed by repeat or clamp-to-edge. With repeat, `p` is at most one +// texel outside the sprite (`sample` reduces the coordinate first), so wrapping is a select: no +// integer division, which Intel GPUs emulate (it cost 0.85 ms a frame on the vignette on an HD 620). fn texel(origin: vec2, size: vec2, p: vec2, clamp_edge: bool) -> vec4 { - var q = ((p % size) + size) % size; + var q = select(select(p, p - size, p >= size), p + size, p < vec2(0)); if clamp_edge { q = clamp(p, vec2(0), size - 1); } return textureLoad(atlas, origin + q, 0); } @@ -34,7 +36,8 @@ fn sample(in: Out) -> vec4 { let origin = vec2(round(in.rect.xy * dims)); let size = max(vec2(round((in.rect.zw - in.rect.xy) * dims)), vec2(1)); let clamp_edge = (in.sampling & SAMPLE_CLAMP) != 0u; - let p = in.uv * vec2(size); + // Repeat: one period of the sprite, so every texel read is at most one outside it. + let p = select(fract(in.uv), in.uv, clamp_edge) * vec2(size); if (in.sampling & SAMPLE_BLUR) == 0u { return texel(origin, size, vec2(floor(p)), clamp_edge) * in.color; }