Skip to content

Commit

Permalink
#5566: Introduce special DepthFillPass type
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 9, 2021
1 parent c580829 commit 4c3a09c
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 13 deletions.
1 change: 1 addition & 0 deletions radiantcore/CMakeLists.txt
Expand Up @@ -211,6 +211,7 @@ add_library(radiantcore MODULE
rendersystem/backend/glprogram/GLSLDepthFillAlphaProgram.cpp
rendersystem/backend/OpenGLShader.cpp
rendersystem/backend/OpenGLShaderPass.cpp
rendersystem/backend/DepthFillPass.cpp
rendersystem/debug/SpacePartitionRenderer.cpp
rendersystem/GLFont.cpp
rendersystem/OpenGLModule.cpp
Expand Down
35 changes: 35 additions & 0 deletions radiantcore/rendersystem/backend/DepthFillPass.cpp
@@ -0,0 +1,35 @@
#include "DepthFillPass.h"

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

namespace render
{

DepthFillPass::DepthFillPass(OpenGLShader& owner, OpenGLRenderSystem& renderSystem) :
OpenGLShaderPass(owner)
{
// Mask colour => we only write to the depth buffer
_glState.setRenderFlag(RENDER_MASKCOLOUR);

_glState.setRenderFlag(RENDER_FILL);
_glState.setRenderFlag(RENDER_CULLFACE);
_glState.setRenderFlag(RENDER_DEPTHTEST);
_glState.setRenderFlag(RENDER_DEPTHWRITE);
_glState.setRenderFlag(RENDER_PROGRAM);

// Our shader will discard any fragments not passing the alphatest (if active)
_glState.setRenderFlag(RENDER_ALPHATEST);

// We need texture coords and the full vertex attribute stack
_glState.setRenderFlag(RENDER_TEXTURE_2D);
_glState.setRenderFlag(RENDER_BUMP);

// ZFILL will make this pass pretty much top priority
_glState.setSortPosition(OpenGLState::SORT_ZFILL);

// Load the GLSL program tailored for this pass
_glState.glProgram = renderSystem.getGLProgramFactory().getBuiltInProgram("depthFillAlpha");
}

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

#include "OpenGLShaderPass.h"

namespace render
{

class OpenGLRenderSystem;

/**
* Special render pass filling the depth buffer.
* This is the first pass before any interaction shaders are run.
*/
class DepthFillPass :
public OpenGLShaderPass
{
public:
DepthFillPass(OpenGLShader& owner, OpenGLRenderSystem& renderSystem);
};

}
24 changes: 11 additions & 13 deletions radiantcore/rendersystem/backend/OpenGLShader.cpp
Expand Up @@ -2,6 +2,7 @@

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

#include "icolourscheme.h"
#include "ishaders.h"
Expand Down Expand Up @@ -256,6 +257,12 @@ OpenGLState& OpenGLShader::appendDefaultPass()
return state;
}

OpenGLState& OpenGLShader::appendDepthFillPass()
{
auto& pass = _shaderPasses.emplace_back(std::make_shared<DepthFillPass>(*this, _renderSystem));
return pass->state();
}

// Test if we can render in bump map mode
bool OpenGLShader::canUseLightingMode() const
{
Expand Down Expand Up @@ -316,23 +323,14 @@ void OpenGLShader::appendInteractionLayer(const DBSTriplet& triplet)
if (triplet.needDepthFill && triplet.diffuse)
{
// Create depth-buffer fill pass with alpha test
OpenGLState& zPass = appendDefaultPass();
zPass.setRenderFlag(RENDER_MASKCOLOUR);
zPass.setRenderFlag(RENDER_FILL);
zPass.setRenderFlag(RENDER_CULLFACE);
zPass.setRenderFlag(RENDER_DEPTHTEST);
zPass.setRenderFlag(RENDER_DEPTHWRITE);
zPass.setRenderFlag(RENDER_PROGRAM);
zPass.setRenderFlag(RENDER_ALPHATEST);
zPass.setRenderFlag(RENDER_TEXTURE_2D);
zPass.setRenderFlag(RENDER_BUMP);
OpenGLState& zPass = appendDepthFillPass();

// Store the alpha test value
zPass.alphaThreshold = static_cast<GLfloat>(alphaTest);

zPass.setSortPosition(OpenGLState::SORT_ZFILL);
// We need a diffuse stage to be able to performthe alpha test
zPass.stage0 = triplet.diffuse;
zPass.texture0 = getTextureOrInteractionDefault(triplet.diffuse)->getGLTexNum();

zPass.glProgram = _renderSystem.getGLProgramFactory().getBuiltInProgram("depthFillAlpha");
}

// Add the DBS pass
Expand Down
1 change: 1 addition & 0 deletions radiantcore/rendersystem/backend/OpenGLShader.h
Expand Up @@ -70,6 +70,7 @@ class OpenGLShader final :

// Add a shader pass to the end of the list, and return its state object
OpenGLState& appendDefaultPass();
OpenGLState& appendDepthFillPass();

// Test if we can render using lighting mode
bool canUseLightingMode() const;
Expand Down
1 change: 1 addition & 0 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.h
Expand Up @@ -25,6 +25,7 @@ class OpenGLShader;
*/
class OpenGLShaderPass
{
protected:
OpenGLShader& _owner;

// The state applied to this bucket
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj
Expand Up @@ -598,6 +598,7 @@
<ClCompile Include="..\..\radiantcore\log\StringLogDevice.cpp" />
<ClCompile Include="..\..\radiantcore\modulesystem\ModuleLoader.cpp" />
<ClCompile Include="..\..\radiantcore\modulesystem\ModuleRegistry.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\DepthFillPass.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\GLProgramFactory.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GenericVFPProgram.cpp" />
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLBumpProgram.cpp" />
Expand Down Expand Up @@ -928,6 +929,7 @@
<ClInclude Include="..\..\radiantcore\messagebus\MessageBus.h" />
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h" />
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleRegistry.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\DepthFillPass.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\GLProgramFactory.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GenericVFPProgram.h" />
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLBumpProgram.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc/DarkRadiantCore.vcxproj.filters
Expand Up @@ -1042,6 +1042,9 @@
<ClCompile Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLDepthFillAlphaProgram.cpp">
<Filter>src\rendersystem\backend\glprogram</Filter>
</ClCompile>
<ClCompile Include="..\..\radiantcore\rendersystem\backend\DepthFillPass.cpp">
<Filter>src\rendersystem\backend</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiantcore\modulesystem\ModuleLoader.h">
Expand Down Expand Up @@ -2127,5 +2130,8 @@
<ClInclude Include="..\..\radiantcore\rendersystem\backend\glprogram\GLSLProgramBase.h">
<Filter>src\rendersystem\backend\glprogram</Filter>
</ClInclude>
<ClInclude Include="..\..\radiantcore\rendersystem\backend\DepthFillPass.h">
<Filter>src\rendersystem\backend</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 4c3a09c

Please sign in to comment.