summaryrefslogtreecommitdiff
path: root/lighting.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-03-10 15:03:05 +1100
committerquou <quou@disroot.org>2025-03-10 15:03:05 +1100
commit37b929e148e5b003f68903eb9ee192d24517e683 (patch)
tree79c39617fa73ddc95f30f0ff2c86b5b81c6de0bc /lighting.cpp
parent075e530b9964d1eb000dded329d2e8d80ee277c3 (diff)
point light
Diffstat (limited to 'lighting.cpp')
-rw-r--r--lighting.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/lighting.cpp b/lighting.cpp
index 0e41ddd..bf01831 100644
--- a/lighting.cpp
+++ b/lighting.cpp
@@ -1,6 +1,7 @@
#include "lighting.hpp"
#include "model.hpp"
#include "renderer.hpp"
+#include "scene.hpp"
#include "world.hpp"
extern "C" {
@@ -10,10 +11,13 @@ extern "C" {
/* needs to match surface shader */
struct GPU_Light {
- v3f dir;
+ v3f pos;
float brightness;
v3f colour;
int caster_id;
+ int type;
+ float range;
+ int pad[2];
};
struct GPU_Caster {
@@ -102,11 +106,12 @@ void Lighting::write_bufs(
Sun_Light& l = v.get<Sun_Light>();
if (count >= max_lights) {
print_war("Over light limit.\n");
- return;
+ goto cancel;
}
+ gl.type = (int)Light::Type::sun;
gl.brightness = l.brightness;
gl.colour = l.colour;
- gl.dir = l.dir;
+ gl.pos = l.dir;
if (l.caster && ccount < max_shadows) {
int cid = ccount++;
GPU_Caster& c = cdst[cid];
@@ -122,6 +127,27 @@ void Lighting::write_bufs(
gl.caster_id = -1;
ldst[count++] = gl;
}
+ for (auto v : w.view<Transform, Point_Light>()) {
+ GPU_Light gl;
+ Transform& t = v.get<Transform>();
+ Point_Light& l = v.get<Point_Light>();
+ if (count >= max_lights) {
+ print_war("Over light limit.\n");
+ goto cancel;
+ }
+ gl.type = (int)Light::Type::point;
+ gl.brightness = l.brightness;
+ gl.colour = l.colour;
+ gl.pos = v3f(
+ t.mat.m[3][0],
+ t.mat.m[3][1],
+ t.mat.m[3][2]
+ );
+ gl.caster_id = -1;
+ gl.range = l.range;
+ ldst[count++] = gl;
+ }
+cancel:
light_count = count;
caster_count = ccount;
}