Skip to content

Commit

Permalink
#5945: Light crystals are now transparent with an additional outline,…
Browse files Browse the repository at this point in the history
… for easier recognition of its orientation.
  • Loading branch information
codereader committed Apr 23, 2022
1 parent 268bfd4 commit b7a17be
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
3 changes: 3 additions & 0 deletions include/irender.h
Expand Up @@ -515,6 +515,9 @@ enum class ColourShaderType

// Items drawn in both camera and ortho views
CameraAndOrthoview,

// Outline shader visible in camera and ortho views
CameraAndOrthoViewOutline,
};

class IRenderResult
Expand Down
32 changes: 26 additions & 6 deletions radiantcore/entity/light/LightNode.cpp
Expand Up @@ -24,7 +24,8 @@ LightNode::LightNode(const IEntityClassPtr& eclass)
_instances(getDoom3Radius().m_centerTransformed, _projVectors.transformed,
sigc::mem_fun(*this, &LightNode::selectedChangedComponent)),
_dragPlanes(sigc::mem_fun(this, &LightNode::selectedChangedComponent)),
_renderableOctagon(*this),
_renderableOctagon(*this, 0.5), // transparent
_renderableOctagonOutline(*this, 1.0), // opaque lines
_renderableLightVolume(*this),
_renderableVertices(*this, _instances, _projUseFlags),
_showLightVolumeWhenUnselected(EntitySettings::InstancePtr()->getShowAllLightRadii()),
Expand All @@ -43,7 +44,8 @@ LightNode::LightNode(const LightNode& other)
_instances(getDoom3Radius().m_centerTransformed, _projVectors.transformed,
sigc::mem_fun(*this, &LightNode::selectedChangedComponent)),
_dragPlanes(std::bind(&LightNode::selectedChangedComponent, this, std::placeholders::_1)),
_renderableOctagon(*this),
_renderableOctagon(*this, 0.5), // transparent
_renderableOctagonOutline(*this, 1.0), // opaque lines
_renderableLightVolume(*this),
_renderableVertices(*this, _instances, _projUseFlags),
_showLightVolumeWhenUnselected(other._showLightVolumeWhenUnselected),
Expand Down Expand Up @@ -138,6 +140,7 @@ void LightNode::transformChanged()
EntityNode::transformChanged();

_renderableOctagon.queueUpdate();
_renderableOctagonOutline.queueUpdate();
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}
Expand All @@ -157,6 +160,7 @@ void LightNode::onRemoveFromScene(scene::IMapRootNode& root)
setSelectedComponents(false, selection::ComponentSelectionMode::Face);

_renderableOctagon.clear();
_renderableOctagonOutline.clear();
_renderableLightVolume.clear();
_renderableVertices.clear();
}
Expand Down Expand Up @@ -336,9 +340,10 @@ void LightNode::onPreRender(const VolumeTest& volume)
{
EntityNode::onPreRender(volume);

// Pick the colour shader according to our settings
const auto& colourShader = _overrideColKey.get() ? getColourShader() : _colourKey.getColourShader();
_renderableOctagon.update(colourShader);
// Octagon faces (camera only)
_renderableOctagon.update(_crystalFillShader);
// Octagon outlines (for both camera and ortho)
_renderableOctagonOutline.update(_crystalOutlineShader);

bool lightIsSelected = isSelected();

Expand All @@ -350,7 +355,7 @@ void LightNode::onPreRender(const VolumeTest& volume)
updateProjection();
}

_renderableLightVolume.update(colourShader);
_renderableLightVolume.update(_crystalOutlineShader);

// Update vertices when the light is selected
if (lightIsSelected)
Expand Down Expand Up @@ -385,6 +390,7 @@ void LightNode::setRenderSystem(const RenderSystemPtr& renderSystem)

// Clear the geometry from any previous shader
_renderableOctagon.clear();
_renderableOctagonOutline.clear();
_renderableLightVolume.clear();
_renderableVertices.clear();

Expand All @@ -393,16 +399,26 @@ void LightNode::setRenderSystem(const RenderSystemPtr& renderSystem)
if (renderSystem)
{
_vertexShader = renderSystem->capture(BuiltInShaderType::BigPoint);

auto renderColour = getEntityColour();
_crystalOutlineShader = renderSystem->capture(ColourShaderType::CameraAndOrthoViewOutline, renderColour);

// Crystal fill shader is transparent
renderColour.w() = 0.3;
_crystalFillShader = renderSystem->capture(ColourShaderType::CameraTranslucent, renderColour);
_renderableVertices.queueUpdate();
}
else
{
_crystalFillShader.reset();
_crystalOutlineShader.reset();
_vertexShader.reset();
}
}

