Browse Source

LibSoftGPU: Shift U/V coordinates just once in `Sampler`

Jelle Raaijmakers 3 years ago
parent
commit
a362a95912
1 changed files with 7 additions and 4 deletions
  1. 7 4
      Userland/Libraries/LibSoftGPU/Sampler.cpp

+ 7 - 4
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);