Use the stencil and depth buffer settings from RenderState when drawing the level mesh

This commit is contained in:
Magnus Norddahl 2023-12-06 10:34:02 +01:00
commit 4a95eafc06
4 changed files with 21 additions and 19 deletions

View file

@ -631,15 +631,7 @@ int VulkanRenderDevice::GetLevelMeshPipelineID(const MeshApplyData& applyData, c
pipelineKey.DrawType = DT_Triangles;
pipelineKey.VertexFormat = levelVertexFormatIndex;
pipelineKey.RenderStyle = applyData.RenderStyle;
pipelineKey.DepthTest = true; // mDepthTest;
pipelineKey.DepthWrite = true; // mDepthTest && mDepthWrite;
pipelineKey.DepthFunc = applyData.DepthFunc;
pipelineKey.DepthClamp = false; // mDepthClamp;
pipelineKey.DepthBias = false; // !(mBias.mFactor == 0 && mBias.mUnits == 0);
pipelineKey.StencilTest = false; // mStencilTest;
pipelineKey.StencilPassOp = 0; // mStencilOp;
pipelineKey.ColorMask = 15; // mColorMask;
pipelineKey.CullMode = Cull_CW; // mCullMode;
pipelineKey.NumTextureLayers = material.mMaterial ? material.mMaterial->NumLayers() : 0;
pipelineKey.NumTextureLayers = max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it
if (applyData.SpecialEffect > EFF_NONE)

View file

@ -858,17 +858,12 @@ void VkRenderState::DrawLevelMeshDepthPass()
auto submesh = fb->GetRaytrace()->GetMesh()->StaticMesh.get();
for (LevelSubmeshDrawRange& range : submesh->DrawList)
{
VkPipelineKey pipelineKey = fb->GetLevelMeshPipelineKey(range.PipelineID);
if (pipelineKey.ShaderKey.AlphaTest) continue;
pipelineKey.ShaderKey.NoFragmentShader = true;
DrawLevelMeshRange(mCommandBuffer, pipelineKey, range.Start, range.Count);
DrawLevelMeshRange(mCommandBuffer, fb->GetLevelMeshPipelineKey(range.PipelineID), range.Start, range.Count, true);
}
/*
for (LevelSubmeshDrawRange& range : submesh->PortalList)
{
VkPipelineKey pipelineKey = fb->GetLevelMeshPipelineKey(range.PipelineID);
pipelineKey.ShaderKey.NoFragmentShader = true;
DrawLevelMeshRange(mCommandBuffer, pipelineKey, range.Start, range.Count);
DrawLevelMeshRange(mCommandBuffer, fb->GetLevelMeshPipelineKey(range.PipelineID), range.Start, range.Count, true);
}
*/
}
@ -880,7 +875,7 @@ void VkRenderState::DrawLevelMeshOpaquePass()
auto submesh = fb->GetRaytrace()->GetMesh()->StaticMesh.get();
for (LevelSubmeshDrawRange& range : submesh->DrawList)
{
DrawLevelMeshRange(mCommandBuffer, fb->GetLevelMeshPipelineKey(range.PipelineID), range.Start, range.Count);
DrawLevelMeshRange(mCommandBuffer, fb->GetLevelMeshPipelineKey(range.PipelineID), range.Start, range.Count, false);
}
}
@ -916,8 +911,21 @@ void VkRenderState::GetQueryResults(int queryStart, int queryCount, TArray<bool>
}
}
void VkRenderState::DrawLevelMeshRange(VulkanCommandBuffer* cmdbuffer, const VkPipelineKey& pipelineKey, int start, int count)
void VkRenderState::DrawLevelMeshRange(VulkanCommandBuffer* cmdbuffer, VkPipelineKey pipelineKey, int start, int count, bool noFragmentShader)
{
if (noFragmentShader && pipelineKey.ShaderKey.AlphaTest)
return;
pipelineKey.ShaderKey.NoFragmentShader = noFragmentShader;
pipelineKey.DepthTest = mDepthTest;
pipelineKey.DepthWrite = mDepthTest && mDepthWrite;
pipelineKey.DepthClamp = mDepthClamp;
pipelineKey.DepthBias = !(mBias.mFactor == 0 && mBias.mUnits == 0);
pipelineKey.StencilTest = mStencilTest;
pipelineKey.StencilPassOp = mStencilOp;
pipelineKey.ColorMask = mColorMask;
pipelineKey.CullMode = mCullMode;
PushConstants pushConstants = {};
pushConstants.uDataIndex = 0;
pushConstants.uLightIndex = -1;

View file

@ -90,7 +90,7 @@ protected:
void WaitForStreamBuffers();
void ApplyLevelMesh();
void DrawLevelMeshRange(VulkanCommandBuffer* cmdbuffer, const VkPipelineKey& pipelineKey, int start, int count);
void DrawLevelMeshRange(VulkanCommandBuffer* cmdbuffer, VkPipelineKey pipelineKey, int start, int count, bool noFragmentShader);
VulkanRenderDevice* fb = nullptr;

View file

@ -412,11 +412,12 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state)
auto& wallPortals = static_cast<DoomLevelSubmesh*>(level.levelMesh->StaticMesh.get())->WallPortals;
// draw level into depth buffer
state.SetColorMask(false);
state.SetCulling(Cull_CW);
state.DrawLevelMeshDepthPass();
// use occlusion queries on all portals in level to decide which are visible
int queryStart = state.GetNextQueryIndex();
state.SetColorMask(false);
state.SetDepthMask(false);
state.EnableTexture(false);
state.SetEffect(EFF_FOGBOUNDARY);
@ -439,6 +440,7 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state)
// draw opaque level so the GPU has something to do while we examine the query results
state.DrawLevelMeshOpaquePass();
state.SetCulling(Cull_None);
// retrieve the query results and use them to fill the portal manager with portals
state.GetQueryResults(queryStart, queryEnd - queryStart, QueryResultsBuffer);