diff options
Diffstat (limited to 'game/scenary')
-rw-r--r-- | game/scenary/foliage.cpp | 24 | ||||
-rw-r--r-- | game/scenary/foliage.h | 4 |
2 files changed, 22 insertions, 6 deletions
diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 73d285f..1e7424e 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,6 +16,17 @@ Foliage::postLoad() texture = getTexture(); bodyMesh->configureVAO(instanceVAO) .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1); + VertexArrayObject {instancePointVAO}.addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>( + instances.bufferName()); +} + +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 @@ -35,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<GLsizei>(count)); + const auto dimensions = bodyMesh->getDimensions(); + mapper.stencilShadowProgram.use(dimensions.centre, dimensions.size); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D_ARRAY, shadowStencil); + glBindVertexArray(instancePointVAO); + glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(count)); + glBindVertexArray(0); } } diff --git a/game/scenary/foliage.h b/game/scenary/foliage.h index 0a4261c..824a644 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" @@ -13,12 +14,15 @@ class Foliage : public Asset, public Renderable, public StdTypeDefs<Foliage> { Mesh::Ptr bodyMesh; Texture::Ptr texture; glVertexArray instanceVAO; + glVertexArray instancePointVAO; public: using LocationVertex = std::pair<glm::mat3, GlobalPosition3D>; mutable InstanceVertices<LocationVertex> 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: friend Persistence::SelectionPtrBase<std::shared_ptr<Foliage>>; |