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 --- gfx/gl/shadowStenciller.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 gfx/gl/shadowStenciller.h (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h new file mode 100644 index 0000000..460fa68 --- /dev/null +++ b/gfx/gl/shadowStenciller.h @@ -0,0 +1,21 @@ +#pragma once + +#include "config/types.h" +#include "gfx/gl/program.h" +#include "gfx/models/mesh.h" +#include "glArrays.h" + +class ShadowStenciller { +public: + ShadowStenciller(); + + [[nodiscard]] + static glTexture createStencilTexture(GLsizei width, GLsizei height); + void renderStencil(const glTexture &, const MeshBase &, const RelativePosition3D & mins, + const RelativePosition3D & maxs) const; + +private: + glFrameBuffer fbo; + Program shadowCaster; + Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; +}; -- 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 --- gfx/gl/shadowStenciller.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 460fa68..5a22a7e 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -11,8 +11,7 @@ public: [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); - void renderStencil(const glTexture &, const MeshBase &, const RelativePosition3D & mins, - const RelativePosition3D & maxs) const; + void renderStencil(const glTexture &, const MeshBase &) const; private: glFrameBuffer fbo; -- 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 --- gfx/gl/shadowStenciller.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 5a22a7e..bf6d204 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -1,8 +1,8 @@ #pragma once -#include "config/types.h" #include "gfx/gl/program.h" #include "gfx/models/mesh.h" +#include "gfx/models/texture.h" #include "glArrays.h" class ShadowStenciller { @@ -11,7 +11,7 @@ public: [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); - void renderStencil(const glTexture &, const MeshBase &) const; + void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const; private: glFrameBuffer fbo; -- 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 --- gfx/gl/shadowStenciller.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index bf6d204..87dc044 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -7,7 +7,7 @@ class ShadowStenciller { public: - ShadowStenciller(); + ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp); [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); @@ -16,5 +16,6 @@ public: private: glFrameBuffer fbo; Program shadowCaster; + glm::mat4 lightDirMat; Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; }; -- cgit v1.2.3 From dd452f3e9238be954c3ecd325ed11e97a50ec1c3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 19 Aug 2024 23:26:32 +0100 Subject: Persist a single ShadowStenciller within ShadowMapper --- gfx/gl/shadowStenciller.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 87dc044..009285c 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -7,15 +7,17 @@ class ShadowStenciller { public: - ShadowStenciller(const Direction3D & lightDir, const Direction3D & lightDirUp); + ShadowStenciller(); [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); + void setLightDirection(const Direction3D & lightDir, const Direction3D & lightDirUp); void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const; private: glFrameBuffer fbo; Program shadowCaster; - glm::mat4 lightDirMat; Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; + + glm::mat4 lightDirMat {}; }; -- cgit v1.2.3 From 10e0fee323e6277ba73ee1fc148417882bc381c3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Aug 2024 13:55:32 +0100 Subject: Add helper to test if a uniform was found --- gfx/gl/shadowStenciller.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 009285c..925f82a 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -17,7 +17,7 @@ public: private: glFrameBuffer fbo; Program shadowCaster; - Program::UniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; + Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; glm::mat4 lightDirMat {}; }; -- cgit v1.2.3 From 5ec74c35fb1f2524add7fd03ace78667f93edb2e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 7 Sep 2024 12:35:03 +0100 Subject: Populate all layers of shadow stencil with view from all around --- gfx/gl/shadowStenciller.h | 1 + 1 file changed, 1 insertion(+) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 925f82a..2edb955 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -20,4 +20,5 @@ private: Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; glm::mat4 lightDirMat {}; + std::array viewProjections; }; -- cgit v1.2.3 From 10998a8302b3d7651b4afc046311961eb2dea2c8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Oct 2024 12:48:40 +0100 Subject: Use LightDirection for calculating/passing all light dir components --- gfx/gl/shadowStenciller.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 2edb955..03efced 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -5,13 +5,15 @@ #include "gfx/models/texture.h" #include "glArrays.h" +class LightDirection; + class ShadowStenciller { public: ShadowStenciller(); [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); - void setLightDirection(const Direction3D & lightDir, const Direction3D & lightDirUp); + void setLightDirection(const LightDirection & lightDir); void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const; private: @@ -19,6 +21,5 @@ private: Program shadowCaster; Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; - glm::mat4 lightDirMat {}; std::array viewProjections; }; -- cgit v1.2.3 From 9a43f9e749f9f51cb37dabd9c1d33f2ee9441b2f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Oct 2024 18:26:24 +0100 Subject: Re-express viewProjections calculations as a fold expression --- gfx/gl/shadowStenciller.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index 03efced..ac83eb1 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -9,6 +9,8 @@ class LightDirection; class ShadowStenciller { public: + template static constexpr T STENCIL_ANGLES = 8; + ShadowStenciller(); [[nodiscard]] @@ -21,5 +23,5 @@ private: Program shadowCaster; Program::RequiredUniformLocation viewProjectionLoc {shadowCaster, "viewProjection"}; - std::array viewProjections; + std::array> viewProjections; }; -- cgit v1.2.3 From 33a691f6ab681160b377102aa02e78ccdfaf1ec3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 17 Oct 2024 18:27:50 +0100 Subject: Misc readability fixes --- gfx/gl/shadowStenciller.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl/shadowStenciller.h') diff --git a/gfx/gl/shadowStenciller.h b/gfx/gl/shadowStenciller.h index ac83eb1..f774ac7 100644 --- a/gfx/gl/shadowStenciller.h +++ b/gfx/gl/shadowStenciller.h @@ -16,7 +16,7 @@ public: [[nodiscard]] static glTexture createStencilTexture(GLsizei width, GLsizei height); void setLightDirection(const LightDirection & lightDir); - void renderStencil(const glTexture &, const MeshBase &, const Texture::AnyPtr texture) const; + void renderStencil(const glTexture &, const MeshBase &, Texture::AnyPtr texture) const; private: glFrameBuffer fbo; -- cgit v1.2.3