From 51eb25ea0f1373ca0442b02049406af38eae3b33 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 12 Jan 2024 19:35:58 +0000 Subject: Add model support for point lights Still invokes non-instanced point light shader --- game/scenary/illuminator.cpp | 20 ++++++++++++++++++++ game/scenary/illuminator.h | 17 ++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'game') 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 @@ -11,10 +11,17 @@ Illuminator::SpotLight::persist(Persistence::PersistenceStore & store) && STORE_MEMBER(arc); } +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) && STORE_HELPER(spotLight, Persistence::Appender) && 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(instancesPointLight.bufferName(), 0) + .addAttribs(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(scount), static_cast(count)); } + if (const auto pcount = instancesPointLight.size()) { + shader.pointLightInst.use(); + glBindVertexArray(instancesPointLightVAO); + glDrawArraysInstanced(GL_POINTS, 0, static_cast(pcount), static_cast(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 { Mesh::Ptr bodyMesh; std::shared_ptr 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 { private: friend Persistence::SelectionPtrBase>; bool persist(Persistence::PersistenceStore & store) override; }; + struct PointLight : Persistence::Persistable, PointLightVertex, StdTypeDefs { + private: + friend Persistence::SelectionPtrBase>; + bool persist(Persistence::PersistenceStore & store) override; + }; + public: using LocationVertex = std::pair; mutable InstanceVertices instances; mutable InstanceVertices instancesSpotLight; + mutable InstanceVertices instancesPointLight; void render(const SceneShader &) const override; void lights(const SceneShader &) const override; @@ -41,5 +54,7 @@ protected: void postLoad() override; std::vector spotLight; + std::vector pointLight; std::vector::InstanceProxy> spotLightInstances; + std::vector::InstanceProxy> pointLightInstances; }; -- cgit v1.2.3