Added PipelineInfo::CullMode

Replaced GL culling functions with CullMode pipeline option.
This commit is contained in:
2022-07-04 20:49:46 -07:00
parent b801da7eb3
commit 943bbfda2f
7 changed files with 31 additions and 50 deletions

View File

@@ -160,10 +160,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
// Enable backface culling
GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE));
// Render the geometry
scene.render(commandBuffer, surface, this, m_viewport.getVisibleBounds(), m_viewport, KRNode::RENDER_PASS_DEFERRED_GBUFFER, false);
@@ -205,10 +201,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// Set source to buffers from pass 2
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 6, lightAccumulationTexture);
// Enable backface culling
GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE));
// Render the geometry
// 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);
@@ -236,11 +228,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
#endif
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
// Enable backface culling
GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE));
*/
KRRenderPass& forwardOpaquePass = surface.getForwardOpaquePass();
@@ -284,8 +271,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
// Disable backface culling
GLDEBUG(glDisable(GL_CULL_FACE));
*/
if(!m_pSkyBoxTexture && m_skyBox.length()) {
@@ -300,6 +285,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueNoDepthWrite;
info.cullMode = PipelineInfo::CullMode::kCullNone;
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());
@@ -324,13 +310,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// // Set render target
// GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
// GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
//
// // Disable backface culling
// GLDEBUG(glDisable(GL_CULL_FACE));
//
// Enable backface culling
GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE));
*/
@@ -346,9 +325,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
// Disable backface culling
GLDEBUG(glDisable(GL_CULL_FACE));
*/
// ----====---- Perform Occlusion Tests ----====----
@@ -361,13 +337,9 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GL_PUSH_GROUP_MARKER("Additive Particles");
/*
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
// Disable backface culling
GLDEBUG(glDisable(GL_CULL_FACE));
*/
// Render all flares
@@ -422,11 +394,6 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface)
GL_PUSH_GROUP_MARKER("Debug Overlays");
if(settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) {
// Enable backface culling
GLDEBUG(glCullFace(GL_BACK));
GLDEBUG(glEnable(GL_CULL_FACE));
PipelineInfo info{};
std::string shader_name("visualize_overlay");
info.shader_name = &shader_name;
@@ -831,15 +798,13 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
}
}
// Disable backface culling
GLDEBUG(glDisable(GL_CULL_FACE));
PipelineInfo info{};
std::string shader_name("debug_font");
info.shader_name = &shader_name;
info.pCamera = this;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlendNoTest;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(surface, info);
getContext().getPipelineManager()->selectPipeline(surface, *this, fontShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero());

View File

@@ -265,6 +265,7 @@ void KRLight::render(RenderInfo& ri) {
info.spot_lights = &this_spot_light;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pParticleShader, ri.viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
@@ -313,6 +314,7 @@ void KRLight::render(RenderInfo& ri) {
info.spot_lights = &this_spot_light;
info.renderPass = KRNode::RENDER_PASS_ADDITIVE_PARTICLES;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
@@ -357,6 +359,7 @@ void KRLight::render(RenderInfo& ri) {
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, info, ri.viewport, occlusion_test_sphere_matrix, Vector3::Zero(), 0.0f, Vector4::Zero())) {
@@ -409,6 +412,7 @@ void KRLight::render(RenderInfo& ri) {
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
@@ -513,10 +517,6 @@ void KRLight::renderShadowBuffers(RenderInfo& ri)
GLDEBUG(glDisable(GL_DITHER));
//GLDEBUG(glCullFace(GL_BACK)); // Enable frontface culling, which eliminates some self-cast shadow artifacts
//GLDEBUG(glEnable(GL_CULL_FACE));
GLDEBUG(glDisable(GL_CULL_FACE));
// Use shader program
PipelineInfo info{};
std::string shader_name("ShadowShader");
@@ -524,14 +524,13 @@ void KRLight::renderShadowBuffers(RenderInfo& ri)
info.pCamera = ri.camera;
info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT;
info.rasterMode = PipelineInfo::RasterMode::kOpaqueLessTest;
info.cullMode = PipelineInfo::CullMode::kCullNone; // Disabling culling, which eliminates some self-cast shadow artifacts
KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, shadowShader, m_shadowViewports[iShadow], Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero());
getScene().render(ri.commandBuffer, *ri.surface, ri.camera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);
GLDEBUG(glEnable(GL_CULL_FACE));
}
}
}

View File

