Added PipelineInfo::RasterMode::kOpaqueNoDepthWrite

Refactored additional GL depth and blending state to use RasterMode
This commit is contained in:
2022-07-03 21:52:54 -07:00
parent 44be42a4a8
commit 2e371386cf
3 changed files with 23 additions and 60 deletions

View File

@@ -157,9 +157,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments)); GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
#endif #endif
// Enable z-buffer write
GLDEBUG(glDepthMask(GL_TRUE));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
@@ -167,18 +164,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glCullFace(GL_BACK)); GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE)); GLDEBUG(glEnable(GL_CULL_FACE));
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
// Disable alpha blending
GLDEBUG(glDisable(GL_BLEND));
// Render the geometry // Render the geometry
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false); scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false);
GL_POP_GROUP_MARKER; GL_POP_GROUP_MARKER;
@@ -194,18 +182,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f)); GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT)); GLDEBUG(glClear(GL_COLOR_BUFFER_BIT));
// Enable additive blending
GLDEBUG(glEnable(GL_BLEND));
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
// Disable z-buffer write
GLDEBUG(glDepthMask(GL_FALSE));
// Set source to buffers from pass 1 // Set source to buffers from pass 1
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 6, compositeColorTexture); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 6, compositeColorTexture);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 7, compositeDepthTexture); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 7, compositeDepthTexture);
// Render the geometry // Render the geometry
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_LIGHTS, false); scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_LIGHTS, false);
@@ -219,9 +199,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer)); GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0)); GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
// Disable alpha blending
GLDEBUG(glDisable(GL_BLEND));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT)); GLDEBUG(glClear(GL_COLOR_BUFFER_BIT));
@@ -232,14 +209,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glCullFace(GL_BACK)); GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE)); GLDEBUG(glEnable(GL_CULL_FACE));
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
// Enable z-buffer write
GLDEBUG(glDepthMask(GL_TRUE));
// Render the geometry // Render the geometry
// TODO: At this point, we only want to render octree nodes that produced fragments during the 1st pass into the GBuffer // TODO: At this point, we only want to render octree nodes that produced fragments during the 1st pass into the GBuffer
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_OPAQUE, false); scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_OPAQUE, false);
@@ -251,23 +220,16 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GL_POP_GROUP_MARKER; GL_POP_GROUP_MARKER;
} else { } else {
// ----====---- Opaque Geometry, Forward Rendering ----====---- // ----====---- Opaque Geometry, Forward Rendering ----====----
/*
GL_PUSH_GROUP_MARKER("Forward Rendering - Opaque"); GL_PUSH_GROUP_MARKER("Forward Rendering - Opaque");
/*
// Set render target // Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer)); GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0)); GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
GLDEBUG(glViewport(0, 0, (GLsizei)(m_viewport.getSize().x * m_downsample.x), (GLsizei)(m_viewport.getSize().y * m_downsample.y))); GLDEBUG(glViewport(0, 0, (GLsizei)(m_viewport.getSize().x * m_downsample.x), (GLsizei)(m_viewport.getSize().y * m_downsample.y)));
// Disable alpha blending
GLDEBUG(glDisable(GL_BLEND));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 1.0f));
// Enable z-buffer write
GLDEBUG(glDepthMask(GL_TRUE));
#if GL_EXT_discard_framebuffer #if GL_EXT_discard_framebuffer
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0}; GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0};
@@ -279,13 +241,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glCullFace(GL_BACK)); GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE)); GLDEBUG(glEnable(GL_CULL_FACE));
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
*/ */
KRRenderPass& forwardOpaquePass = surface.getForwardOpaquePass(); KRRenderPass& forwardOpaquePass = surface.getForwardOpaquePass();
@@ -294,6 +249,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// Render the geometry // Render the geometry
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false); scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_FORWARD_OPAQUE, false);
GL_POP_GROUP_MARKER;
// ---------- Start: Vulkan Debug Code ---------- // ---------- Start: Vulkan Debug Code ----------
KRMeshManager::KRVBOData& testVertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; KRMeshManager::KRVBOData& testVertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES;
@@ -319,9 +275,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// ----====---- Sky Box ----====---- // ----====---- Sky Box ----====----
GL_PUSH_GROUP_MARKER("Sky Box");
// TODO - Vulkan refactoring... // TODO - Vulkan refactoring...
/* /*
GL_PUSH_GROUP_MARKER("Sky Box");
// Set render target // Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer)); GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
@@ -329,14 +285,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// Disable backface culling // Disable backface culling
GLDEBUG(glDisable(GL_CULL_FACE)); GLDEBUG(glDisable(GL_CULL_FACE));
// Disable z-buffer write
GLDEBUG(glDepthMask(GL_FALSE));
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
*/ */
if(!m_pSkyBoxTexture && m_skyBox.length()) { if(!m_pSkyBoxTexture && m_skyBox.length()) {
@@ -350,6 +298,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
info.shader_name = &shader_name; info.shader_name = &shader_name;
info.pCamera = this; info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE; info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueNoDepthWrite;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(surface, info); KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(surface, info);
getContext().getPipelineManager()->selectPipeline(surface, *this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero()); getContext().getPipelineManager()->selectPipeline(surface, *this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero());
@@ -361,10 +310,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
} }
// TODO - Vulkan refactoring...
/*
GL_POP_GROUP_MARKER; GL_POP_GROUP_MARKER;
*/
// ----====---- Transparent Geometry, Forward Rendering ----====---- // ----====---- Transparent Geometry, Forward Rendering ----====----

View File

@@ -283,6 +283,7 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
switch (info.rasterMode) { switch (info.rasterMode) {
case PipelineInfo::RasterMode::kOpaque: case PipelineInfo::RasterMode::kOpaque:
case PipelineInfo::RasterMode::kOpaqueLessTest: case PipelineInfo::RasterMode::kOpaqueLessTest:
case PipelineInfo::RasterMode::kOpaqueNoDepthWrite:
colorBlendAttachment.blendEnable = VK_FALSE; colorBlendAttachment.blendEnable = VK_FALSE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE; colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO; colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ZERO;
@@ -337,6 +338,7 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
depthStencil.depthTestEnable = VK_TRUE; depthStencil.depthTestEnable = VK_TRUE;
depthStencil.depthWriteEnable = VK_TRUE; depthStencil.depthWriteEnable = VK_TRUE;
break; break;
case PipelineInfo::RasterMode::kOpaqueNoDepthWrite:
case PipelineInfo::RasterMode::kAlphaBlend: case PipelineInfo::RasterMode::kAlphaBlend:
case PipelineInfo::RasterMode::kAdditive: case PipelineInfo::RasterMode::kAdditive:
depthStencil.depthTestEnable = VK_TRUE; depthStencil.depthTestEnable = VK_TRUE;

View File

@@ -63,6 +63,21 @@ public:
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0); glDepthRangef(0.0, 1.0);
*/ */
kOpaqueNoDepthWrite,
/*
kOpaque is equivalent to:
// Disable blending
glDisable(GL_BLEND));
// Disable z-buffer write
glDepthMask(GL_FALSE);
// Enable z-buffer test
glEnable(GL_DEPTH_TEST))
glDepthFunc(GL_LEQUAL);
glDepthRangef(0.0, 1.0);
*/
kOpaqueLessTest, kOpaqueLessTest,
/* /*
kOpaqueLessTest is equivalent to: kOpaqueLessTest is equivalent to: