diff options
author | quou <quou@disroot.org> | 2025-02-22 23:11:15 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2025-02-22 23:25:45 +1100 |
commit | ed5d6dfa2ed08c5a9185f3eb4ffb4deb898ed2af (patch) | |
tree | 29a6dc82b3ccd528c80978dbc5bd6ef8c925f231 /lighting.cpp | |
parent | ab9ed1ccadbd2c1b971bfbfb5ee651aa03a4a63e (diff) |
move shadows to a fullscreen buffer
Diffstat (limited to 'lighting.cpp')
-rw-r--r-- | lighting.cpp | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/lighting.cpp b/lighting.cpp index 0e41ddd..4f1fdfb 100644 --- a/lighting.cpp +++ b/lighting.cpp @@ -20,7 +20,7 @@ struct GPU_Caster { m4f projection; }; -void Lighting::init(Device* dev) { +void Lighting::init(Device* dev, int w, int h) { int i; Sampler_State ss{}; lights.init( @@ -46,6 +46,9 @@ void Lighting::init(Device* dev) { max_shadows, 0 ); + zero(ss_shadows, sizeof ss_shadows); + zero(ss_shadow_slices, sizeof ss_shadow_slices); + recreate(dev, w, h); for (i = 0; i < max_shadows; i++) { cameras[i] = 0; shadow_slices[i] = dev->alias_texture( @@ -85,6 +88,50 @@ void Lighting::destroy(Device* dev, Renderer& r) { r.destroy_camera(cameras[i]); } dev->destroy_texture(shadows); + destroy_ss(dev); +} + +void Lighting::destroy_ss(Device* dev) { + int i, j; + for (i = 0; i < 2; i++) { + for (j = 0; j < max_shadows; j++) + if (ss_shadow_slices[i][j]) + dev->destroy_texture(ss_shadow_slices[i][j]); + if (ss_shadows[i]) + dev->destroy_texture(ss_shadows[i]); + } +} + +void Lighting::recreate(Device* dev, int w, int h) { + int i, j; + destroy_ss(dev); + for (i = 0; i < 2; i++) { + ss_shadows[i] = dev->create_texture( + "Shadow accumulation buffer", + texture_format_r8i, + Texture_Flags::sampleable | Texture_Flags::colour_target, + w, + h, + 1, + 1, + max_shadows, + 0 + ); + for (j = 0; j < max_shadows; j++) + ss_shadow_slices[i][j] = dev->alias_texture( + ss_shadows[i], + "Shadow accumulation buffer slice", + texture_format_r8i, + Texture_Flags::colour_target, + shadow_res, + shadow_res, + 1, + 1, + 1, + 0, + j + ); + } } void Lighting::write_bufs( |