@@ -99,6 +99,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) {
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
// Vector3 rim_color; Vector4 fade_color;

View File

@@ -261,7 +261,17 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
rasterizer.rasterizerDiscardEnable = VK_FALSE;
rasterizer.polygonMode = VK_POLYGON_MODE_FILL;
rasterizer.lineWidth = 1.0f;
rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
switch (info.cullMode) {
case PipelineInfo::CullMode::kCullBack:
rasterizer.cullMode = VK_CULL_MODE_BACK_BIT;
break;
case PipelineInfo::CullMode::kCullFront:
rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT;
break;
case PipelineInfo::CullMode::kCullNone:
rasterizer.cullMode = VK_CULL_MODE_NONE;
break;
}
rasterizer.frontFace = VK_FRONT_FACE_CLOCKWISE;
rasterizer.depthBiasEnable = VK_FALSE;
rasterizer.depthBiasConstantFactor = 0.0f;

View File

@@ -167,6 +167,11 @@ public:
glDisable(GL_DEPTH_TEST)
*/
};
enum class CullMode : uint32_t {
kCullBack = 0,
kCullFront,
kCullNone
};
const std::string* shader_name;
KRCamera* pCamera;
const std::vector<KRPointLight*>* point_lights;
@@ -190,6 +195,7 @@ public:
bool bAlphaTest : 1;
bool bRimColor : 1;
RasterMode rasterMode;
CullMode cullMode;
KRNode::RenderPass renderPass;
};

View File

@@ -128,6 +128,7 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
key.second.push_back(info.pCamera->settings.fog_type);
key.second.push_back(info.pCamera->settings.bEnablePerPixel);
key.second.push_back((int)info.rasterMode);
key.second.push_back((int)info.cullMode);
key.second.push_back(info.bAlphaTest);
key.second.push_back(info.bDiffuseMap);
key.second.push_back(info.bNormalMap);
@@ -166,8 +167,6 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
key.second.push_back((int)(info.pCamera->settings.vignette_falloff * 1000.0f));
key.second.push_back(info.bRimColor);
key.second.push_back(bFadeColorEnabled);
key.second.push_back((int)info.rasterMode);
KRPipeline *pPipeline = m_pipelines[key];
@@ -281,7 +280,7 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
Vector4 fade_color = info.pCamera->getFadeColor();
char szKey[256];
sprintf(szKey, "%i_%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", (int)info.rasterMode, light_directional_count, light_point_count, light_spot_count, info.bone_count, info.pCamera->settings.fog_type, info.pCamera->settings.bEnablePerPixel, info.bAlphaTest, info.bDiffuseMap, info.bNormalMap, info.bSpecMap, info.bReflectionMap, info.bReflectionCubeMap, info.pCamera->settings.bDebugPSSM, iShadowQuality, info.pCamera->settings.bEnableAmbient, info.pCamera->settings.bEnableDiffuse, info.pCamera->settings.bEnableSpecular, info.bLightMap, info.bDiffuseMapScale, info.bSpecMapScale, info.bReflectionMapScale, info.bNormalMapScale, info.bDiffuseMapOffset, info.bSpecMapOffset, info.bReflectionMapOffset, info.bNormalMapOffset, info.pCamera->settings.volumetric_environment_enable && info.pCamera->settings.volumetric_environment_downsample != 0, info.renderPass, info.shader_name->c_str(), info.pCamera->settings.dof_quality, info.pCamera->settings.bEnableFlash, info.pCamera->settings.bEnableVignette, info.pCamera->settings.dof_depth, info.pCamera->settings.dof_falloff, info.pCamera->settings.flash_depth, info.pCamera->settings.flash_falloff, info.pCamera->settings.flash_intensity, info.pCamera->settings.vignette_radius, info.pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w);
sprintf(szKey, "%i_%i_%i_%i_%i_%i_%i_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f_%f", (int)info.rasterMode, (int)info.cullMode, light_directional_count, light_point_count, light_spot_count, info.bone_count, info.pCamera->settings.fog_type, info.pCamera->settings.bEnablePerPixel, info.bAlphaTest, info.bDiffuseMap, info.bNormalMap, info.bSpecMap, info.bReflectionMap, info.bReflectionCubeMap, info.pCamera->settings.bDebugPSSM, iShadowQuality, info.pCamera->settings.bEnableAmbient, info.pCamera->settings.bEnableDiffuse, info.pCamera->settings.bEnableSpecular, info.bLightMap, info.bDiffuseMapScale, info.bSpecMapScale, info.bReflectionMapScale, info.bNormalMapScale, info.bDiffuseMapOffset, info.bSpecMapOffset, info.bReflectionMapOffset, info.bNormalMapOffset, info.pCamera->settings.volumetric_environment_enable && info.pCamera->settings.volumetric_environment_downsample != 0, info.renderPass, info.shader_name->c_str(), info.pCamera->settings.dof_quality, info.pCamera->settings.bEnableFlash, info.pCamera->settings.bEnableVignette, info.pCamera->settings.dof_depth, info.pCamera->settings.dof_falloff, info.pCamera->settings.flash_depth, info.pCamera->settings.flash_falloff, info.pCamera->settings.flash_intensity, info.pCamera->settings.vignette_radius, info.pCamera->settings.vignette_falloff, fade_color.x, fade_color.y, fade_color.z, fade_color.w);
pPipeline = new KRPipeline(getContext(), szKey, options, vertSource->getData()->getString(), fragSource->getData()->getString());

View File

@@ -151,6 +151,7 @@ void KRSprite::render(RenderInfo& ri) {
info.spot_lights = &ri.spot_lights;
info.renderPass = ri.renderPass;
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
info.cullMode = PipelineInfo::CullMode::kCullNone;
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
if(getContext().getPipelineManager()->selectPipeline(*ri.surface, *ri.camera, pShader, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, 0, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);