aboutsummaryrefslogtreecommitdiff
path: root/src/fb/pixfb.cpp
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2026-01-17 00:06:31 +0100
committervimene <vincent.menegaux@gmail.com>2026-01-17 00:06:31 +0100
commit0d10b77f77459333c5549711334f417623ab1f3e (patch)
tree6584ab5d09fa72c93a70ac916bfdf401c7617157 /src/fb/pixfb.cpp
parent175c71637b6bea6dcdd0faf3d614339983809bb1 (diff)
downloadengine-0d10b77f77459333c5549711334f417623ab1f3e.tar.gz
improved software shaders
- unified terminal and graphical software renderer shaders - added vertex shaders for software renderers - removed VertexData - moved shaders from frame buffers to their own class - added FrameBufferConcept and ShadersConcept
Diffstat (limited to 'src/fb/pixfb.cpp')
-rw-r--r--src/fb/pixfb.cpp37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/fb/pixfb.cpp b/src/fb/pixfb.cpp
index c629adb..c86859b 100644
--- a/src/fb/pixfb.cpp
+++ b/src/fb/pixfb.cpp
@@ -2,16 +2,9 @@
#include <cstdint>
#include <algorithm>
#include "math/vector.hpp"
-#include "math/quat.hpp"
-#include "o3d/vertex_data.hpp"
-#include "o3d/camera.hpp"
using namespace engine::fb;
-using
- engine::math::Vector2,
- engine::math::Vector3,
- engine::o3d::VertexData,
- engine::o3d::Camera;
+using engine::math::Vector4;
PixelFrameBuffer::PixelFrameBuffer(unsigned int w, unsigned int h) {
resize(w, h);
@@ -28,26 +21,10 @@ void PixelFrameBuffer::clear() {
std::fill(pixels_vector.begin(), pixels_vector.end(), 0xff000000);
}
-extern Camera* camera;
-
-void PixelFrameBuffer::draw_point(int x, int y, const Vector3& /* loc */, const Vector3& normal, const Vector2& /* uv */, const VertexData& vd) {
- auto u = vd.world_loc - camera->transform.loc;
- float u_len_sq = u.length_squared();
- u = u.normalize();
- float attenuation = camera->transform.rot.rot({ 0.f, 0.f, -1.f }).dot(u);
- if (attenuation < .7f) attenuation = 0.f;
- else if (attenuation > .8f) attenuation = 1.f;
- else attenuation = (attenuation - .7f) / .1f;
- float light = -normal.normalize().dot(u) / u_len_sq;
- if (light < 0.f) light = 0.f;
- float final_light = .003f + light * attenuation * .8f * .997f;
- if (final_light > 1.f) final_light = 1.f;
- // gamma correction
- // TODO: improve, we shouldn't do it here
- if (final_light <= .0031308f)
- final_light = final_light * 12.92f;
- else
- final_light = 1.055f * pow(final_light, 1.f / 2.4f) - .055f;
- std::uint32_t c = (int) (final_light * 255.f);
- pixels_vector[x + y * w] = 0xff000000 | c << 16 | c << 8 | c;
+void PixelFrameBuffer::draw_point(int x, int y, const Vector4& point) {
+ pixels_vector[x + y * w] =
+ std::clamp(static_cast<std::uint32_t>(point.w * 256), static_cast<std::uint32_t>(0), static_cast<std::uint32_t>(255)) << (3 * 8)
+ | std::clamp(static_cast<std::uint32_t>(point.x * 256), static_cast<std::uint32_t>(0), static_cast<std::uint32_t>(255)) << (2 * 8)
+ | std::clamp(static_cast<std::uint32_t>(point.y * 256), static_cast<std::uint32_t>(0), static_cast<std::uint32_t>(255)) << (1 * 8)
+ | std::clamp(static_cast<std::uint32_t>(point.z * 256), static_cast<std::uint32_t>(0), static_cast<std::uint32_t>(255)) << (0 * 8);
}