Vector4 LightNode::getEntityColour() const
{
// Pick the colour shader according to our settings
return _overrideColKey.get() ? EntityNode::getEntityColour() : Vector4(_colourKey.getColour(), 1.0);
}

Expand Down Expand Up @@ -504,6 +520,7 @@ void LightNode::_onTransformationChanged()
updateOrigin();

_renderableOctagon.queueUpdate();
_renderableOctagonOutline.queueUpdate();
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}
Expand Down Expand Up @@ -550,13 +567,15 @@ void LightNode::onVisibilityChanged(bool isVisibleNow)
if (isVisibleNow)
{
_renderableOctagon.queueUpdate();
_renderableOctagonOutline.queueUpdate();
_renderableLightVolume.queueUpdate();
_renderableVertices.queueUpdate();
}
else
{
_renderableLightVolume.clear();
_renderableOctagon.clear();
_renderableOctagonOutline.clear();
_renderableVertices.clear();
}
}
Expand Down Expand Up @@ -1239,6 +1258,7 @@ const IRenderEntity& LightNode::getLightEntity() const
void LightNode::onColourKeyChanged(const std::string& value)
{
_renderableOctagon.queueUpdate();
_renderableOctagonOutline.queueUpdate();
_renderableLightVolume.queueUpdate();
}

Expand Down
3 changes: 3 additions & 0 deletions radiantcore/entity/light/LightNode.h
Expand Up @@ -66,6 +66,8 @@ class LightNode :

LightShader m_shader;
ShaderPtr _vertexShader;
ShaderPtr _crystalFillShader;
ShaderPtr _crystalOutlineShader;

// The 8x8 box representing the light object itself
AABB _lightBox;
Expand All @@ -81,6 +83,7 @@ class LightNode :

// Renderable components of this light
RenderableLightOctagon _renderableOctagon;
RenderableLightOctagon _renderableOctagonOutline;
RenderableLightVolume _renderableLightVolume;
RenderableLightVertices _renderableVertices;

Expand Down
1 change: 1 addition & 0 deletions radiantcore/entity/light/Renderables.cpp
Expand Up @@ -36,6 +36,7 @@ void RenderableLightOctagon::updateGeometry()
Vector3 mid(Origin);

auto colour = _light.getEntityColour();
colour.w() = _alpha;

// top, bottom, tleft, tright, bright, bleft
std::vector<render::RenderVertex> vertices
Expand Down
6 changes: 4 additions & 2 deletions radiantcore/entity/light/Renderables.h
Expand Up @@ -17,11 +17,13 @@ class RenderableLightOctagon :
private:
const LightNode& _light;
bool _needsUpdate;
float _alpha;

public:
RenderableLightOctagon(const LightNode& light) :
RenderableLightOctagon(const LightNode& light, float alpha) :
_light(light),
_needsUpdate(true)
_needsUpdate(true),
_alpha(alpha)
{}

void queueUpdate()
Expand Down
10 changes: 9 additions & 1 deletion radiantcore/rendersystem/backend/ColourShader.cpp
Expand Up @@ -100,8 +100,13 @@ void ColourShader::construct()
}

case ColourShaderType::CameraAndOrthoview:
case ColourShaderType::CameraAndOrthoViewOutline:
{
state.setRenderFlag(RENDER_FILL);
if (_type == ColourShaderType::CameraAndOrthoview)
{
state.setRenderFlag(RENDER_FILL);
}

state.setRenderFlag(RENDER_LIGHTING);
state.setRenderFlag(RENDER_DEPTHTEST);
state.setRenderFlag(RENDER_CULLFACE);
Expand Down Expand Up @@ -151,6 +156,9 @@ std::string ColourShader::ConstructName(ColourShaderType type, const Colour4& co

case ColourShaderType::CameraAndOrthoview:
return fmt::format("{{{0:f} {1:f} {2:f}}}", colour[0], colour[1], colour[2]);

case ColourShaderType::CameraAndOrthoViewOutline:
return fmt::format("<{{{0:f} {1:f} {2:f}}}>", colour[0], colour[1], colour[2]);
}

throw std::runtime_error("Unknown colour shader type: " + string::to_string(static_cast<int>(type)));
Expand Down

0 comments on commit b7a17be

Please sign in to comment.