From 8bee10c768a382e950b04a836f70ec55b89303a0 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Sat, 21 Sep 2024 17:16:13 -0700 Subject: [PATCH] Refactoring to reduce parameter count for KRPipeline::bind, passing by RenderInfo --- kraken/KRPipeline.cpp | 131 ++++++++++----------- kraken/KRPipeline.h | 2 +- kraken/nodes/KRAmbientZone.cpp | 2 +- kraken/nodes/KRAudioSource.cpp | 2 +- kraken/nodes/KRBone.cpp | 2 +- kraken/nodes/KRCamera.cpp | 26 +++- kraken/nodes/KRCollider.cpp | 2 +- kraken/nodes/KRDirectionalLight.cpp | 2 +- kraken/nodes/KRLight.cpp | 10 +- kraken/nodes/KRParticleSystemNewtonian.cpp | 2 +- kraken/nodes/KRPointLight.cpp | 2 +- kraken/nodes/KRReverbZone.cpp | 2 +- kraken/nodes/KRSprite.cpp | 2 +- kraken/resources/material/KRMaterial.cpp | 4 +- kraken/resources/material/KRMaterial.h | 2 +- kraken/resources/mesh/KRMesh.cpp | 2 +- kraken/resources/mesh/KRMesh.h | 2 +- kraken/resources/scene/KRScene.cpp | 2 +- 18 files changed, 105 insertions(+), 94 deletions(-) diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index d559b22..3efeff4 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -651,69 +651,66 @@ void KRPipeline::updateDescriptorBinding() // Vulkan Refactoring } -bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector* point_lights, const std::vector* directional_lights, const std::vector* spot_lights, const KRRenderPass* renderPass) +bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel) { updateDescriptorBinding(); updateDescriptorSets(); - bindDescriptorSets(commandBuffer); + bindDescriptorSets(ri.commandBuffer); setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime()); int light_directional_count = 0; //int light_point_count = 0; //int light_spot_count = 0; // TODO - Need to support multiple lights and more light types in forward rendering - if (renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) { + if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_LIGHTS && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_GBUFFER && ri.renderPass->getType() != RenderPassType::RENDER_PASS_DEFERRED_OPAQUE && ri.renderPass->getType() != RenderPassType::RENDER_PASS_SHADOWMAP) { - - 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 (hasPushConstant(PushConstant::shadowtexture1) && cShadowBuffers > 0) { - // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering - if (m_pContext->getTextureManager()->selectTexture(0 /*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)); - } - } - - if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) { - // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering - if (m_pContext->getTextureManager()->selectTexture(0 /*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)); - } - } - - if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) { - // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering - if (m_pContext->getTextureManager()->selectTexture(0 /*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)); - } - } - - Matrix4 matBias; - matBias.translate(1.0, 1.0, 1.0); - matBias.scale(0.5); - for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) { - setPushConstant(static_cast(static_cast(PushConstant::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias); - } - - if (hasPushConstant(PushConstant::light_direction_model_space)) { - Matrix4 inverseModelMatrix = matModel; - inverseModelMatrix.invert(); - - // Bind the light direction vector - Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); - lightDirObject.normalize(); - setPushConstant(PushConstant::light_direction_model_space, lightDirObject); + for (std::vector::const_iterator light_itr = ri.directional_lights.begin(); light_itr != ri.directional_lights.end(); light_itr++) { + KRDirectionalLight* directional_light = (*light_itr); + if (light_directional_count == 0) { + int cShadowBuffers = directional_light->getShadowBufferCount(); + if (hasPushConstant(PushConstant::shadowtexture1) && cShadowBuffers > 0) { + // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering + if (m_pContext->getTextureManager()->selectTexture(0 /*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)); } } - light_directional_count++; + if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && ri.camera->settings.m_cShadowBuffers > 1) { + // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering + if (m_pContext->getTextureManager()->selectTexture(0 /*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)); + } + } + + if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && ri.camera->settings.m_cShadowBuffers > 2) { + // TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering + if (m_pContext->getTextureManager()->selectTexture(0 /*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)); + } + } + + Matrix4 matBias; + matBias.translate(1.0, 1.0, 1.0); + matBias.scale(0.5); + for (int iShadow = 0; iShadow < cShadowBuffers; iShadow++) { + setPushConstant(static_cast(static_cast(PushConstant::shadow_mvp1) + iShadow), matModel * directional_light->getShadowViewports()[iShadow].getViewProjectionMatrix() * matBias); + } + + if (hasPushConstant(PushConstant::light_direction_model_space)) { + Matrix4 inverseModelMatrix = matModel; + inverseModelMatrix.invert(); + + // Bind the light direction vector + Vector3 lightDirObject = Matrix4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); + lightDirObject.normalize(); + setPushConstant(PushConstant::light_direction_model_space, lightDirObject); + } } + + light_directional_count++; } //light_point_count = point_lights.size(); @@ -726,14 +723,14 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR if (hasPushConstant(PushConstant::camerapos_model_space)) { // Transform location of camera to object space for calculation of specular halfVec - Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, viewport.getCameraPosition()); + Vector3 cameraPosObject = Matrix4::Dot(inverseModelMatrix, ri.viewport->getCameraPosition()); setPushConstant(PushConstant::camerapos_model_space, cameraPosObject); } } if (hasPushConstant(PushConstant::mvp) || hasPushConstant(KRPipeline::PushConstant::invmvp)) { // Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram - Matrix4 mvpMatrix = matModel * viewport.getViewProjectionMatrix(); + Matrix4 mvpMatrix = matModel * ri.viewport->getViewProjectionMatrix(); setPushConstant(PushConstant::mvp, mvpMatrix); if (hasPushConstant(KRPipeline::PushConstant::invmvp)) { @@ -742,7 +739,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR } if (hasPushConstant(KRPipeline::PushConstant::view_space_model_origin) || hasPushConstant(PushConstant::model_view_inverse_transpose) || hasPushConstant(KRPipeline::PushConstant::model_view)) { - Matrix4 matModelView = matModel * viewport.getViewMatrix(); + Matrix4 matModelView = matModel * ri.viewport->getViewMatrix(); setPushConstant(PushConstant::model_view, matModelView); @@ -767,11 +764,11 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR } if (hasPushConstant(KRPipeline::PushConstant::invp)) { - setPushConstant(PushConstant::invp, viewport.getInverseProjectionMatrix()); + setPushConstant(PushConstant::invp, ri.viewport->getInverseProjectionMatrix()); } if (hasPushConstant(KRPipeline::PushConstant::invmvp_no_translate)) { - Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();; + Matrix4 matInvMVPNoTranslate = matModel * ri.viewport->getViewMatrix();; // Remove the translation matInvMVPNoTranslate.getPointer()[3] = 0; matInvMVPNoTranslate.getPointer()[7] = 0; @@ -780,40 +777,40 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR matInvMVPNoTranslate.getPointer()[13] = 0; matInvMVPNoTranslate.getPointer()[14] = 0; matInvMVPNoTranslate.getPointer()[15] = 1.0; - matInvMVPNoTranslate = matInvMVPNoTranslate * viewport.getProjectionMatrix(); + matInvMVPNoTranslate = matInvMVPNoTranslate * ri.viewport->getProjectionMatrix(); matInvMVPNoTranslate.invert(); setPushConstant(PushConstant::invmvp_no_translate, matInvMVPNoTranslate); } setPushConstant(PushConstant::model_matrix, matModel); if (hasPushConstant(PushConstant::projection_matrix)) { - setPushConstant(PushConstant::projection_matrix, viewport.getProjectionMatrix()); + setPushConstant(PushConstant::projection_matrix, ri.viewport->getProjectionMatrix()); } if (hasPushConstant(PushConstant::viewport)) { setPushConstant(PushConstant::viewport, Vector4::Create( (float)0.0, (float)0.0, - (float)viewport.getSize().x, - (float)viewport.getSize().y + (float)ri.viewport->getSize().x, + (float)ri.viewport->getSize().y ) ); } // Fog parameters - setPushConstant(PushConstant::fog_near, camera.settings.fog_near); - setPushConstant(PushConstant::fog_far, camera.settings.fog_far); - setPushConstant(PushConstant::fog_density, camera.settings.fog_density); - setPushConstant(PushConstant::fog_color, camera.settings.fog_color); + setPushConstant(PushConstant::fog_near, ri.camera->settings.fog_near); + setPushConstant(PushConstant::fog_far, ri.camera->settings.fog_far); + setPushConstant(PushConstant::fog_density, ri.camera->settings.fog_density); + setPushConstant(PushConstant::fog_color, ri.camera->settings.fog_color); if (hasPushConstant(PushConstant::fog_scale)) { - setPushConstant(PushConstant::fog_scale, 1.0f / (camera.settings.fog_far - camera.settings.fog_near)); + setPushConstant(PushConstant::fog_scale, 1.0f / (ri.camera->settings.fog_far - ri.camera->settings.fog_near)); } if (hasPushConstant(PushConstant::density_premultiplied_exponential)) { - setPushConstant(PushConstant::density_premultiplied_exponential, -camera.settings.fog_density * 1.442695f); // -fog_density / log(2) + setPushConstant(PushConstant::density_premultiplied_exponential, -ri.camera->settings.fog_density * 1.442695f); // -fog_density / log(2) } if (hasPushConstant(PushConstant::density_premultiplied_squared)) { - setPushConstant(PushConstant::density_premultiplied_squared, (float)(-camera.settings.fog_density * camera.settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2) + setPushConstant(PushConstant::density_premultiplied_squared, (float)(-ri.camera->settings.fog_density * ri.camera->settings.fog_density * 1.442695)); // -fog_density * fog_density / log(2) } // Sets the diffuseTexture variable to the first texture unit @@ -841,11 +838,11 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR for (StageInfo& stageInfo : m_stages) { PushConstantInfo& pushConstants = stageInfo.pushConstants; if (pushConstants.buffer) { - vkCmdPushConstants(commandBuffer, pushConstants.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, pushConstants.bufferSize, pushConstants.buffer); + vkCmdPushConstants(ri.commandBuffer, pushConstants.layout, VK_SHADER_STAGE_VERTEX_BIT, 0, pushConstants.bufferSize, pushConstants.buffer); } } - vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); + vkCmdBindPipeline(ri.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphicsPipeline); return true; } diff --git a/kraken/KRPipeline.h b/kraken/KRPipeline.h index 37ef87e..3600d85 100644 --- a/kraken/KRPipeline.h +++ b/kraken/KRPipeline.h @@ -218,7 +218,7 @@ public: virtual ~KRPipeline(); const char* getKey() const; - bool bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const hydra::Matrix4& matModel, const std::vector* point_lights, const std::vector* directional_lights, const std::vector* spot_lights, const KRRenderPass* renderPass); + bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel); enum class PushConstant : uint8_t { diff --git a/kraken/nodes/KRAmbientZone.cpp b/kraken/nodes/KRAmbientZone.cpp index c65efc9..9b3ef53 100755 --- a/kraken/nodes/KRAmbientZone.cpp +++ b/kraken/nodes/KRAmbientZone.cpp @@ -148,7 +148,7 @@ void KRAmbientZone::render(RenderInfo& ri) info.vertexAttributes = sphereModel->getVertexAttributes(); KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pPipeline->bind(ri.commandBuffer, *ri.camera, *ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pPipeline->bind(ri, sphereModelMatrix); sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f); } // sphereModel diff --git a/kraken/nodes/KRAudioSource.cpp b/kraken/nodes/KRAudioSource.cpp index 69260ec..6e0fc09 100755 --- a/kraken/nodes/KRAudioSource.cpp +++ b/kraken/nodes/KRAudioSource.cpp @@ -215,7 +215,7 @@ void KRAudioSource::render(RenderInfo& ri) info.vertexAttributes = sphereModel->getVertexAttributes(); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, sphereModelMatrix); sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f); } // sphereModels.size() diff --git a/kraken/nodes/KRBone.cpp b/kraken/nodes/KRBone.cpp index 15cadb5..5a805e2 100755 --- a/kraken/nodes/KRBone.cpp +++ b/kraken/nodes/KRBone.cpp @@ -99,7 +99,7 @@ void KRBone::render(RenderInfo& ri) info.vertexAttributes = sphereModel->getVertexAttributes(); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, sphereModelMatrix); sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f); } // sphereModel diff --git a/kraken/nodes/KRCamera.cpp b/kraken/nodes/KRCamera.cpp index 2eae544..c78d49c 100755 --- a/kraken/nodes/KRCamera.cpp +++ b/kraken/nodes/KRCamera.cpp @@ -284,7 +284,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS info.vertexAttributes = sphereMesh->getVertexAttributes(); info.modelFormat = sphereMesh->getModelFormat(); KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(compositeSurface, info); - testPipeline->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, info.renderPass); + testPipeline->bind(ri, Matrix4()); sphereMesh->renderNoMaterials(commandBuffer, info.renderPass, "Vulkan Test", "vulkan_test", 1.0); } @@ -305,17 +305,19 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS if (m_pSkyBoxTexture) { m_pSkyBoxTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); + ri.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE); + std::string shader_name("sky_box"); PipelineInfo info{}; info.shader_name = &shader_name; info.pCamera = this; - info.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE); + info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kOpaqueNoDepthWrite; info.cullMode = CullMode::kCullNone; KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info); pPipeline->setImageBinding("diffuseTexture", m_pSkyBoxTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - pPipeline->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE)); + pPipeline->bind(ri, Matrix4()); // Render a full screen quad m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f); @@ -395,6 +397,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS ri.renderPass->begin(commandBuffer, compositeSurface); scene.render(ri, false); ri.renderPass->end(commandBuffer); + ri.viewport = &m_viewport; GL_POP_GROUP_MARKER; } @@ -407,22 +410,25 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS if (settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) { KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES; + ri.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT); + PipelineInfo info{}; std::string shader_name("visualize_overlay"); info.shader_name = &shader_name; info.pCamera = this; - info.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT); + info.renderPass = ri.renderPass; info.rasterMode = RasterMode::kAdditive; info.vertexAttributes = vertices.getVertexAttributes(); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; KRPipeline* pVisShader = getContext().getPipelineManager()->getPipeline(compositeSurface, info); + m_pContext->getMeshManager()->bindVBO(commandBuffer, &vertices, 1.0f); for (unordered_map::iterator itr = m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { Matrix4 matModel = Matrix4(); matModel.scale((*itr).first.size() * 0.5f); matModel.translate((*itr).first.center()); - pVisShader->bind(commandBuffer, *this, m_viewport, matModel, nullptr, nullptr, nullptr, compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT)); + pVisShader->bind(ri,matModel); vkCmdDraw(commandBuffer, 14, 1, 0, 0); } } @@ -816,8 +822,16 @@ void KRCamera::renderDebug(VkCommandBuffer& commandBuffer, KRSurface& surface) info.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA); info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(surface, info); + + RenderInfo ri(commandBuffer); + ri.camera = this; + ri.renderPass = surface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT); + ri.surface = &surface; + ri.viewport = &m_viewport; + + fontShader->setImageBinding("fontTexture", fontTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - fontShader->bind(commandBuffer, *this, m_viewport, Matrix4(), nullptr, nullptr, nullptr, surface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT)); + fontShader->bind(ri, Matrix4()); m_debug_text_vbo_data.bind(commandBuffer); diff --git a/kraken/nodes/KRCollider.cpp b/kraken/nodes/KRCollider.cpp index b81c74d..91b55c4 100755 --- a/kraken/nodes/KRCollider.cpp +++ b/kraken/nodes/KRCollider.cpp @@ -238,7 +238,7 @@ void KRCollider::render(RenderInfo& ri) KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, getModelMatrix()); m_model->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f); diff --git a/kraken/nodes/KRDirectionalLight.cpp b/kraken/nodes/KRDirectionalLight.cpp index 8151a51..7eaa292 100755 --- a/kraken/nodes/KRDirectionalLight.cpp +++ b/kraken/nodes/KRDirectionalLight.cpp @@ -163,7 +163,7 @@ void KRDirectionalLight::render(RenderInfo& ri) pShader->setPushConstant(KRPipeline::PushConstant::light_direction_view_space, light_direction_view_space); pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color); pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, getModelMatrix(), nullptr, &this_light, nullptr, ri.renderPass); + pShader->bind(ri, getModelMatrix()); // TODO: Need to pass in the light index to the shader // Render a full screen quad m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); diff --git a/kraken/nodes/KRLight.cpp b/kraken/nodes/KRLight.cpp index 2d564e9..6da2d07 100755 --- a/kraken/nodes/KRLight.cpp +++ b/kraken/nodes/KRLight.cpp @@ -287,7 +287,7 @@ void KRLight::render(RenderInfo& ri) pParticleShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); pParticleShader->setPushConstant(KRPipeline::PushConstant::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero())); pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_dust_particle_size); - pParticleShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, particleModelMatrix, &this_point_light, &this_directional_light, &this_spot_light, ri.renderPass); + pParticleShader->bind(ri, particleModelMatrix); // TODO: Pass light index to shader m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f); @@ -338,7 +338,7 @@ void KRLight::render(RenderInfo& ri) pFogShader->setPushConstant(KRPipeline::PushConstant::slice_depth_scale, Vector2::Create(slice_near, slice_spacing)); pFogShader->setPushConstant(KRPipeline::PushConstant::light_color, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f)); - pFogShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, Matrix4(), &this_point_light, &this_directional_light, &this_spot_light, ri.renderPass); + pFogShader->bind(ri, Matrix4()); // TODO: Pass indexes of lights to shader m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING, 1.0f); vkCmdDraw(ri.commandBuffer, slice_count * 6, 1, 0, 0); @@ -371,7 +371,7 @@ void KRLight::render(RenderInfo& ri) info.vertexAttributes = sphereModel->getVertexAttributes(); KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pPipeline->bind(ri.commandBuffer, *info.pCamera, *ri.viewport, occlusion_test_sphere_matrix, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass); + pPipeline->bind(ri, occlusion_test_sphere_matrix); GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery)); #if TARGET_OS_IPHONE || defined(ANDROID) @@ -429,7 +429,7 @@ void KRLight::render(RenderInfo& ri) pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, 1.0f); pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize); pShader->setImageBinding("diffuseTexture", m_pFlareTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, getModelMatrix()); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); @@ -542,7 +542,7 @@ void KRLight::renderShadowBuffers(RenderInfo& ri) KRPipeline* shadowShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); ri.viewport = &m_shadowViewports[iShadow]; - shadowShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, Matrix4(), nullptr, nullptr, nullptr, ri.renderPass); + shadowShader->bind(ri, Matrix4()); getScene().render(ri, true); } diff --git a/kraken/nodes/KRParticleSystemNewtonian.cpp b/kraken/nodes/KRParticleSystemNewtonian.cpp index f126601..b36b055 100755 --- a/kraken/nodes/KRParticleSystemNewtonian.cpp +++ b/kraken/nodes/KRParticleSystemNewtonian.cpp @@ -106,7 +106,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri) KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, 1.0f); - pParticleShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pParticleShader->bind(ri, getModelMatrix()); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f); diff --git a/kraken/nodes/KRPointLight.cpp b/kraken/nodes/KRPointLight.cpp index 40da0d4..0c398ca 100755 --- a/kraken/nodes/KRPointLight.cpp +++ b/kraken/nodes/KRPointLight.cpp @@ -121,7 +121,7 @@ void KRPointLight::render(RenderInfo& ri) pShader->setPushConstant(KRPipeline::PushConstant::light_decay_start, getDecayStart()); pShader->setPushConstant(KRPipeline::PushConstant::light_cutoff, KRLIGHT_MIN_INFLUENCE); pShader->setPushConstant(KRPipeline::PushConstant::light_position, light_position); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, sphereModelMatrix, &this_light, nullptr, nullptr, ri.renderPass); + pShader->bind(ri, sphereModelMatrix); // TODO: Pass light index to shader if (bInsideLight) { // Render a full screen quad diff --git a/kraken/nodes/KRReverbZone.cpp b/kraken/nodes/KRReverbZone.cpp index f0476a6..14955ce 100755 --- a/kraken/nodes/KRReverbZone.cpp +++ b/kraken/nodes/KRReverbZone.cpp @@ -145,7 +145,7 @@ void KRReverbZone::render(RenderInfo& ri) KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, sphereModelMatrix); sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f); } // sphereModel diff --git a/kraken/nodes/KRSprite.cpp b/kraken/nodes/KRSprite.cpp index 4df60f0..e0d72f3 100755 --- a/kraken/nodes/KRSprite.cpp +++ b/kraken/nodes/KRSprite.cpp @@ -167,7 +167,7 @@ void KRSprite::render(RenderInfo& ri) KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha); pShader->setImageBinding("diffuseTexture", m_pSpriteTexture, m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, getModelMatrix()); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); diff --git a/kraken/resources/material/KRMaterial.cpp b/kraken/resources/material/KRMaterial.cpp index 34e1c06..02785c0 100755 --- a/kraken/resources/material/KRMaterial.cpp +++ b/kraken/resources/material/KRMaterial.cpp @@ -325,7 +325,7 @@ void KRMaterial::getTextures() } } -void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector& bones, const std::vector& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage) +void KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector& bones, const std::vector& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage) { bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap; @@ -467,7 +467,7 @@ void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __u pShader->setImageBinding("reflectionTexture", m_pReflectionMap, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); } - pShader->bind(ri.commandBuffer, *ri.camera, *ri.viewport, matModel, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass); + pShader->bind(ri, matModel); } const std::string& KRMaterial::getName() const diff --git a/kraken/resources/material/KRMaterial.h b/kraken/resources/material/KRMaterial.h index ea08ad9..da91fbd 100755 --- a/kraken/resources/material/KRMaterial.h +++ b/kraken/resources/material/KRMaterial.h @@ -87,7 +87,7 @@ public: bool isTransparent(); const std::string& getName() const; - void bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector& bones, const std::vector& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); + void bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector& bones, const std::vector& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); bool needsVertexTangents(); diff --git a/kraken/resources/mesh/KRMesh.cpp b/kraken/resources/mesh/KRMesh.cpp index a8e07c2..3ee5c75 100755 --- a/kraken/resources/mesh/KRMesh.cpp +++ b/kraken/resources/mesh/KRMesh.cpp @@ -252,7 +252,7 @@ kraken_stream_level KRMesh::getStreamLevel() } -void KRMesh::render(const KRNode::RenderInfo& ri, const std::string& object_name, const Matrix4& matModel, KRTexture* pLightMap, const std::vector& bones, const Vector3& rim_color, float rim_power, float lod_coverage) +void KRMesh::render(KRNode::RenderInfo& ri, const std::string& object_name, const Matrix4& matModel, KRTexture* pLightMap, const std::vector& bones, const Vector3& rim_color, float rim_power, float lod_coverage) { //fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); if (ri.renderPass->getType() != RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES && ri.renderPass->getType() != RenderPassType::RENDER_PASS_PARTICLE_OCCLUSION && ri.renderPass->getType() != RenderPassType::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { diff --git a/kraken/resources/mesh/KRMesh.h b/kraken/resources/mesh/KRMesh.h index 1b109e6..395a9f2 100755 --- a/kraken/resources/mesh/KRMesh.h +++ b/kraken/resources/mesh/KRMesh.h @@ -119,7 +119,7 @@ public: std::vector > bone_weights; } mesh_info; - void render(const KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector& bones, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); + void render(KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector& bones, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f); std::string m_lodBaseName; diff --git a/kraken/resources/scene/KRScene.cpp b/kraken/resources/scene/KRScene.cpp index 71fca1c..474e336 100755 --- a/kraken/resources/scene/KRScene.cpp +++ b/kraken/resources/scene/KRScene.cpp @@ -303,7 +303,7 @@ void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, std::vec info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - pPipeline->bind(ri.commandBuffer, *info.pCamera, *ri.viewport, matModel, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass); + pPipeline->bind(ri, matModel); vkCmdDraw(ri.commandBuffer, 14, 1, 0, 0); m_pContext->getMeshManager()->log_draw_call(ri.renderPass->getType(), "octree", "occlusion_test", 14);