Refactoring to reduce parameter count for KRPipeline::bind, passing by RenderInfo

This commit is contained in:
2024-09-21 17:16:13 -07:00
parent d7672d31f4
commit 8bee10c768
18 changed files with 105 additions and 94 deletions

View File

@@ -651,22 +651,20 @@ void KRPipeline::updateDescriptorBinding()
// Vulkan Refactoring // Vulkan Refactoring
} }
bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRRenderPass* renderPass) bool KRPipeline::bind(KRNode::RenderInfo& ri, const Matrix4& matModel)
{ {
updateDescriptorBinding(); updateDescriptorBinding();
updateDescriptorSets(); updateDescriptorSets();
bindDescriptorSets(commandBuffer); bindDescriptorSets(ri.commandBuffer);
setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime()); setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime());
int light_directional_count = 0; int light_directional_count = 0;
//int light_point_count = 0; //int light_point_count = 0;
//int light_spot_count = 0; //int light_spot_count = 0;
// TODO - Need to support multiple lights and more light types in forward rendering // 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) {
for (std::vector<KRDirectionalLight*>::const_iterator light_itr = ri.directional_lights.begin(); light_itr != ri.directional_lights.end(); light_itr++) {
if (directional_lights) {
for (std::vector<KRDirectionalLight*>::const_iterator light_itr = directional_lights->begin(); light_itr != directional_lights->end(); light_itr++) {
KRDirectionalLight* directional_light = (*light_itr); KRDirectionalLight* directional_light = (*light_itr);
if (light_directional_count == 0) { if (light_directional_count == 0) {
int cShadowBuffers = directional_light->getShadowBufferCount(); int cShadowBuffers = directional_light->getShadowBufferCount();
@@ -678,7 +676,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
} }
} }
if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) { if (hasPushConstant(PushConstant::shadowtexture2) && cShadowBuffers > 1 && ri.camera->settings.m_cShadowBuffers > 1) {
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering // 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])) { 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_MIN_FILTER, GL_LINEAR));
@@ -686,7 +684,7 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
} }
} }
if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) { if (hasPushConstant(PushConstant::shadowtexture3) && cShadowBuffers > 2 && ri.camera->settings.m_cShadowBuffers > 2) {
// TODO - Vulkan Refactoring. Note: Sampler needs clamp-to-edge and linear filtering // 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])) { 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_MIN_FILTER, GL_LINEAR));
@@ -714,7 +712,6 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
light_directional_count++; light_directional_count++;
} }
}
//light_point_count = point_lights.size(); //light_point_count = point_lights.size();
//light_spot_count = spot_lights.size(); //light_spot_count = spot_lights.size();
@@ -726,14 +723,14 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
if (hasPushConstant(PushConstant::camerapos_model_space)) { if (hasPushConstant(PushConstant::camerapos_model_space)) {
// Transform location of camera to object space for calculation of specular halfVec // 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); setPushConstant(PushConstant::camerapos_model_space, cameraPosObject);
} }
} }
if (hasPushConstant(PushConstant::mvp) || hasPushConstant(KRPipeline::PushConstant::invmvp)) { if (hasPushConstant(PushConstant::mvp) || hasPushConstant(KRPipeline::PushConstant::invmvp)) {
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram // 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); setPushConstant(PushConstant::mvp, mvpMatrix);
if (hasPushConstant(KRPipeline::PushConstant::invmvp)) { 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)) { 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); setPushConstant(PushConstant::model_view, matModelView);
@@ -767,11 +764,11 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
} }
if (hasPushConstant(KRPipeline::PushConstant::invp)) { if (hasPushConstant(KRPipeline::PushConstant::invp)) {
setPushConstant(PushConstant::invp, viewport.getInverseProjectionMatrix()); setPushConstant(PushConstant::invp, ri.viewport->getInverseProjectionMatrix());
} }
if (hasPushConstant(KRPipeline::PushConstant::invmvp_no_translate)) { if (hasPushConstant(KRPipeline::PushConstant::invmvp_no_translate)) {
Matrix4 matInvMVPNoTranslate = matModel * viewport.getViewMatrix();; Matrix4 matInvMVPNoTranslate = matModel * ri.viewport->getViewMatrix();;
// Remove the translation // Remove the translation
matInvMVPNoTranslate.getPointer()[3] = 0; matInvMVPNoTranslate.getPointer()[3] = 0;
matInvMVPNoTranslate.getPointer()[7] = 0; matInvMVPNoTranslate.getPointer()[7] = 0;
@@ -780,40 +777,40 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR
matInvMVPNoTranslate.getPointer()[13] = 0; matInvMVPNoTranslate.getPointer()[13] = 0;
matInvMVPNoTranslate.getPointer()[14] = 0; matInvMVPNoTranslate.getPointer()[14] = 0;
matInvMVPNoTranslate.getPointer()[15] = 1.0; matInvMVPNoTranslate.getPointer()[15] = 1.0;
matInvMVPNoTranslate = matInvMVPNoTranslate * viewport.getProjectionMatrix(); matInvMVPNoTranslate = matInvMVPNoTranslate * ri.viewport->getProjectionMatrix();
matInvMVPNoTranslate.invert(); matInvMVPNoTranslate.invert();
setPushConstant(PushConstant::invmvp_no_translate, matInvMVPNoTranslate); setPushConstant(PushConstant::invmvp_no_translate, matInvMVPNoTranslate);
} }
setPushConstant(PushConstant::model_matrix, matModel); setPushConstant(PushConstant::model_matrix, matModel);
if (hasPushConstant(PushConstant::projection_matrix)) { if (hasPushConstant(PushConstant::projection_matrix)) {
setPushConstant(PushConstant::projection_matrix, viewport.getProjectionMatrix()); setPushConstant(PushConstant::projection_matrix, ri.viewport->getProjectionMatrix());
} }
if (hasPushConstant(PushConstant::viewport)) { if (hasPushConstant(PushConstant::viewport)) {
setPushConstant(PushConstant::viewport, Vector4::Create( setPushConstant(PushConstant::viewport, Vector4::Create(
(float)0.0, (float)0.0,
(float)0.0, (float)0.0,
(float)viewport.getSize().x, (float)ri.viewport->getSize().x,
(float)viewport.getSize().y (float)ri.viewport->getSize().y
) )
); );
} }
// Fog parameters // Fog parameters
setPushConstant(PushConstant::fog_near, camera.settings.fog_near); setPushConstant(PushConstant::fog_near, ri.camera->settings.fog_near);
setPushConstant(PushConstant::fog_far, camera.settings.fog_far); setPushConstant(PushConstant::fog_far, ri.camera->settings.fog_far);
setPushConstant(PushConstant::fog_density, camera.settings.fog_density); setPushConstant(PushConstant::fog_density, ri.camera->settings.fog_density);
setPushConstant(PushConstant::fog_color, camera.settings.fog_color); setPushConstant(PushConstant::fog_color, ri.camera->settings.fog_color);
if (hasPushConstant(PushConstant::fog_scale)) { 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)) { 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)) { 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 // 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) { for (StageInfo& stageInfo : m_stages) {
PushConstantInfo& pushConstants = stageInfo.pushConstants; PushConstantInfo& pushConstants = stageInfo.pushConstants;
if (pushConstants.buffer) { 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; return true;
} }

View File

@@ -218,7 +218,7 @@ public:
virtual ~KRPipeline(); virtual ~KRPipeline();
const char* getKey() const; const char* getKey() const;
bool bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const hydra::Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRRenderPass* renderPass); bool bind(KRNode::RenderInfo& ri, const hydra::Matrix4& matModel);
enum class PushConstant : uint8_t enum class PushConstant : uint8_t
{ {

View File

@@ -148,7 +148,7 @@ void KRAmbientZone::render(RenderInfo& ri)
info.vertexAttributes = sphereModel->getVertexAttributes(); info.vertexAttributes = sphereModel->getVertexAttributes();
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
} // sphereModel } // sphereModel

View File

@@ -215,7 +215,7 @@ void KRAudioSource::render(RenderInfo& ri)
info.vertexAttributes = sphereModel->getVertexAttributes(); info.vertexAttributes = sphereModel->getVertexAttributes();
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
} // sphereModels.size() } // sphereModels.size()

View File

@@ -99,7 +99,7 @@ void KRBone::render(RenderInfo& ri)
info.vertexAttributes = sphereModel->getVertexAttributes(); info.vertexAttributes = sphereModel->getVertexAttributes();
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
} // sphereModel } // sphereModel

View File

@@ -284,7 +284,7 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
info.vertexAttributes = sphereMesh->getVertexAttributes(); info.vertexAttributes = sphereMesh->getVertexAttributes();
info.modelFormat = sphereMesh->getModelFormat(); info.modelFormat = sphereMesh->getModelFormat();
KRPipeline* testPipeline = m_pContext->getPipelineManager()->getPipeline(compositeSurface, info); 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); 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) { if (m_pSkyBoxTexture) {
m_pSkyBoxTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); 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"); std::string shader_name("sky_box");
PipelineInfo info{}; PipelineInfo info{};
info.shader_name = &shader_name; info.shader_name = &shader_name;
info.pCamera = this; info.pCamera = this;
info.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_OPAQUE); info.renderPass = ri.renderPass;
info.rasterMode = RasterMode::kOpaqueNoDepthWrite; info.rasterMode = RasterMode::kOpaqueNoDepthWrite;
info.cullMode = CullMode::kCullNone; info.cullMode = CullMode::kCullNone;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info); KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
pPipeline->setImageBinding("diffuseTexture", m_pSkyBoxTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); 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 // Render a full screen quad
m_pContext->getMeshManager()->bindVBO(commandBuffer, &getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f); 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); ri.renderPass->begin(commandBuffer, compositeSurface);
scene.render(ri, false); scene.render(ri, false);
ri.renderPass->end(commandBuffer); ri.renderPass->end(commandBuffer);
ri.viewport = &m_viewport;
GL_POP_GROUP_MARKER; GL_POP_GROUP_MARKER;
} }
@@ -407,22 +410,25 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
if (settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) { if (settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_OCTREE) {
KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES; KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES;
ri.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT);
PipelineInfo info{}; PipelineInfo info{};
std::string shader_name("visualize_overlay"); std::string shader_name("visualize_overlay");
info.shader_name = &shader_name; info.shader_name = &shader_name;
info.pCamera = this; info.pCamera = this;
info.renderPass = compositeSurface.getRenderPass(RenderPassType::RENDER_PASS_FORWARD_TRANSPARENT); info.renderPass = ri.renderPass;
info.rasterMode = RasterMode::kAdditive; info.rasterMode = RasterMode::kAdditive;
info.vertexAttributes = vertices.getVertexAttributes(); info.vertexAttributes = vertices.getVertexAttributes();
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pVisShader = getContext().getPipelineManager()->getPipeline(compositeSurface, info); KRPipeline* pVisShader = getContext().getPipelineManager()->getPipeline(compositeSurface, info);
m_pContext->getMeshManager()->bindVBO(commandBuffer, &vertices, 1.0f); m_pContext->getMeshManager()->bindVBO(commandBuffer, &vertices, 1.0f);
for (unordered_map<AABB, int>::iterator itr = m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) { for (unordered_map<AABB, int>::iterator itr = m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
Matrix4 matModel = Matrix4(); Matrix4 matModel = Matrix4();
matModel.scale((*itr).first.size() * 0.5f); matModel.scale((*itr).first.size() * 0.5f);
matModel.translate((*itr).first.center()); 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); 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.vertexAttributes = (1 << KRMesh::KRENGINE_ATTRIB_VERTEX) | (1 << KRMesh::KRENGINE_ATTRIB_TEXUVA);
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
KRPipeline* fontShader = m_pContext->getPipelineManager()->getPipeline(surface, info); 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->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); m_debug_text_vbo_data.bind(commandBuffer);

View File

@@ -238,7 +238,7 @@ void KRCollider::render(RenderInfo& ri)
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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); m_model->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);

View File

@@ -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_direction_view_space, light_direction_view_space);
pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color); pShader->setPushConstant(KRPipeline::PushConstant::light_color, m_color);
pShader->setPushConstant(KRPipeline::PushConstant::light_intensity, m_intensity * 0.01f); 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 // Render a full screen quad
m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);

View File

@@ -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::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::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero()));
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_dust_particle_size); 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); 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::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->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); 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); vkCmdDraw(ri.commandBuffer, slice_count * 6, 1, 0, 0);
@@ -371,7 +371,7 @@ void KRLight::render(RenderInfo& ri)
info.vertexAttributes = sphereModel->getVertexAttributes(); info.vertexAttributes = sphereModel->getVertexAttributes();
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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)); GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
#if TARGET_OS_IPHONE || defined(ANDROID) #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::material_alpha, 1.0f);
pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize); pShader->setPushConstant(KRPipeline::PushConstant::flare_size, m_flareSize);
pShader->setImageBinding("diffuseTexture", m_pFlareTexture, getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); 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); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); 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); KRPipeline* shadowShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
ri.viewport = &m_shadowViewports[iShadow]; 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); getScene().render(ri, true);
} }

View File

@@ -106,7 +106,7 @@ void KRParticleSystemNewtonian::render(RenderInfo& ri)
KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info);
pParticleShader->setPushConstant(KRPipeline::PushConstant::flare_size, 1.0f); 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); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_RANDOM_PARTICLES, 1.0f);

