Skip to content

Commit

Permalink
#5893: Restrict LightInteractions rendering to those stages that feat…
Browse files Browse the repository at this point in the history
…ure a lighting (DBS) pass
  • Loading branch information
codereader committed Feb 19, 2022
1 parent 95d16e3 commit 6a2149a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 21 deletions.
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Expand Up @@ -222,6 +222,7 @@ add_library(radiantcore MODULE
rendersystem/backend/OpenGLShader.cpp
rendersystem/backend/OpenGLShaderPass.cpp
rendersystem/backend/DepthFillPass.cpp
rendersystem/backend/InteractionPass.cpp
rendersystem/debug/SpacePartitionRenderer.cpp
rendersystem/GLFont.cpp
rendersystem/OpenGLModule.cpp
Expand Down
3 changes: 3 additions & 0 deletions radiantcore/rendersystem/OpenGLRenderSystem.cpp
Expand Up @@ -364,6 +364,9 @@ IRenderResult::Ptr OpenGLRenderSystem::renderLitScene(RenderStateFlags globalFla
result->drawCalls += interactionList.getDrawCalls();
}

// Draw non-interaction passes (like skyboxes or blend stages)
// TODO

renderText();

finishRendering();
Expand Down
31 changes: 31 additions & 0 deletions radiantcore/rendersystem/backend/InteractionPass.cpp
@@ -0,0 +1,31 @@
#include "InteractionPass.h"

#include "GLProgramFactory.h"
#include "../OpenGLRenderSystem.h"

namespace render
{

InteractionPass::InteractionPass(OpenGLShader& owner, OpenGLRenderSystem& renderSystem) :
OpenGLShaderPass(owner)
{
// Set render flags
_glState.setRenderFlag(RENDER_BLEND);
_glState.setRenderFlag(RENDER_FILL);
_glState.setRenderFlag(RENDER_TEXTURE_2D);
_glState.setRenderFlag(RENDER_CULLFACE);
_glState.setRenderFlag(RENDER_DEPTHTEST);
_glState.setRenderFlag(RENDER_SMOOTH);
_glState.setRenderFlag(RENDER_BUMP);
_glState.setRenderFlag(RENDER_PROGRAM);

_glState.glProgram = renderSystem.getGLProgramFactory().getBuiltInProgram(ShaderProgram::Interaction);

_glState.setDepthFunc(GL_LEQUAL);
_glState.polygonOffset = 0.5f;
_glState.setSortPosition(OpenGLState::SORT_INTERACTION);
_glState.m_blend_src = GL_ONE;
_glState.m_blend_dst = GL_ONE;
}

}
20 changes: 20 additions & 0 deletions radiantcore/rendersystem/backend/InteractionPass.h
@@ -0,0 +1,20 @@
#pragma once

#include "OpenGLShaderPass.h"

namespace render
{

class OpenGLRenderSystem;

/**
* Lighting Interaction pass (Diffuse/Bump/Specular).
*/
class InteractionPass :
public OpenGLShaderPass
{
public:
InteractionPass(OpenGLShader& owner, OpenGLRenderSystem& renderSystem);
};

}
5 changes: 5 additions & 0 deletions radiantcore/rendersystem/backend/LightInteractions.cpp
Expand Up @@ -83,6 +83,11 @@ void LightInteractions::collectSurfaces(const std::set<IRenderEntityPtr>& entiti
return;
}

if (!glShader->getInteractionPass())
{
return; // This material doesn't interact with lighting
}

addObject(*object, *entity, glShader);
});
}
Expand Down
37 changes: 16 additions & 21 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -3,6 +3,7 @@
#include "GLProgramFactory.h"
#include "../OpenGLRenderSystem.h"
#include "DepthFillPass.h"
#include "InteractionPass.h"

#include "icolourscheme.h"
#include "ishaders.h"
Expand Down Expand Up @@ -325,6 +326,7 @@ void OpenGLShader::removePasses()

void OpenGLShader::clearPasses()
{
_interactionPass.reset();
_depthFillPass.reset();
_shaderPasses.clear();
}
Expand Down Expand Up @@ -365,6 +367,12 @@ OpenGLState& OpenGLShader::appendDepthFillPass()
return _depthFillPass->state();
}

OpenGLState& OpenGLShader::appendInteractionPass()
{
_interactionPass = _shaderPasses.emplace_back(std::make_shared<InteractionPass>(*this, _renderSystem));
return _interactionPass->state();
}

