From 52c8ec2776932407a74bf0e0cb790dec76a37cf2 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Tue, 5 Apr 2022 22:25:19 -0700 Subject: [PATCH] Reduced boilerplate needed to select and bind a KRPipeline --- kraken/KRAmbientZone.cpp | 2 +- kraken/KRAudioSource.cpp | 2 +- kraken/KRBone.cpp | 2 +- kraken/KRCamera.cpp | 32 ++------- kraken/KRCollider.cpp | 2 +- kraken/KRDirectionalLight.cpp | 7 +- kraken/KRLight.cpp | 14 ++-- kraken/KRMaterial.cpp | 2 +- kraken/KRParticleSystemNewtonian.cpp | 2 +- kraken/KRPipeline.cpp | 104 ++++++++++++++------------- kraken/KRPipeline.h | 2 +- kraken/KRPipelineManager.cpp | 17 +++-- kraken/KRPipelineManager.h | 2 +- kraken/KRPointLight.cpp | 6 +- kraken/KRReverbZone.cpp | 2 +- kraken/KRSprite.cpp | 2 +- 16 files changed, 85 insertions(+), 115 deletions(-) diff --git a/kraken/KRAmbientZone.cpp b/kraken/KRAmbientZone.cpp index 83c33b4..600b8b7 100755 --- a/kraken/KRAmbientZone.cpp +++ b/kraken/KRAmbientZone.cpp @@ -140,7 +140,7 @@ void KRAmbientZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pPipeline, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pPipeline, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRAudioSource.cpp b/kraken/KRAudioSource.cpp index 3ba0d3a..35aa81e 100755 --- a/kraken/KRAudioSource.cpp +++ b/kraken/KRAudioSource.cpp @@ -207,7 +207,7 @@ void KRAudioSource::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, st KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRBone.cpp b/kraken/KRBone.cpp index 5764a67..e68e8ae 100755 --- a/kraken/KRBone.cpp +++ b/kraken/KRBone.cpp @@ -102,7 +102,7 @@ void KRBone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vect KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { std::vector sphereModels = getContext().getMeshManager()->getModel("__sphere"); if(sphereModels.size()) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { diff --git a/kraken/KRCamera.cpp b/kraken/KRCamera.cpp index 92e0aaf..6df85cc 100755 --- a/kraken/KRCamera.cpp +++ b/kraken/KRCamera.cpp @@ -340,19 +340,13 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) if(m_pSkyBoxTexture) { std::string shader_name("sky_box"); - std::vector no_point_lights; - std::vector no_directional_lights; - std::vector no_spot_lights; KRPipelineManager::PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = this; - info.point_lights = &no_point_lights; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = KRNode::RENDER_PASS_FORWARD_OPAQUE; KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(info); - getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), no_point_lights, no_directional_lights, no_spot_lights, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getPipelineManager()->selectPipeline(*this, pPipeline, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, Vector4::Zero()); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); @@ -539,16 +533,10 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE)); - std::vector no_point_lights; - std::vector no_directional_lights; - std::vector no_spot_lights; KRPipelineManager::PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = this; - info.point_lights = &no_point_lights; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT; KRPipeline *pVisShader = getContext().getPipelineManager()->getPipeline(info); @@ -557,7 +545,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface) Matrix4 matModel = Matrix4(); matModel.scale((*itr).first.size() * 0.5f); matModel.translate((*itr).first.center()); - if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*this, pVisShader, m_viewport, matModel, nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero())) { GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); } } @@ -782,22 +770,16 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer) GLDEBUG(glViewport(0, 0, (GLsizei)m_viewport.getSize().x, (GLsizei)m_viewport.getSize().y)); GLDEBUG(glDisable(GL_DEPTH_TEST)); - std::vector no_point_lights; - std::vector no_directional_lights; - std::vector no_spot_lights; KRPipelineManager::PipelineInfo info{}; std::string shader_name("PostShader"); info.shader_name = &shader_name; info.pCamera = this; - info.point_lights = &no_point_lights; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT; KRPipeline *postShader = m_pContext->getPipelineManager()->getPipeline(info); Vector3 rim_color; - getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color); + getContext().getPipelineManager()->selectPipeline(*this, postShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 1, compositeColorTexture); @@ -979,19 +961,13 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer) // Enable alpha blending GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); - std::vector no_point_lights; - std::vector no_directional_lights; - std::vector no_spot_lights; KRPipelineManager::PipelineInfo info{}; std::string shader_name("debug_font"); info.shader_name = &shader_name; info.pCamera = this; - info.point_lights = &no_point_lights; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT; KRPipeline *fontShader = m_pContext->getPipelineManager()->getPipeline(info); - getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getPipelineManager()->selectPipeline(*this, fontShader, m_viewport, Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, Vector4::Zero()); m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI); diff --git a/kraken/KRCollider.cpp b/kraken/KRCollider.cpp index ee18d4e..8b86c4a 100755 --- a/kraken/KRCollider.cpp +++ b/kraken/KRCollider.cpp @@ -215,7 +215,7 @@ void KRCollider::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std:: KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRDirectionalLight.cpp b/kraken/KRDirectionalLight.cpp index f67570e..ace67cc 100755 --- a/kraken/KRDirectionalLight.cpp +++ b/kraken/KRDirectionalLight.cpp @@ -130,9 +130,6 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer std::vector this_light; this_light.push_back(this); - std::vector no_point_lights; - std::vector no_spot_lights; - Matrix4 matModelViewInverseTranspose = viewport.getViewMatrix() * getModelMatrix(); matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.invert(); @@ -145,13 +142,11 @@ void KRDirectionalLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamer std::string shader_name("light_directional"); info.shader_name = &shader_name; info.pCamera = pCamera; - info.point_lights = &no_point_lights; info.directional_lights = &this_light; - info.spot_lights = &no_spot_lights; info.renderPass = renderPass; KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), no_point_lights, this_light, no_spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), nullptr, &this_light, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space); pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); diff --git a/kraken/KRLight.cpp b/kraken/KRLight.cpp index c14cf38..d107cd6 100755 --- a/kraken/KRLight.cpp +++ b/kraken/KRLight.cpp @@ -268,7 +268,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec info.renderPass = renderPass; KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_PARTICLE_ORIGIN, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero())); @@ -316,7 +316,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec KRPipeline *pFogShader = m_pContext->getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pFogShader, viewport, Matrix4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pFogShader, viewport, Matrix4(), &this_point_light, &this_directional_light, &this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, Vector4::Zero())) { int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5; float slice_near = -pCamera->settings.getPerspectiveNearZ(); @@ -413,7 +413,7 @@ void KRLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::vec info.renderPass = renderPass; KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE); @@ -528,20 +528,14 @@ void KRLight::renderShadowBuffers(VkCommandBuffer& commandBuffer, KRCamera *pCam GLDEBUG(glDisable(GL_BLEND)); // Use shader program - std::vector no_point_lights; - std::vector no_directional_lights; - std::vector no_spot_lights; KRPipelineManager::PipelineInfo info{}; std::string shader_name("ShadowShader"); info.shader_name = &shader_name; info.pCamera = pCamera; - info.point_lights = &no_point_lights; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = KRNode::RENDER_PASS_FORWARD_TRANSPARENT; KRPipeline *shadowShader = m_pContext->getPipelineManager()->getPipeline(info); - getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), std::vector(), std::vector(), std::vector(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero()); + getContext().getPipelineManager()->selectPipeline(*pCamera, shadowShader, m_shadowViewports[iShadow], Matrix4(), nullptr, nullptr, nullptr, 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, Vector4::Zero()); getScene().render(commandBuffer, pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true); diff --git a/kraken/KRMaterial.cpp b/kraken/KRMaterial.cpp index d6ac464..dba3400 100755 --- a/kraken/KRMaterial.cpp +++ b/kraken/KRMaterial.cpp @@ -349,7 +349,7 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector &point_ligh KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); Vector4 fade_color; - if(!getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) { + if(!getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, matModel, &point_lights, &directional_lights, &spot_lights, 0, renderPass, rim_color, rim_power, fade_color)) { return false; } diff --git a/kraken/KRParticleSystemNewtonian.cpp b/kraken/KRParticleSystemNewtonian.cpp index 2fa35e5..9b8752f 100755 --- a/kraken/KRParticleSystemNewtonian.cpp +++ b/kraken/KRParticleSystemNewtonian.cpp @@ -107,7 +107,7 @@ void KRParticleSystemNewtonian::render(VkCommandBuffer& commandBuffer, KRCamera KRPipeline *pParticleShader = m_pContext->getPipelineManager()->getPipeline(info); // Vector3 rim_color; Vector4 fade_color; - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pParticleShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pParticleShader->setUniform(KRPipeline::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f); KRDataBlock index_data; diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index 8c24a62..a3d9616 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -584,7 +584,7 @@ void KRPipeline::bind(VkCommandBuffer& commandBuffer) vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); } -bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) { +bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector *spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) { if(m_iProgram == 0) { return false; } @@ -606,58 +606,60 @@ bool KRPipeline::bind(KRCamera &camera, const KRViewport &viewport, const Matrix if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) { - for(std::vector::const_iterator light_itr=directional_lights.begin(); light_itr != directional_lights.end(); light_itr++) { - KRDirectionalLight *directional_light = (*light_itr); - if(light_directional_count == 0) { - int cShadowBuffers = directional_light->getShadowBufferCount(); - if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1 && cShadowBuffers > 0) { - if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 3, directional_light->getShadowTextures()[0])) { - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - } - - m_pContext->getTextureManager()->_setWrapModeS(3, GL_CLAMP_TO_EDGE); - m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE); - } - - if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) { - if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 4, directional_light->getShadowTextures()[1])) { - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - } - m_pContext->getTextureManager()->_setWrapModeS(4, GL_CLAMP_TO_EDGE); - m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE); - } - - if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) { - if(m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 5, directional_light->getShadowTextures()[2])) { - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - } - m_pContext->getTextureManager()->_setWrapModeS(5, GL_CLAMP_TO_EDGE); - m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE); - } - - Matrix4 matBias; - matBias.translate(1.0, 1.0, 1.0); - matBias.scale(0.5); - for(int iShadow=0; iShadow < cShadowBuffers; iShadow++) { - setUniform(KRENGINE_UNIFORM_SHADOWMVP1 + iShadow, matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias); - } - - if(m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) { - Matrix4 inverseModelMatrix = matModel; - inverseModelMatrix.invert(); - - // Bind the light direction vector - Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); - lightDirObject.normalize(); - setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); - } + if (directional_lights) { + for (std::vector::const_iterator light_itr = directional_lights->begin(); light_itr != directional_lights->end(); light_itr++) { + KRDirectionalLight* directional_light = (*light_itr); + if (light_directional_count == 0) { + int cShadowBuffers = directional_light->getShadowBufferCount(); + if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1 && cShadowBuffers > 0) { + if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 3, directional_light->getShadowTextures()[0])) { + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + } + + m_pContext->getTextureManager()->_setWrapModeS(3, GL_CLAMP_TO_EDGE); + m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE); } - - light_directional_count++; + + if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) { + if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 4, directional_light->getShadowTextures()[1])) { + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + } + m_pContext->getTextureManager()->_setWrapModeS(4, GL_CLAMP_TO_EDGE); + m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE); + } + + if (m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) { + if (m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 5, directional_light->getShadowTextures()[2])) { + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + } + m_pContext->getTextureManager()->_setWrapModeS(5, GL_CLAMP_TO_EDGE); + m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE); + } + + Matrix4 matBias; + matBias.translate(1.0, 1.0, 1.0); + matBias.scale(0.5); + for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) { + setUniform(KRENGINE_UNIFORM_SHADOWMVP1 + iShadow, matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias); + } + + if (m_uniforms[KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE] != -1) { + Matrix4 inverseModelMatrix = matModel; + inverseModelMatrix.invert(); + + // Bind the light direction vector + Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); + lightDirObject.normalize(); + setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); + } + } + + light_directional_count++; } + } //light_point_count = point_lights.size(); //light_spot_count = spot_lights.size(); diff --git a/kraken/KRPipeline.h b/kraken/KRPipeline.h index 6d91604..0c8de9d 100644 --- a/kraken/KRPipeline.h +++ b/kraken/KRPipeline.h @@ -53,7 +53,7 @@ public: virtual ~KRPipeline(); const char *getKey() const; - bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + bool bind(KRCamera &camera, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector*spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); void bind(VkCommandBuffer& commandBuffer); enum { diff --git a/kraken/KRPipelineManager.cpp b/kraken/KRPipelineManager.cpp index 54d1f9f..81c79e4 100644 --- a/kraken/KRPipelineManager.cpp +++ b/kraken/KRPipelineManager.cpp @@ -98,9 +98,16 @@ KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) { int light_point_count = 0; int light_spot_count = 0; if(info.renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && info.renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && info.renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && info.renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) { - light_directional_count = (int)info.directional_lights->size(); - light_point_count = (int)info.point_lights->size(); - light_spot_count = (int)info.spot_lights->size(); + if (info.directional_lights) { + light_directional_count = (int)info.directional_lights->size(); + } + + if (info.point_lights) { + light_point_count = (int)info.point_lights->size(); + } + if (info.spot_lights) { + light_spot_count = (int)info.spot_lights->size(); + } for(std::vector::const_iterator light_itr=info.directional_lights->begin(); light_itr != info.directional_lights->end(); light_itr++) { KRDirectionalLight *directional_light =(*light_itr); iShadowQuality = directional_light->getShadowBufferCount(); @@ -282,10 +289,10 @@ KRPipeline *KRPipelineManager::getPipeline(const PipelineInfo &info) { bool KRPipelineManager::selectPipeline(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color) { KRPipeline* pPipeline = getPipeline(info); - return selectPipeline(*info.pCamera, pPipeline, viewport, matModel, *info.point_lights, *info.directional_lights, *info.spot_lights, info.bone_count, info.renderPass, rim_color, rim_power, fade_color); + return selectPipeline(*info.pCamera, pPipeline, viewport, matModel, info.point_lights, info.directional_lights, info.spot_lights, info.bone_count, info.renderPass, rim_color, rim_power, fade_color); } -bool KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) +bool KRPipelineManager::selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector *spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color) { if(pPipeline) { return pPipeline->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color); diff --git a/kraken/KRPipelineManager.h b/kraken/KRPipelineManager.h index 4c79304..cbcc504 100644 --- a/kraken/KRPipelineManager.h +++ b/kraken/KRPipelineManager.h @@ -84,7 +84,7 @@ public: KRPipeline *getPipeline(KRSurface& surface, KRRenderPass& renderPass, const std::string& shader_name, uint32_t vertexAttributes, KRMesh::model_format_t modelFormat); KRPipeline* getPipeline(const PipelineInfo& info); - bool selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector &point_lights, const std::vector &directional_lights, const std::vector&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); + bool selectPipeline(KRCamera &camera, KRPipeline *pPipeline, const KRViewport &viewport, const Matrix4 &matModel, const std::vector *point_lights, const std::vector *directional_lights, const std::vector *spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const Vector4 &fade_color); bool selectPipeline(const PipelineInfo& info, const KRViewport& viewport, const Matrix4& matModel, const Vector3& rim_color, float rim_power, const Vector4& fade_color); size_t getPipelineHandlesUsed(); diff --git a/kraken/KRPointLight.cpp b/kraken/KRPointLight.cpp index 56ba933..7b99029 100755 --- a/kraken/KRPointLight.cpp +++ b/kraken/KRPointLight.cpp @@ -96,18 +96,14 @@ void KRPointLight::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ()); - std::vector no_directional_lights; - std::vector no_spot_lights; std::string shader_name(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point")); KRPipelineManager::PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = pCamera; info.point_lights = &this_light; - info.directional_lights = &no_directional_lights; - info.spot_lights = &no_spot_lights; info.renderPass = renderPass; KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector(), std::vector(), 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &this_light, nullptr, nullptr, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); diff --git a/kraken/KRReverbZone.cpp b/kraken/KRReverbZone.cpp index 16b5844..30277b4 100755 --- a/kraken/KRReverbZone.cpp +++ b/kraken/KRReverbZone.cpp @@ -138,7 +138,7 @@ void KRReverbZone::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, sphereModelMatrix, &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { // Enable additive blending GLDEBUG(glEnable(GL_BLEND)); diff --git a/kraken/KRSprite.cpp b/kraken/KRSprite.cpp index 7855644..77330a7 100755 --- a/kraken/KRSprite.cpp +++ b/kraken/KRSprite.cpp @@ -165,7 +165,7 @@ void KRSprite::render(VkCommandBuffer& commandBuffer, KRCamera *pCamera, std::ve info.spot_lights = &spot_lights; info.renderPass = renderPass; KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(info); - if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { + if(getContext().getPipelineManager()->selectPipeline(*pCamera, pShader, viewport, getModelMatrix(), &point_lights, &directional_lights, &spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) { pShader->setUniform(KRPipeline::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha); m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE); m_pContext->getMeshManager()->bindVBO(commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);