Skip to content

Commit

Permalink
#5584: Renderable light geometry is now respecting the node's orienta…
Browse files Browse the repository at this point in the history
…tion.

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.
  • Loading branch information
codereader committed Dec 5, 2021
1 parent 803d511 commit 6da7470
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions radiantcore/entity/EntityModule.cpp
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -623,7 +623,7 @@ void LightNode::onVisibilityChanged(bool isVisibleNow)

void LightNode::onEntitySettingsChanged()
{
_renderableOctagon.queueUpdate();
// TODO
}

} // namespace entity
20 changes: 14 additions & 6 deletions radiantcore/entity/light/Renderables.h
Expand Up @@ -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)
{}

Expand All @@ -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 <points>
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<ArbitraryMeshVertex> vertices
Expand All @@ -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<unsigned int> Indices
{
Expand Down

0 comments on commit 6da7470

Please sign in to comment.