// Test if we can render in bump map mode
bool OpenGLShader::canUseLightingMode() const
{
Expand Down Expand Up @@ -425,7 +433,7 @@ void OpenGLShader::appendInteractionLayer(const DBSTriplet& triplet)
if (triplet.needDepthFill && triplet.diffuse)
{
// Create depth-buffer fill pass with alpha test
OpenGLState& zPass = appendDepthFillPass();
auto& zPass = appendDepthFillPass();

// Store the alpha test value
zPass.alphaThreshold = static_cast<GLfloat>(alphaTest);
Expand All @@ -436,23 +444,11 @@ void OpenGLShader::appendInteractionLayer(const DBSTriplet& triplet)
}

// Add the DBS pass
OpenGLState& dbsPass = appendDefaultPass();
auto& dbsPass = appendInteractionPass();

// Populate the textures and remember the stage reference
setGLTexturesFromTriplet(dbsPass, triplet);

// Set render flags
dbsPass.setRenderFlag(RENDER_BLEND);
dbsPass.setRenderFlag(RENDER_FILL);
dbsPass.setRenderFlag(RENDER_TEXTURE_2D);
dbsPass.setRenderFlag(RENDER_CULLFACE);
dbsPass.setRenderFlag(RENDER_DEPTHTEST);
dbsPass.setRenderFlag(RENDER_SMOOTH);
dbsPass.setRenderFlag(RENDER_BUMP);
dbsPass.setRenderFlag(RENDER_PROGRAM);

dbsPass.glProgram = _renderSystem.getGLProgramFactory().getBuiltInProgram(ShaderProgram::Interaction);

if (vcolMode != IShaderLayer::VERTEX_COLOUR_NONE)
{
// Vertex colours allowed
Expand All @@ -471,13 +467,7 @@ void OpenGLShader::appendInteractionLayer(const DBSTriplet& triplet)
if (triplet.diffuse)
{
dbsPass.setColour(triplet.diffuse->getColour());
}

dbsPass.setDepthFunc(GL_LEQUAL);
dbsPass.polygonOffset = 0.5f;
dbsPass.setSortPosition(OpenGLState::SORT_INTERACTION);
dbsPass.m_blend_src = GL_ONE;
dbsPass.m_blend_dst = GL_ONE;
}
}

void OpenGLShader::applyAlphaTestToPass(OpenGLState& pass, double alphaTest)
Expand Down Expand Up @@ -845,5 +835,10 @@ OpenGLShaderPass* OpenGLShader::getDepthFillPass() const
return _depthFillPass.get();
}

OpenGLShaderPass* OpenGLShader::getInteractionPass() const
{
return _interactionPass.get();
}

}

7 changes: 7 additions & 0 deletions radiantcore/rendersystem/backend/OpenGLShader.h
Expand Up @@ -38,6 +38,9 @@ class OpenGLShader :
// Lighting mode needs to have quick access to this pass
OpenGLShaderPassPtr _depthFillPass;

// Interaction pass used by lighting mode
OpenGLShaderPassPtr _interactionPass;

// The Material corresponding to this OpenGLShader
MaterialPtr _material;
sigc::connection _materialChanged;
Expand Down Expand Up @@ -153,6 +156,9 @@ class OpenGLShader :
// Returns the depth fill pass of this shader, or null if this shader doesn't have one
OpenGLShaderPass* getDepthFillPass() const;

// Returns the interaction pass of this shader, or null if this shader doesn't have one
OpenGLShaderPass* getInteractionPass() const;

protected:
// Start point for constructing shader passes from the shader name
virtual void construct();
Expand Down Expand Up @@ -182,6 +188,7 @@ class OpenGLShader :
void clearPasses();

OpenGLState& appendDepthFillPass();
OpenGLState& appendInteractionPass();
};

typedef std::shared_ptr<OpenGLShader> OpenGLShaderPtr;
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -632,6 +632,7 @@
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLDepthFillAlphaProgram.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLDepthFillProgram.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLProgramBase.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\InteractionPass.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\LightInteractions.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\OpenGLShader.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\OpenGLShaderPass.cpp" />
Expand Down Expand Up @@ -995,6 +996,7 @@
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLDepthFillAlphaProgram.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLDepthFillProgram.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLProgramBase.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\InteractionPass.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\LightInteractions.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\OpenGLShader.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\OpenGLShaderPass.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1126,6 +1126,9 @@
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLCubeMapProgram.cpp">
<Filter>src\rendersystem\backend\glprogram</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\rendersystem\backend\InteractionPass.cpp">
<Filter>src\rendersystem\backend</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2313,5 +2316,8 @@
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLCubeMapProgram.h">
<Filter>src\rendersystem\backend\glprogram</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\rendersystem\backend\InteractionPass.h">
<Filter>src\rendersystem\backend</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 6a2149a

Please sign in to comment.