aboutsummaryrefslogtreecommitdiff
path: root/src/shaders/simple_shaders.hpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2026-02-03 20:26:01 +0100
committervimene <vincent.menegaux@gmail.com>2026-02-03 20:26:01 +0100
commitcbf7d23623b5bb2d2092cb6c86bc965138b4ea75 (patch)
tree7234b255b871cecca24aadc03c8d0857202f48e4 /src/shaders/simple_shaders.hpp
parent0d10b77f77459333c5549711334f417623ab1f3e (diff)
downloadengine-cbf7d23623b5bb2d2092cb6c86bc965138b4ea75.tar.gz
added mipmaps for the hw renderer, improvementsHEADmain
This commit add mipmaps, but for now, mipmaps are generated on the gpu at runtime. We should generate them in advance. - added mipmaps for the hardware renderer - renamed stb_image.c to stb_image.cpp - add compiler flag to stb_image.cpp to prevent warning - added pipe notation for various objects to have all clipping functions be left to right. We need this for the time being because dot notation would considerably complicate the current implementation - small improvements
Diffstat (limited to 'src/shaders/simple_shaders.hpp')
-rw-r--r--src/shaders/simple_shaders.hpp29
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];
}
};