From 900d19a41bc1886e7a809d99d6119b12235a4f0a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jul 2024 10:57:17 +0100 Subject: Initial commit of basic shadow depth map creation --- game/scenary/foliage.cpp | 3 +++ game/scenary/foliage.h | 2 ++ 2 files changed, 5 insertions(+) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 73d285f..870adb0 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -17,6 +17,9 @@ Foliage::postLoad() texture = getTexture(); bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); + ShadowStenciller ss; + ss.renderStencil(shadowStencil, *bodyMesh, {-4000, -4000, 0}, {4000, 4000, 8000}); + Texture::saveDepth(shadowStencil, std::format("/tmp/stencil-{}.tga", id).c_str()); } void diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index 0a4261c..5367d44 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -2,6 +2,7 @@ #include "assetFactory/asset.h" #include "gfx/gl/instanceVertices.h" +#include "gfx/gl/shadowStenciller.h" #include "gfx/models/texture.h" #include "gfx/renderable.h" @@ -19,6 +20,7 @@ public: mutable InstanceVertices instances; void render(const SceneShader &) const override; void shadows(const ShadowMapper &) const override; + glTexture shadowStencil = ShadowStenciller::createStencilTexture(256, 256); protected: friend Persistence::SelectionPtrBase>; -- cgit v1.2.3 From 4ba67f34eac848e43bad2ccc4b5c09ac65dd7952 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jul 2024 12:55:15 +0100 Subject: Use mesh extents for shadow stencil extents --- game/scenary/foliage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 870adb0..24caeb7 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -18,7 +18,7 @@ Foliage::postLoad() bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); ShadowStenciller ss; - ss.renderStencil(shadowStencil, *bodyMesh, {-4000, -4000, 0}, {4000, 4000, 8000}); + ss.renderStencil(shadowStencil, *bodyMesh); Texture::saveDepth(shadowStencil, std::format("/tmp/stencil-{}.tga", id).c_str()); } -- cgit v1.2.3 From f737aada2b7164683303beb3bb490c30a4949fb0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Jul 2024 02:33:24 +0100 Subject: Use texture alpha in shadow stencil --- game/scenary/foliage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 24caeb7..ba1b37e 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -18,7 +18,7 @@ Foliage::postLoad() bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); ShadowStenciller ss; - ss.renderStencil(shadowStencil, *bodyMesh); + ss.renderStencil(shadowStencil, *bodyMesh, texture); Texture::saveDepth(shadowStencil, std::format("/tmp/stencil-{}.tga", id).c_str()); } -- cgit v1.2.3 From 172beac34e82c86f8c16b8a1be5fca9d7ccfc0d1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 18 Aug 2024 16:14:29 +0100 Subject: Update asset stencils from shadow mapper --- game/scenary/foliage.cpp | 13 +++++++++---- game/scenary/foliage.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index ba1b37e..13d2f3b 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -3,7 +3,6 @@ #include "gfx/gl/shadowMapper.h" #include "gfx/gl/vertexArrayObject.h" #include "gfx/models/texture.h" -#include "location.h" bool Foliage::persist(Persistence::PersistenceStore & store) @@ -17,9 +16,15 @@ Foliage::postLoad() texture = getTexture(); bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); - ShadowStenciller ss; - ss.renderStencil(shadowStencil, *bodyMesh, texture); - Texture::saveDepth(shadowStencil, std::format("/tmp/stencil-{}.tga", id).c_str()); +} + +void +Foliage::updateStencil(const ShadowStenciller & ss) const +{ + if (instances.size() > 0) { + ss.renderStencil(shadowStencil, *bodyMesh, texture); + Texture::saveDepth(shadowStencil, std::format("/tmp/stencil-{}.tga", id).c_str()); + } } void diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index 5367d44..fa6c63b 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -20,6 +20,7 @@ public: mutable InstanceVertices instances; void render(const SceneShader &) const override; void shadows(const ShadowMapper &) const override; + void updateStencil(const ShadowStenciller &) const override; glTexture shadowStencil = ShadowStenciller::createStencilTexture(256, 256); protected: -- cgit v1.2.3 From 362c6952742eb01e32fdeb2ec26a2fe463e5001c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Aug 2024 13:47:22 +0100 Subject: Add a foliage vertex array for just the location data --- game/scenary/foliage.cpp | 2 ++ game/scenary/foliage.h | 1 + 2 files changed, 3 insertions(+) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 13d2f3b..1c03217 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -16,6 +16,8 @@ Foliage::postLoad() texture = getTexture(); bodyMesh->configureVAO(instanceVAO) .addAttribs(instances.bufferName(), 1); + VertexArrayObject {instancePointVAO}.addAttribs( + instances.bufferName()); } void diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index fa6c63b..824a644 100644 --- a/game/scenary/foliage.h +++ b/game/scenary/foliage.h @@ -14,6 +14,7 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs { Mesh::Ptr bodyMesh; Texture::Ptr texture; glVertexArray instanceVAO; + glVertexArray instancePointVAO; public: using LocationVertex = std::pair; -- cgit v1.2.3 From 75905c01b13fd7a1d58494b8aaacb3b4b3cccdaa Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 28 Aug 2024 03:48:43 +0100 Subject: Use billboard shadows for foliage --- game/scenary/foliage.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 1c03217..af67ea6 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -45,10 +45,12 @@ void Foliage::shadows(const ShadowMapper & mapper) const { if (const auto count = instances.size()) { - mapper.dynamicPointInstWithTextures.use(); - if (texture) { - texture->bind(GL_TEXTURE3); - } - bodyMesh->DrawInstanced(instanceVAO, static_cast(count)); + const auto dimensions = bodyMesh->getDimensions(); + mapper.stencilShadowProgram.use(dimensions.centre, dimensions.size); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, shadowStencil); + glBindVertexArray(instancePointVAO); + glDrawArrays(GL_POINTS, 0, static_cast(count)); + glBindVertexArray(0); } } -- cgit v1.2.3 From 052b2b49d9bfdaaa7f7c5603fa7c47b881df93c2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 2 Sep 2024 21:00:41 +0100 Subject: Update stencil texture to 2d array --- game/scenary/foliage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index af67ea6..1e7424e 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -48,7 +48,7 @@ Foliage::shadows(const ShadowMapper & mapper) const const auto dimensions = bodyMesh->getDimensions(); mapper.stencilShadowProgram.use(dimensions.centre, dimensions.size); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, shadowStencil); + glBindTexture(GL_TEXTURE_2D_ARRAY, shadowStencil); glBindVertexArray(instancePointVAO); glDrawArrays(GL_POINTS, 0, static_cast(count)); glBindVertexArray(0); -- cgit v1.2.3