summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSoftGPU/Sampler.cpp
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2022-01-04 15:03:13 +0100
committerLinus Groh <mail@linusgroh.de>2022-01-04 17:48:28 +0000
commita362a959121e287b7f93d5217d2421a7b53d9fb9 (patch)
treeb5985d786aa460d23e71add1a7e29bb5944f541c /Userland/Libraries/LibSoftGPU/Sampler.cpp
parentbca1b9f475512da0ff6d506aad5fe1e0e2d2bfdd (diff)
downloadserenity-a362a959121e287b7f93d5217d2421a7b53d9fb9.zip
LibSoftGPU: Shift U/V coordinates just once in `Sampler`
Diffstat (limited to 'Userland/Libraries/LibSoftGPU/Sampler.cpp')
-rw-r--r--Userland/Libraries/LibSoftGPU/Sampler.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/Userland/Libraries/LibSoftGPU/Sampler.cpp b/Userland/Libraries/LibSoftGPU/Sampler.cpp
index 986fe33213..296ebc6ba7 100644
--- a/Userland/Libraries/LibSoftGPU/Sampler.cpp
+++ b/Userland/Libraries/LibSoftGPU/Sampler.cpp
@@ -86,8 +86,11 @@ FloatVector4 Sampler::sample_2d(FloatVector2 const& uv) const
return image.texel(layer, level, i, j, 0);
}
- int i0 = m_config.texture_wrap_u == TextureWrapMode::Repeat ? static_cast<unsigned>(floorf(u - 0.5f)) % width : floorf(u - 0.5f);
- int j0 = m_config.texture_wrap_v == TextureWrapMode::Repeat ? static_cast<unsigned>(floorf(v - 0.5f)) % height : floorf(v - 0.5f);
+ u -= 0.5f;
+ v -= 0.5f;
+
+ int i0 = m_config.texture_wrap_u == TextureWrapMode::Repeat ? static_cast<unsigned>(floorf(u)) % width : floorf(u);
+ int j0 = m_config.texture_wrap_v == TextureWrapMode::Repeat ? static_cast<unsigned>(floorf(v)) % height : floorf(v);
int i1 = m_config.texture_wrap_u == TextureWrapMode::Repeat ? (i0 + 1) % width : i0 + 1;
int j1 = m_config.texture_wrap_v == TextureWrapMode::Repeat ? (j0 + 1) % height : j0 + 1;
@@ -108,8 +111,8 @@ FloatVector4 Sampler::sample_2d(FloatVector2 const& uv) const
t3 = (i1 < 0 || i1 >= w || j1 < 0 || j1 >= h) ? m_config.border_color : image.texel(layer, level, i1, j1, 0);
}
- float const alpha = fracf(u - 0.5f);
- float const beta = fracf(v - 0.5f);
+ float const alpha = fracf(u);
+ float const beta = fracf(v);
auto const lerp_0 = mix(t0, t1, alpha);
auto const lerp_1 = mix(t2, t3, alpha);