diff --git a/include/soft_render/core/texture.hpp b/include/soft_render/core/texture.hpp index e7ee146..fd54895 100644 --- a/include/soft_render/core/texture.hpp +++ b/include/soft_render/core/texture.hpp @@ -34,8 +34,8 @@ class Texture { if (width_ == 0 || height_ == 0) return {1, 1, 1}; // Wrap - u = u - std::floor(u); - v = v - std::floor(v); + int iu = static_cast(u); u = u - static_cast(iu - (iu > u)); + int iv = static_cast(v); v = v - static_cast(iv - (iv > v)); float fx = u * (width_ - 1); float fy = v * (height_ - 1); @@ -58,8 +58,8 @@ class Texture { // Nearest-neighbor (faster) math::Color sampleNearest(float u, float v) const { if (width_ == 0 || height_ == 0) return {1, 1, 1}; - u = u - std::floor(u); - v = v - std::floor(v); + int iu = static_cast(u); u = u - static_cast(iu - (iu > u)); + int iv = static_cast(v); v = v - static_cast(iv - (iv > v)); int x = static_cast(u * width_) % width_; int y = static_cast(v * height_) % height_; return fetch(x, y);