Skip to content

Commit

Permalink
Skip lighting calculations in non-lit render mode
Browse files Browse the repository at this point in the history
CamRenderer::calculateLightIntersections() was being invoked even when lights
were not being rendered, which is a complete waste of CPU cycles.
  • Loading branch information
Matthew Mott committed Dec 14, 2020
1 parent 05eb111 commit a8a19be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 20 additions & 7 deletions libs/render/CamRenderer.h
Expand Up @@ -71,20 +71,32 @@ class CamRenderer: public RenderableCollector

public:

// Initialise CamRenderer with optional highlight shaders
/// Initialise CamRenderer with optional highlight shaders
CamRenderer(const VolumeTest& view, Shader* primHighlightShader = nullptr,
Shader* faceHighlightShader = nullptr)
: _view(view),
_highlightedPrimitiveShader(primHighlightShader),
_highlightedFaceShader(faceHighlightShader)
{}

// Instruct the CamRenderer to push its sorted renderables to their
// respective shaders
void submitToShaders()
/**
* \brief
* Instruct the CamRenderer to push its sorted renderables to their
* respective shaders.
*
* \param useLights
* true if lighting calculations should be performed and light lists sent
* to shaders; false if lights should be ignored (e.g. in fullbright render
* mode).
*/
void submitToShaders(bool useLights = true)
{
// Calculate intersections between lights and renderables we have received
calculateLightIntersections();
if (useLights)
{
// Calculate intersections between lights and renderables we have
// received
calculateLightIntersections();
}

// Render objects with calculated light lists
for (auto i = _litRenderables.begin(); i != _litRenderables.end(); ++i)
Expand All @@ -95,7 +107,8 @@ class CamRenderer: public RenderableCollector
{
const LitRenderable& lr = *j;
shader->addRenderable(lr.renderable, lr.local2World,
&lr.lights, lr.entity);
useLights ? &lr.lights : nullptr,
lr.entity);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion radiant/camera/CamWnd.cpp
Expand Up @@ -758,7 +758,9 @@ void CamWnd::Cam_Draw()
}

// Back end (submit to shaders and do the actual render)
renderer.submitToShaders();
renderer.submitToShaders(
getCameraSettings()->getRenderMode() == RENDER_MODE_LIGHTING
);
GlobalRenderSystem().render(allowedRenderFlags, _camera->getModelView(),
_camera->getProjection(), _view.getViewer());
}
Expand Down

0 comments on commit a8a19be

Please sign in to comment.