summaryrefslogtreecommitdiff
path: root/lighting.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-02-13 23:32:28 +1100
committerquou <quou@disroot.org>2025-02-13 23:33:54 +1100
commit2e4ecca19aadc09d5c3d927724f8004b6a0ff0b0 (patch)
tree156c747452788f5221158f6e2a9151eaeb61b672 /lighting.cpp
parent42cd6a572a35c354dc7d7fd390e86e7cff191617 (diff)
refactoring; prep for shadows
Diffstat (limited to 'lighting.cpp')
-rw-r--r--lighting.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/lighting.cpp b/lighting.cpp
index d78ef6e..75ae7c2 100644
--- a/lighting.cpp
+++ b/lighting.cpp
@@ -1,4 +1,5 @@
#include "lighting.hpp"
+#include "model.hpp"
#include "world.hpp"
extern "C" {
@@ -15,21 +16,52 @@ struct GPU_Light {
};
void Lighting::init(Device* dev) {
+ int i;
lights.init(
dev,
"Light buffer",
max_lights * sizeof(GPU_Light),
Buffer_Flags::storage_buffer
);
+ shadows = dev->create_texture(
+ "Shadowmap Array",
+ texture_format_d16,
+ Texture_Flags::sampleable | Texture_Flags::depth_stencil_target,
+ shadow_res,
+ shadow_res,
+ 1,
+ 1,
+ max_shadows,
+ 0
+ );
+ for (i = 0; i < max_shadows; i++) {
+ shadow_slices[i] = dev->alias_texture(
+ shadows,
+ "Shadowmap Slice",
+ texture_format_d16,
+ Texture_Flags::depth_stencil_target,
+ shadow_res,
+ shadow_res,
+ 1,
+ 1,
+ 1,
+ 0,
+ i
+ );
+ }
}
void Lighting::destroy(Device* dev) {
+ int i;
lights.destroy(dev);
+ for (i = 0; i < max_shadows; i++)
+ dev->destroy_texture(shadow_slices[i]);
+ dev->destroy_texture(shadows);
}
void Lighting::write_buf(void* ptr, World& w) {
GPU_Light* dst = (GPU_Light*)ptr;
- int count = 0;
+ int count = 0, ccount = 0;
for (auto v : w.view<Sun_Light>()) {
GPU_Light gl;
Sun_Light& l = v.get<Sun_Light>();
@@ -41,8 +73,13 @@ void Lighting::write_buf(void* ptr, World& w) {
gl.colour = l.colour;
gl.dir = l.dir;
dst[count++] = gl;
+ if (l.caster) {
+ Caster& c = casters[ccount++];
+ c.vp = m4f::identity();
+ }
}
light_count = count;
+ caster_count = ccount;
}
void Lighting::update(Device* dev, Context& ctx, World& w) {