diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-12 19:35:58 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-12 19:35:58 +0000 |
commit | 51eb25ea0f1373ca0442b02049406af38eae3b33 (patch) | |
tree | 389169a5f60d58398554168b94a0c6003302fbf6 /game/scenary | |
parent | Fix order or multiple to address reversed rotation (diff) | |
download | ilt-51eb25ea0f1373ca0442b02049406af38eae3b33.tar.bz2 ilt-51eb25ea0f1373ca0442b02049406af38eae3b33.tar.xz ilt-51eb25ea0f1373ca0442b02049406af38eae3b33.zip |
Add model support for point lights
Still invokes non-instanced point light shader
Diffstat (limited to 'game/scenary')
-rw-r--r-- | game/scenary/illuminator.cpp | 20 | ||||
-rw-r--r-- | game/scenary/illuminator.h | 17 |
2 files changed, 36 insertions, 1 deletions
diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 6f51506..3de4e52 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -12,9 +12,16 @@ Illuminator::SpotLight::persist(Persistence::PersistenceStore & store) } bool +Illuminator::PointLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq); +} + +bool Illuminator::persist(Persistence::PersistenceStore & store) { return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) + && STORE_HELPER(pointLight, Persistence::Appender<decltype(pointLight)>) && STORE_HELPER(spotLight, Persistence::Appender<decltype(spotLight)>) && Asset::persist(store); } @@ -32,6 +39,14 @@ Illuminator::postLoad() std::transform(spotLight.begin(), spotLight.end(), std::back_inserter(spotLightInstances), [this](const auto & s) { return instancesSpotLight.acquire(*s); }); + VertexArrayObject {instancesPointLightVAO} + .addAttribs<PointLightVertex, &PointLightVertex::position, &PointLightVertex::colour, + &PointLightVertex::kq>(instancesPointLight.bufferName(), 0) + .addAttribs<LocationVertex, &LocationVertex::first, &LocationVertex::second>(instances.bufferName(), 1); + std::transform( + pointLight.begin(), pointLight.end(), std::back_inserter(pointLightInstances), [this](const auto & s) { + return instancesPointLight.acquire(*s); + }); } void @@ -55,6 +70,11 @@ Illuminator::lights(const SceneShader & shader) const glBindVertexArray(instancesSpotLightVAO); glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(scount), static_cast<GLsizei>(count)); } + if (const auto pcount = instancesPointLight.size()) { + shader.pointLightInst.use(); + glBindVertexArray(instancesPointLightVAO); + glDrawArraysInstanced(GL_POINTS, 0, static_cast<GLsizei>(pcount), static_cast<GLsizei>(count)); + } glBindVertexArray(0); } diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index 99b87eb..a2b287d 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -11,7 +11,7 @@ class Texture; class Illuminator : public Asset, public Renderable, public StdTypeDefs<Illuminator> { Mesh::Ptr bodyMesh; std::shared_ptr<Texture> texture; - glVertexArray instanceVAO, instancesSpotLightVAO; + glVertexArray instanceVAO, instancesSpotLightVAO, instancesPointLightVAO; public: struct SpotLightVertex { @@ -22,16 +22,29 @@ public: Angle arc; }; + struct PointLightVertex { + RelativePosition3D position; + RGB colour; + RelativeDistance kq; + }; + struct SpotLight : Persistence::Persistable, SpotLightVertex, StdTypeDefs<SpotLight> { private: friend Persistence::SelectionPtrBase<std::shared_ptr<SpotLight>>; bool persist(Persistence::PersistenceStore & store) override; }; + struct PointLight : Persistence::Persistable, PointLightVertex, StdTypeDefs<PointLight> { + private: + friend Persistence::SelectionPtrBase<std::shared_ptr<PointLight>>; + bool persist(Persistence::PersistenceStore & store) override; + }; + public: using LocationVertex = std::pair<glm::mat4, GlobalPosition3D>; mutable InstanceVertices<LocationVertex> instances; mutable InstanceVertices<SpotLightVertex> instancesSpotLight; + mutable InstanceVertices<PointLightVertex> instancesPointLight; void render(const SceneShader &) const override; void lights(const SceneShader &) const override; @@ -41,5 +54,7 @@ protected: void postLoad() override; std::vector<SpotLight::Ptr> spotLight; + std::vector<PointLight::Ptr> pointLight; std::vector<InstanceVertices<SpotLightVertex>::InstanceProxy> spotLightInstances; + std::vector<InstanceVertices<PointLightVertex>::InstanceProxy> pointLightInstances; }; |