From 6da7470f4e5c020e39b72bc36eb20c8d37981338 Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 5 Dec 2021 06:59:07 +0100 Subject: [PATCH] #5584: Renderable light geometry is now respecting the node's orientation. The transformation is baked into the vertices on transformation change, which the cost of being able to submit all geometry of the same shader in one single draw call. --- radiantcore/entity/EntityModule.cpp | 2 ++ radiantcore/entity/light/LightNode.cpp | 6 +++--- radiantcore/entity/light/Renderables.h | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/radiantcore/entity/EntityModule.cpp b/radiantcore/entity/EntityModule.cpp index 690514fd1c..ece80064a6 100644 --- a/radiantcore/entity/EntityModule.cpp +++ b/radiantcore/entity/EntityModule.cpp @@ -312,6 +312,8 @@ void Doom3EntityModule::shutdownModule() void Doom3EntityModule::onEntitySettingsChanged() { + if (!GlobalMapModule().getRoot()) return; + // Actively notify all LightNodes (only those for now) about the settings change GlobalMapModule().getRoot()->foreachNode([](const scene::INodePtr& node) { diff --git a/radiantcore/entity/light/LightNode.cpp b/radiantcore/entity/light/LightNode.cpp index 544e97c3cc..401ecbb4cd 100644 --- a/radiantcore/entity/light/LightNode.cpp +++ b/radiantcore/entity/light/LightNode.cpp @@ -25,7 +25,7 @@ LightNode::LightNode(const IEntityClassPtr& eclass) : _lightStartInstance(_light.startTransformed(), std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)), _lightEndInstance(_light.endTransformed(), std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)), _dragPlanes(std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)), - _renderableOctagon(_light._originTransformed), + _renderableOctagon(*this), _renderableRadius(_light._lightBox.origin), _renderableFrustum(_light._lightBox.origin, _light._lightStartTransformed, _light._frustum), _overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL) @@ -47,7 +47,7 @@ LightNode::LightNode(const LightNode& other) : _lightStartInstance(_light.startTransformed(), std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)), _lightEndInstance(_light.endTransformed(), std::bind(&LightNode::selectedChangedComponent, this,std::placeholders:: _1)), _dragPlanes(std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)), - _renderableOctagon(_light._originTransformed), + _renderableOctagon(*this), _renderableRadius(_light._lightBox.origin), _renderableFrustum(_light._lightBox.origin, _light._lightStartTransformed, _light._frustum), _overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL) @@ -623,7 +623,7 @@ void LightNode::onVisibilityChanged(bool isVisibleNow) void LightNode::onEntitySettingsChanged() { - _renderableOctagon.queueUpdate(); + // TODO } } // namespace entity diff --git a/radiantcore/entity/light/Renderables.h b/radiantcore/entity/light/Renderables.h index 8ea5e4a685..417a3e8943 100644 --- a/radiantcore/entity/light/Renderables.h +++ b/radiantcore/entity/light/Renderables.h @@ -40,12 +40,12 @@ class RenderableLightOctagon : public render::RenderableGeometry { private: - const Vector3& _origin; + const scene::INode& _owner; bool _needsUpdate; public: - RenderableLightOctagon(const Vector3& origin) : - _origin(origin), + RenderableLightOctagon(const scene::INode& owner) : + _owner(owner), _needsUpdate(true) {} @@ -62,12 +62,13 @@ class RenderableLightOctagon : _needsUpdate = false; // Generate the indexed vertex data + static Vector3 Origin(0, 0, 0); static Vector3 Extents(8, 8, 8); // Calculate the light vertices of this bounding box and store them into - Vector3 max(_origin + Extents); - Vector3 min(_origin - Extents); - Vector3 mid(_origin); + Vector3 max(Origin + Extents); + Vector3 min(Origin - Extents); + Vector3 mid(Origin); // top, bottom, tleft, tright, bright, bleft std::vector vertices @@ -80,6 +81,13 @@ class RenderableLightOctagon : ArbitraryMeshVertex({ min[0], min[1], mid[2] }, {1,0,0}, {0,0}), }; + // Orient the points using the transform + const auto& orientation = _owner.localToWorld(); + for (auto& vertex : vertices) + { + vertex.vertex = orientation * vertex.vertex; + } + // Indices are always the same, therefore constant static const std::vector Indices {