Skip to content

Commit

Permalink
#5364: 'Override light colour' now working
Browse files Browse the repository at this point in the history
If the checkbox is set, the LightNode::renderLightVolume() method uses the
EntityNode::_wireShader shader instead of the shader exposed by ColourKey
(which changes with the '_color' spawnarg).
  • Loading branch information
Matthew Mott committed Dec 22, 2020
1 parent 10bbba2 commit deaea8a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 44 deletions.
7 changes: 7 additions & 0 deletions include/icolourscheme.h
Expand Up @@ -7,6 +7,13 @@
namespace colours
{

/**
* Registry key set when light volumes should be rendered in a single colour
* set by the colourscheme, rather than the colour contained in their _color
* key.
*/
constexpr const char* RKEY_OVERRIDE_LIGHTCOL = "user/ui/colour/overrideLightColour";

class IColourItem
{
public:
Expand Down
14 changes: 2 additions & 12 deletions radiant/uimanager/colourscheme/ColourSchemeEditor.cpp
Expand Up @@ -10,6 +10,7 @@
#include "wxutil/dialog/MessageBox.h"
#include "wxutil/TreeView.h"
#include "registry/registry.h"
#include "registry/Widgets.h"

#include <wx/panel.h>
#include <wx/sizer.h>
Expand All @@ -24,8 +25,6 @@ namespace ui
namespace
{
const char* const EDITOR_WINDOW_TITLE = N_("Edit Colour Schemes");

constexpr const char* RKEY_OVERRIDE_LIGHTCOL = "user/ui/colour/overrideLightColour";
}

ColourSchemeEditor::ColourSchemeEditor() :
Expand Down Expand Up @@ -84,16 +83,7 @@ void ColourSchemeEditor::addOptionsPanel(wxBoxSizer& vbox)
wxCheckBox* overrideLightsCB = new wxCheckBox(
this, wxID_ANY, _("Override light volume colour")
);
overrideLightsCB->SetValue(
registry::getValue(RKEY_OVERRIDE_LIGHTCOL, false)
);
overrideLightsCB->Bind(
wxEVT_CHECKBOX,
[this](wxCommandEvent& ev)
{
registry::setValue(RKEY_OVERRIDE_LIGHTCOL, ev.IsChecked());
}
);
registry::bindWidget(overrideLightsCB, colours::RKEY_OVERRIDE_LIGHTCOL);

vbox.Add(overrideLightsCB, 0, wxEXPAND | wxTOP, 6);
}
Expand Down
9 changes: 5 additions & 4 deletions radiantcore/entity/ColourKey.h
Expand Up @@ -56,10 +56,11 @@ class ColourKey :
captureShader();
}

const ShaderPtr& getWireShader() const
{
return _wireShader;
}
/// Return a non-owning (possibly null) pointer to the Shader
Shader* getWireShader() const
{
return _wireShader.get();
}

private:

Expand Down
10 changes: 0 additions & 10 deletions radiantcore/entity/EntityNode.cpp
Expand Up @@ -308,16 +308,6 @@ std::size_t EntityNode::getHighlightFlags()
return isGroupMember() ? (Highlight::Selected | Highlight::GroupMember) : Highlight::Selected;
}

const Vector3& EntityNode::getColour() const
{
return _colourKey.getColour();
}

const ShaderPtr& EntityNode::getColourShader() const
{
return _colourKey.getWireShader();
}

ModelKey& EntityNode::getModelKey()
{
return _modelKey;
Expand Down
4 changes: 0 additions & 4 deletions radiantcore/entity/EntityNode.h
Expand Up @@ -130,10 +130,6 @@ class EntityNode :
void addKeyObserver(const std::string& key, KeyObserver& observer);
void removeKeyObserver(const std::string& key, KeyObserver& observer);

// Returns the colour as defined in the _color spawnarg
const Vector3& getColour() const;
const ShaderPtr& getColourShader() const;

ModelKey& getModelKey(); // needed by the Doom3Group class, could be a fixme
const ModelKey& getModelKey() const;

Expand Down
33 changes: 20 additions & 13 deletions radiantcore/entity/light/LightNode.cpp
@@ -1,9 +1,12 @@
#include "LightNode.h"

#include "itextstream.h"
#include "icolourscheme.h"
#include "../EntitySettings.h"
#include <functional>

#include "registry/CachedKey.h"

namespace entity {

// --------- LightNode implementation ------------------------------------
Expand Down Expand Up @@ -283,32 +286,36 @@ void LightNode::renderSolid(RenderableCollector& collector, const VolumeTest& vo

// Re-use the same method as in wireframe rendering for the moment
const bool lightIsSelected = isSelected();
renderLightVolume(
collector, volume, localToWorld(), lightIsSelected
);
renderLightVolume(collector, localToWorld(), lightIsSelected);

renderInactiveComponents(collector, volume, lightIsSelected);
}

void LightNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
EntityNode::renderWireframe(collector, volume);
EntityNode::renderWireframe(collector, volume);

const bool lightIsSelected = isSelected();
renderLightVolume(
collector, volume, localToWorld(), lightIsSelected
);
const bool lightIsSelected = isSelected();
renderLightVolume(collector, localToWorld(), lightIsSelected);

renderInactiveComponents(collector, volume, lightIsSelected);
renderInactiveComponents(collector, volume, lightIsSelected);
}

void LightNode::renderLightVolume(RenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld,
bool selected) const
{
// Obtain the appropriate Shader for the light volume colour
static registry::CachedKey<bool> _overrideColKey(
colours::RKEY_OVERRIDE_LIGHTCOL
);
Shader* colourShader = _overrideColKey.get() ? EntityNode::_wireShader.get()
: _colourKey.getWireShader();
if (!colourShader)
return;

// Main render, submit the diamond that represents the light entity
collector.addRenderable(*getColourShader(), *this, localToWorld);
collector.addRenderable(*colourShader, *this, localToWorld);

// Render bounding box if selected or the showAllLighRadii flag is set
if (selected || EntitySettings::InstancePtr()->getShowAllLightRadii())
Expand All @@ -318,12 +325,12 @@ void LightNode::renderLightVolume(RenderableCollector& collector,
// greebo: This is not much of an performance impact as the
// projection gets only recalculated when it has actually changed.
_light.updateProjection();
collector.addRenderable(*getColourShader(), _renderableFrustum, localToWorld);
collector.addRenderable(*colourShader, _renderableFrustum, localToWorld);
}
else
{
updateRenderableRadius();
collector.addRenderable(*getColourShader(), _renderableRadius, localToWorld);
collector.addRenderable(*colourShader, _renderableRadius, localToWorld);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion radiantcore/entity/light/LightNode.h
Expand Up @@ -144,7 +144,6 @@ class LightNode :

// Render the light volume including bounds and origin
void renderLightVolume(RenderableCollector& collector,
const VolumeTest& volume,
const Matrix4& localToWorld, bool selected) const;

// Update the bounds of the renderable radius box
Expand Down

0 comments on commit deaea8a

Please sign in to comment.