summaryrefslogtreecommitdiff
path: root/game/scenary
diff options
context:
space:
mode:
Diffstat (limited to 'game/scenary')
-rw-r--r--game/scenary/foliage.cpp38
-rw-r--r--game/scenary/foliage.h21
-rw-r--r--game/scenary/illuminator.cpp12
-rw-r--r--game/scenary/illuminator.h8
-rw-r--r--game/scenary/plant.cpp3
5 files changed, 65 insertions, 17 deletions
diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp
index c258b77..140c4e5 100644
--- a/game/scenary/foliage.cpp
+++ b/game/scenary/foliage.cpp
@@ -2,8 +2,16 @@
#include "gfx/gl/sceneShader.h"
#include "gfx/gl/shadowMapper.h"
#include "gfx/gl/vertexArrayObject.h"
-#include "gfx/models/texture.h"
-#include "location.h"
+#include <location.h>
+
+static_assert(std::is_constructible_v<Foliage>);
+
+std::any
+Foliage::createAt(const Location & position) const
+{
+ return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>(
+ instances.acquire(position.getRotationTransform(), position.rot.y, position.pos));
+}
bool
Foliage::persist(Persistence::PersistenceStore & store)
@@ -16,11 +24,22 @@ Foliage::postLoad()
{
texture = getTexture();
bodyMesh->configureVAO(instanceVAO)
- .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1);
+ .addAttribs<LocationVertex, &LocationVertex::rotation, &LocationVertex::position>(
+ instances.bufferName(), 1);
+ VertexArrayObject {instancePointVAO}.addAttribs<LocationVertex, &LocationVertex::position, &LocationVertex::yaw>(
+ instances.bufferName());
+}
+
+void
+Foliage::updateStencil(const ShadowStenciller & ss) const
+{
+ if (instances.size() > 0) {
+ ss.renderStencil(shadowStencil, *bodyMesh, texture);
+ }
}
void
-Foliage::render(const SceneShader & shader) const
+Foliage::render(const SceneShader & shader, const Frustum &) const
{
if (const auto count = instances.size()) {
shader.basicInst.use();
@@ -32,10 +51,15 @@ Foliage::render(const SceneShader & shader) const
}
void
-Foliage::shadows(const ShadowMapper & mapper) const
+Foliage::shadows(const ShadowMapper & mapper, const Frustum &) const
{
if (const auto count = instances.size()) {
- mapper.dynamicPointInst.use();
- 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 3beda89..d15a8b0 100644
--- a/game/scenary/foliage.h
+++ b/game/scenary/foliage.h
@@ -2,23 +2,34 @@
#include "assetFactory/asset.h"
#include "gfx/gl/instanceVertices.h"
+#include "gfx/gl/shadowStenciller.h"
+#include "gfx/models/texture.h"
#include "gfx/renderable.h"
class SceneShader;
class ShadowMapper;
class Location;
-class Texture;
class Foliage : public Asset, public Renderable, public StdTypeDefs<Foliage> {
Mesh::Ptr bodyMesh;
- std::shared_ptr<Texture> texture;
+ Texture::Ptr texture;
glVertexArray instanceVAO;
+ glVertexArray instancePointVAO;
public:
- using LocationVertex = std::pair<glm::mat3, GlobalPosition3D>;
+ [[nodiscard]] std::any createAt(const Location &) const override;
+
+ struct LocationVertex {
+ glm::mat3 rotation;
+ float yaw;
+ GlobalPosition3D position;
+ };
+
mutable InstanceVertices<LocationVertex> instances;
- void render(const SceneShader &) const override;
- void shadows(const ShadowMapper &) const override;
+ void render(const SceneShader &, const Frustum &) const override;
+ void shadows(const ShadowMapper &, const Frustum &) const override;
+ void updateStencil(const ShadowStenciller &) const override;
+ glTexture shadowStencil = ShadowStenciller::createStencilTexture(256, 256);
protected:
friend Persistence::SelectionPtrBase<std::shared_ptr<Foliage>>;
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp
index e3810ec..d8e4c4e 100644
--- a/game/scenary/illuminator.cpp
+++ b/game/scenary/illuminator.cpp
@@ -2,6 +2,16 @@
#include "gfx/gl/sceneShader.h"
#include "gfx/gl/vertexArrayObject.h"
#include "gfx/models/texture.h" // IWYU pragma: keep
+#include <location.h>
+
+static_assert(std::is_constructible_v<Illuminator>);
+
+std::any
+Illuminator::createAt(const Location & position) const
+{
+ return std::make_shared<InstanceVertices<LocationVertex>::InstanceProxy>(
+ instances.acquire(position.getRotationTransform(), position.pos));
+}
bool
Illuminator::SpotLight::persist(Persistence::PersistenceStore & store)
@@ -59,7 +69,7 @@ Illuminator::postLoad()
}
void
-Illuminator::render(const SceneShader & shader) const
+Illuminator::render(const SceneShader & shader, const Frustum &) const
{
if (const auto count = instances.size()) {
shader.basicInst.use();
diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h
index cd6073c..200ba40 100644
--- a/game/scenary/illuminator.h
+++ b/game/scenary/illuminator.h
@@ -2,19 +2,21 @@
#include "assetFactory/asset.h"
#include "gfx/gl/instanceVertices.h"
+#include "gfx/models/texture.h"
#include "gfx/renderable.h"
class SceneShader;
class Location;
-class Texture;
class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> {
Mesh::Ptr bodyMesh;
- std::shared_ptr<Texture> texture;
+ Texture::Ptr texture;
glVertexArray instanceVAO;
std::optional<glVertexArray> instancesSpotLightVAO, instancesPointLightVAO;
public:
+ [[nodiscard]] std::any createAt(const Location &) const override;
+
struct LightCommonVertex {
RelativePosition3D position;
RGB colour;
@@ -45,7 +47,7 @@ public:
mutable InstanceVertices<LocationVertex> instances;
mutable InstanceVertices<SpotLightVertex> instancesSpotLight;
mutable InstanceVertices<PointLightVertex> instancesPointLight;
- void render(const SceneShader &) const override;
+ void render(const SceneShader &, const Frustum &) const override;
void lights(const SceneShader &) const override;
protected:
diff --git a/game/scenary/plant.cpp b/game/scenary/plant.cpp
index b39c28b..2006225 100644
--- a/game/scenary/plant.cpp
+++ b/game/scenary/plant.cpp
@@ -2,6 +2,7 @@
#include "location.h"
Plant::Plant(std::shared_ptr<const Foliage> type, const Location & position) :
- type {std::move(type)}, location {this->type->instances.acquire(position.getRotationTransform(), position.pos)}
+ type {std::move(type)},
+ location {this->type->instances.acquire(position.getRotationTransform(), position.rot.y, position.pos)}
{
}