This commit is contained in:
arvid schröder 2022-12-13 00:18:46 +01:00
parent f561ceec19
commit 32e54bbdf1

View file

@ -62,10 +62,10 @@ Color Texture::color(float u, float v, bool interpolate) const {
float y2 = std::ceil(v * this->height());
float x = u * this->width();
float y = v * this->height();
Color x1y1 = this->getPixelAt(int(x1), int(y1));
Color x2y1 = this->getPixelAt(int(x2), int(y1));
Color x1y2 = this->getPixelAt(int(x1), int(y2));
Color x2y2 = this->getPixelAt(int(x2), int(y2));
Color x1y1 = this->getPixelAt(static_cast<int>(x1), static_cast<int>(y1));
Color x2y1 = this->getPixelAt(static_cast<int>(x2), static_cast<int>(y1));
Color x1y2 = this->getPixelAt(static_cast<int>(x1), static_cast<int>(y2));
Color x2y2 = this->getPixelAt(static_cast<int>(x2), static_cast<int>(y2));
Color fxy1 = ((x2 - x) / (x2 - x1)) * x1y1 + ((x - x1) / (x2 - x1)) * x2y1;
Color fxy2 = ((x2 - x) / (x2 - x1)) * x1y2 + ((x - x1) / (x2 - x1)) * x2y2;
color = ((y2 - y) / (y2 - y1)) * fxy1 + ((y - y1) / (y2 - y1)) * fxy2;