Skip to content

Commit

Permalink
#5584: Light Vertex rendering is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 21, 2022
1 parent f2b990b commit 840bd64
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
7 changes: 5 additions & 2 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -34,7 +34,7 @@ LightNode::LightNode(const IEntityClassPtr& eclass)
_dragPlanes(sigc::mem_fun(this, &LightNode::selectedChangedComponent)),
_renderableOctagon(*this),
_renderableLightVolume(*this),
_renderableVertices(*this, _instances),
_renderableVertices(*this, _instances, _projUseFlags),
_showLightVolumeWhenUnselected(EntitySettings::InstancePtr()->getShowAllLightRadii()),
_overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL)
{
Expand All @@ -61,7 +61,7 @@ LightNode::LightNode(const LightNode& other)
_dragPlanes(std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)),
_renderableOctagon(*this),
_renderableLightVolume(*this),
_renderableVertices(*this, _instances),
_renderableVertices(*this, _instances, _projUseFlags),
_showLightVolumeWhenUnselected(other._showLightVolumeWhenUnselected),
_overrideColKey(colours::RKEY_OVERRIDE_LIGHTCOL)
{
Expand Down Expand Up @@ -1193,6 +1193,9 @@ void LightNode::projectionChanged()
_projectionChanged = true;
m_doom3Radius.m_changed();

_renderableVertices.queueUpdate();
_renderableLightVolume.queueUpdate();

SceneChangeNotify();
}

Expand Down
47 changes: 40 additions & 7 deletions radiantcore/entity/light/Renderables.cpp
Expand Up @@ -227,6 +227,18 @@ void RenderableLightVolume::updateProjectedLightVolume()
}
}

namespace detail
{

inline void addVertex(std::vector<ArbitraryMeshVertex>& vertices, std::vector<unsigned int>& indices,
const Vector3& vertex, const Vector4& colour)
{
indices.push_back(static_cast<unsigned int>(vertices.size()));
vertices.push_back(ArbitraryMeshVertex(vertex, { 0,0,0 }, { 0,0 }, colour));
}

}

void RenderableLightVertices::updateGeometry()
{
if (!_needsUpdate) return;
Expand All @@ -243,21 +255,42 @@ void RenderableLightVertices::updateGeometry()
const auto& colourVertexSelected = settings.getLightVertexColour(LightEditVertexType::Selected);
const auto& colourVertexDeselected = settings.getLightVertexColour(LightEditVertexType::Deselected);
const auto& colourVertexInactive = settings.getLightVertexColour(LightEditVertexType::Inactive);
const auto& colourStartEndSelected = settings.getLightVertexColour(LightEditVertexType::StartEndSelected);
const auto& colourStartEndDeselected = settings.getLightVertexColour(LightEditVertexType::StartEndDeselected);

unsigned int index = 0;
// Local colour evaluation lambdas
auto getRegularVertexColour = [&](const VertexInstance& instance)->const Vector3&
{
return _mode != selection::ComponentSelectionMode::Vertex ? colourVertexInactive :
instance.isSelected() ? colourVertexSelected : colourVertexDeselected;
};

auto getStartEndVertexColour = [&](const VertexInstance& instance)->const Vector3&
{
return _mode != selection::ComponentSelectionMode::Vertex ? colourVertexInactive :
instance.isSelected() ? colourStartEndSelected : colourStartEndDeselected;
};

if (_light.isProjected())
{
// TODO
detail::addVertex(vertices, indices, _instances.target.getVertex(), getRegularVertexColour(_instances.target));
detail::addVertex(vertices, indices, _instances.right.getVertex(), getRegularVertexColour(_instances.right));
detail::addVertex(vertices, indices, _instances.up.getVertex(), getRegularVertexColour(_instances.up));

if (_useFlags.start)
{
detail::addVertex(vertices, indices, _instances.start.getVertex(), getStartEndVertexColour(_instances.start));
}

if (_useFlags.end)
{
detail::addVertex(vertices, indices, _instances.end.getVertex(), getStartEndVertexColour(_instances.end));
}
}
else
{
// Not a projected light, include just the light centre vertex
const auto& colour = _mode != selection::ComponentSelectionMode::Vertex ? colourVertexInactive :
_instances.center.isSelected() ? colourVertexSelected : colourVertexDeselected;

vertices.push_back(ArbitraryMeshVertex(_instances.center.getVertex(), { 0,0,0 }, { 0,0 }, colour));
indices.push_back(index++);
detail::addVertex(vertices, indices, _instances.center.getVertex(), getRegularVertexColour(_instances.center));
}

// Apply the local2world transform to all the vertices
Expand Down
6 changes: 5 additions & 1 deletion radiantcore/entity/light/Renderables.h
Expand Up @@ -69,14 +69,18 @@ class RenderableLightVertices :
private:
const LightNode& _light;
const LightVertexInstanceSet& _instances;
const Projected<bool>& _useFlags;

bool _needsUpdate;
selection::ComponentSelectionMode _mode;

public:
RenderableLightVertices(const LightNode& light, const LightVertexInstanceSet& instances) :
RenderableLightVertices(const LightNode& light,
const LightVertexInstanceSet& instances,
const Projected<bool>& useFlags) :
_light(light),
_instances(instances),
_useFlags(useFlags),
_needsUpdate(true),
_mode(selection::ComponentSelectionMode::Default)
{}
Expand Down

0 comments on commit 840bd64

Please sign in to comment.