From 37b929e148e5b003f68903eb9ee192d24517e683 Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 10 Mar 2025 15:03:05 +1100 Subject: point light --- lighting.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'lighting.cpp') 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(); 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()) { + GPU_Light gl; + Transform& t = v.get(); + Point_Light& l = v.get(); + 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; } -- cgit v1.2.3-54-g00ecf