diff options
Diffstat (limited to 'src/shaders/simple_shaders.hpp')
| -rw-r--r-- | src/shaders/simple_shaders.hpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/shaders/simple_shaders.hpp b/src/shaders/simple_shaders.hpp index c308ab3..831f969 100644 --- a/src/shaders/simple_shaders.hpp +++ b/src/shaders/simple_shaders.hpp @@ -3,6 +3,7 @@ #include <algorithm> #include <cmath> +#include <vector> #include "fb/pixfb.hpp" #include "math/vector.hpp" #include "math/mat4.hpp" @@ -16,7 +17,7 @@ class SimpleShaders { engine::math::Matrix4 model_mat, view_mat, proj_mat, final_mat; int w, h; - unsigned char* pixels; + std::vector<engine::math::Vector4> pixels; SimpleShaders(int w, int h, unsigned char* pixels); void set_view(const engine::math::Matrix4& view_mat, const engine::math::Matrix4& proj_mat); @@ -54,27 +55,11 @@ class SimpleShaders { int tx1 = std::clamp(static_cast<int>(txf) + 1, 0, w); int ty0 = std::clamp(static_cast<int>(tyf) + 0, 0, h); int ty1 = std::clamp(static_cast<int>(tyf) + 1, 0, h); - float r00 = static_cast<float>(pixels[(tx0 + ty0 * w) * 4 + 0]) / 255.f; - float r10 = static_cast<float>(pixels[(tx1 + ty0 * w) * 4 + 0]) / 255.f; - float r01 = static_cast<float>(pixels[(tx0 + ty1 * w) * 4 + 0]) / 255.f; - float r11 = static_cast<float>(pixels[(tx1 + ty1 * w) * 4 + 0]) / 255.f; - float r = (1.f - fac_x) * (1.f - fac_y) * r00 + fac_x * (1.f - fac_y) * r10 + (1.f - fac_x) * fac_y * r01 + fac_x * fac_y * r11; - float g00 = static_cast<float>(pixels[(tx0 + ty0 * w) * 4 + 1]) / 255.f; - float g10 = static_cast<float>(pixels[(tx1 + ty0 * w) * 4 + 1]) / 255.f; - float g01 = static_cast<float>(pixels[(tx0 + ty1 * w) * 4 + 1]) / 255.f; - float g11 = static_cast<float>(pixels[(tx1 + ty1 * w) * 4 + 1]) / 255.f; - float g = (1.f - fac_x) * (1.f - fac_y) * g00 + fac_x * (1.f - fac_y) * g10 + (1.f - fac_x) * fac_y * g01 + fac_x * fac_y * g11; - float b00 = static_cast<float>(pixels[(tx0 + ty0 * w) * 4 + 2]) / 255.f; - float b10 = static_cast<float>(pixels[(tx1 + ty0 * w) * 4 + 2]) / 255.f; - float b01 = static_cast<float>(pixels[(tx0 + ty1 * w) * 4 + 2]) / 255.f; - float b11 = static_cast<float>(pixels[(tx1 + ty1 * w) * 4 + 2]) / 255.f; - float b = (1.f - fac_x) * (1.f - fac_y) * b00 + fac_x * (1.f - fac_y) * b10 + (1.f - fac_x) * fac_y * b01 + fac_x * fac_y * b11; - float a00 = static_cast<float>(pixels[(tx0 + ty0 * w) * 4 + 3]) / 255.f; - float a10 = static_cast<float>(pixels[(tx1 + ty0 * w) * 4 + 3]) / 255.f; - float a01 = static_cast<float>(pixels[(tx0 + ty1 * w) * 4 + 3]) / 255.f; - float a11 = static_cast<float>(pixels[(tx1 + ty1 * w) * 4 + 3]) / 255.f; - float a = (1.f - fac_x) * (1.f - fac_y) * a00 + fac_x * (1.f - fac_y) * a10 + (1.f - fac_x) * fac_y * a01 + fac_x * fac_y * a11; - return engine::math::Vector4 { r, g, b, a }; + return + ((1.f - fac_x) * (1.f - fac_y)) * pixels[tx0 + ty0 * w] + + (fac_x * (1.f - fac_y)) * pixels[tx1 + ty0 * w] + + ((1.f - fac_x) * fac_y ) * pixels[tx0 + ty1 * w] + + (fac_x * fac_y ) * pixels[tx1 + ty1 * w]; } }; |
