Skip to content

Commit

Permalink
#5893: Cut off redundant calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 28, 2022
1 parent 58e1122 commit 71b3f66
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
7 changes: 6 additions & 1 deletion radiantcore/rendersystem/backend/LightInteractions.cpp
Expand Up @@ -120,6 +120,11 @@ void LightInteractions::render(OpenGLState& state, RenderStateFlags globalFlagsM

shader->foreachPassWithoutDepthPass([&](OpenGLShaderPass& pass)
{
if (!pass.stateIsActive())
{
return;
}

// Reset the texture matrix
glMatrixMode(GL_TEXTURE);
glLoadMatrixd(Matrix4::getIdentity());
Expand All @@ -135,7 +140,7 @@ void LightInteractions::render(OpenGLState& state, RenderStateFlags globalFlagsM
{
if (state.glProgram)
{
OpenGLShaderPass::setUpLightingCalculation(state, &_light,
OpenGLShaderPass::setUpLightingCalculation(state, &_light, _worldToLight,
view.getViewer(), surface.get().getSurfaceTransform(), renderTime, state.isColourInverted());
}

Expand Down
2 changes: 2 additions & 0 deletions radiantcore/rendersystem/backend/LightInteractions.h
Expand Up @@ -22,6 +22,7 @@ class LightInteractions
{
private:
RendererLight& _light;
Matrix4 _worldToLight;

// A flat list of surfaces
using SurfaceList = std::vector<std::reference_wrapper<IRenderableSurface>>;
Expand All @@ -37,6 +38,7 @@ class LightInteractions
public:
LightInteractions(RendererLight& light) :
_light(light),
_worldToLight(light.getLightTextureTransformation()),
_drawCalls(0)
{}

Expand Down
9 changes: 4 additions & 5 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -631,6 +631,7 @@ bool OpenGLShaderPass::stateIsActive()
// Setup lighting
void OpenGLShaderPass::setUpLightingCalculation(OpenGLState& current,
const RendererLight* light,
const Matrix4& worldToLight,
const Vector3& viewer,
const Matrix4& objTransform,
std::size_t time,
Expand Down Expand Up @@ -671,12 +672,9 @@ void OpenGLShaderPass::setUpLightingCalculation(OpenGLState& current,
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

// Get the world-space to light-space transformation matrix
Matrix4 world2light = light->getLightTextureTransformation();

// Set the GL program parameters
GLProgram::Params parms(
light->getLightOrigin(), layer->getColour(), world2light
light->getLightOrigin(), layer->getColour(), worldToLight
);
parms.isAmbientLight = lightMat->isAmbientLight();
parms.invertVertexColour = invertVertexColour;
Expand Down Expand Up @@ -725,7 +723,8 @@ void OpenGLShaderPass::renderAllContained(const Renderables& renderables,
const RendererLight* light = r.light;
if (current.glProgram && light)
{
setUpLightingCalculation(current, light, viewer, *transform, time, _glState.isColourInverted());
setUpLightingCalculation(current, light, light->getLightTextureTransformation(),
viewer, *transform, time, _glState.isColourInverted());
}

// Render the renderable
Expand Down
9 changes: 5 additions & 4 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.h
Expand Up @@ -72,10 +72,7 @@ class OpenGLShaderPass

protected:

// Returns true if the stage associated to this pass is active and should be rendered
bool stateIsActive();

void setupTextureMatrix(GLenum textureUnit, const IShaderLayer::Ptr& stage);
void setupTextureMatrix(GLenum textureUnit, const IShaderLayer::Ptr& stage);

// Render all of the given TransformedRenderables
void renderAllContained(const Renderables& renderables,
Expand Down Expand Up @@ -113,6 +110,9 @@ class OpenGLShaderPass
_owner(owner)
{}

// Returns true if the stage associated to this pass is active and should be rendered
bool stateIsActive();

/**
* \brief
* Add a renderable to this shader pass the given object transform matrix
Expand Down Expand Up @@ -190,6 +190,7 @@ class OpenGLShaderPass
// Set up lighting calculation
static void setUpLightingCalculation(OpenGLState& current,
const RendererLight* light,
const Matrix4& worldToLight,
const Vector3& viewer,
const Matrix4& objTransform,
std::size_t time,
Expand Down

0 comments on commit 71b3f66

Please sign in to comment.