View File

@@ -121,7 +121,7 @@ void KRPointLight::render(RenderInfo& ri)
pShader->setPushConstant(KRPipeline::PushConstant::light_decay_start, getDecayStart()); pShader->setPushConstant(KRPipeline::PushConstant::light_decay_start, getDecayStart());
pShader->setPushConstant(KRPipeline::PushConstant::light_cutoff, KRLIGHT_MIN_INFLUENCE); pShader->setPushConstant(KRPipeline::PushConstant::light_cutoff, KRLIGHT_MIN_INFLUENCE);
pShader->setPushConstant(KRPipeline::PushConstant::light_position, light_position); 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) { if (bInsideLight) {
// Render a full screen quad // Render a full screen quad

View File

@@ -145,7 +145,7 @@ void KRReverbZone::render(RenderInfo& ri)
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
} // sphereModel } // sphereModel

View File

@@ -167,7 +167,7 @@ void KRSprite::render(RenderInfo& ri)
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha); pShader->setPushConstant(KRPipeline::PushConstant::material_alpha, m_spriteAlpha);
pShader->setImageBinding("diffuseTexture", m_pSpriteTexture, m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); 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); m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f);
vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0);

View File

@@ -325,7 +325,7 @@ void KRMaterial::getTextures()
} }
} }
void KRMaterial::bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<Matrix4>& 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<KRBone*>& bones, const std::vector<Matrix4>& bind_poses, const Matrix4& matModel, KRTexture* pLightMap, const Vector3& rim_color, float rim_power, float lod_coverage)
{ {
bool bLightMap = pLightMap && ri.camera->settings.bEnableLightMap; 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->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 const std::string& KRMaterial::getName() const

View File

@@ -87,7 +87,7 @@ public:
bool isTransparent(); bool isTransparent();
const std::string& getName() const; const std::string& getName() const;
void bind(const KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_t vertexAttributes, CullMode cullMode, const std::vector<KRBone*>& bones, const std::vector<hydra::Matrix4>& 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<KRBone*>& bones, const std::vector<hydra::Matrix4>& bind_poses, const hydra::Matrix4& matModel, KRTexture* pLightMap, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f);
bool needsVertexTangents(); bool needsVertexTangents();

View File

@@ -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<KRBone*>& 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<KRBone*>& bones, const Vector3& rim_color, float rim_power, float lod_coverage)
{ {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //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) { 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) {

View File

@@ -119,7 +119,7 @@ public:
std::vector<std::vector<float> > bone_weights; std::vector<std::vector<float> > bone_weights;
} mesh_info; } mesh_info;
void render(const KRNode::RenderInfo& ri, const std::string& object_name, const hydra::Matrix4& matModel, KRTexture* pLightMap, const std::vector<KRBone*>& 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<KRBone*>& bones, const hydra::Vector3& rim_color, float rim_power, float lod_coverage = 0.0f);
std::string m_lodBaseName; std::string m_lodBaseName;

View File

@@ -303,7 +303,7 @@ void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, std::vec
info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP;
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info); 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); vkCmdDraw(ri.commandBuffer, 14, 1, 0, 0);
m_pContext->getMeshManager()->log_draw_call(ri.renderPass->getType(), "octree", "occlusion_test", 14); m_pContext->getMeshManager()->log_draw_call(ri.renderPass->getType(), "octree", "occlusion_test", 14);