diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index 9adaf69..6392a86 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -843,20 +843,3 @@ VkPipeline& KRPipeline::getPipeline() return m_graphicsPipeline; } -void KRPipeline::setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler) -{ - for (int stage = 0; stage < static_cast(ShaderStage::ShaderStageCount); stage++) { - StageInfo& stageInfo = m_stages[stage]; - for (DescriptorSetInfo& descriptorSetInfo : stageInfo.descriptorSets) { - for (DescriptorBinding& binding : descriptorSetInfo.bindings) { - ImageDescriptorInfo* image = std::get_if(&binding); - if (image) { - if (image->name == name) { - image->texture = texture; - image->sampler = sampler; - } - } - } - } - } -} diff --git a/kraken/KRPipeline.h b/kraken/KRPipeline.h index 6edb8b8..2c1344b 100644 --- a/kraken/KRPipeline.h +++ b/kraken/KRPipeline.h @@ -232,8 +232,6 @@ public: void setPushConstant(ShaderValue location, const hydra::Matrix4& value); void setPushConstant(ShaderValue location, const hydra::Matrix4* value, const size_t count); - void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler); - VkPipeline& getPipeline(); void bindDescriptorSets(VkCommandBuffer& commandBuffer); diff --git a/kraken/nodes/KRCamera.cpp b/kraken/nodes/KRCamera.cpp index da15b59..921b7c4 100755 --- a/kraken/nodes/KRCamera.cpp +++ b/kraken/nodes/KRCamera.cpp @@ -859,7 +859,6 @@ bool KRCamera::getImageBinding(const std::string& name, const KRTextureBinding** *binding = &m_skyBox.val; *sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER; return true; - } else { return KRNode::getImageBinding(name, binding, sample); } diff --git a/kraken/nodes/KRLight.cpp b/kraken/nodes/KRLight.cpp index 92f6b82..8b19000 100755 --- a/kraken/nodes/KRLight.cpp +++ b/kraken/nodes/KRLight.cpp @@ -174,6 +174,7 @@ void KRLight::getResourceBindings(std::list& bindings) void KRLight::render(RenderInfo& ri) { KRNode::render(ri); + ri.reflectedObjects.push_back(this); if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_SHADOWMAP && (ri.camera->settings.volumetric_environment_enable || ri.camera->settings.dust_particle_enable || (ri.camera->settings.m_cShadowBuffers > 0 && m_casts_shadow))) { allocateShadowBuffers(configureShadowBufferViewports(*ri.viewport)); @@ -336,6 +337,8 @@ void KRLight::render(RenderInfo& ri) } } + + ri.reflectedObjects.pop_back(); } if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) { @@ -347,35 +350,31 @@ void KRLight::render(RenderInfo& ri) GLDEBUG(glDeleteQueriesEXT(1, &m_occlusionQuery)); if (params) { - KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; + KRMeshManager::KRVBOData& vertices = getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; - // Render light flare on transparency pass - PipelineInfo info{}; - std::string shader_name("flare"); - info.shader_name = &shader_name; - info.pCamera = ri.camera; - info.point_lights = &ri.point_lights; - info.directional_lights = &ri.directional_lights; - info.spot_lights = &ri.spot_lights; - info.renderPass = ri.renderPass; - info.rasterMode = RasterMode::kAdditiveNoTest; - info.cullMode = CullMode::kCullNone; - info.vertexAttributes = vertices.getVertexAttributes(); - info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; + // Render light flare on transparency pass + PipelineInfo info{}; + std::string shader_name("flare"); + info.shader_name = &shader_name; + info.pCamera = ri.camera; + info.point_lights = &ri.point_lights; + info.directional_lights = &ri.directional_lights; + info.spot_lights = &ri.spot_lights; + info.renderPass = ri.renderPass; + info.rasterMode = RasterMode::kAdditiveNoTest; + info.cullMode = CullMode::kCullNone; + info.vertexAttributes = vertices.getVertexAttributes(); + info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; - KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - if (pShader) { - pShader->setImageBinding("diffuseTexture", m_flareTexture.val.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - if (pShader->bind(ri, getModelMatrix())) { - m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); - vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); - } - } + KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); + if (pShader && pShader->bind(ri, getModelMatrix())) { + m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); + vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); } + } } } - } } @@ -552,3 +551,15 @@ bool KRLight::getShaderValue(ShaderValue value, hydra::Vector3* output) const return KRNode::getShaderValue(value, output); } } + + +bool KRLight::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const +{ + if (name == "flareTexture") { + *binding = &m_flareTexture.val; + *sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER; + return true; + } else { + return KRNode::getImageBinding(name, binding, sample); + } +} \ No newline at end of file diff --git a/kraken/nodes/KRLight.h b/kraken/nodes/KRLight.h index 5360a90..fcdddb3 100755 --- a/kraken/nodes/KRLight.h +++ b/kraken/nodes/KRLight.h @@ -78,6 +78,7 @@ protected: bool getShaderValue(ShaderValue value, float* output) const override; bool getShaderValue(ShaderValue value, hydra::Vector3* output) const override; + bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final; // Properties KRNODE_PROPERTY(float, m_decayStart, 0.f, "decay_start"); diff --git a/kraken/nodes/KRSprite.cpp b/kraken/nodes/KRSprite.cpp index bb7a7ee..f36b205 100755 --- a/kraken/nodes/KRSprite.cpp +++ b/kraken/nodes/KRSprite.cpp @@ -113,39 +113,36 @@ void KRSprite::getResourceBindings(std::list& bindings) void KRSprite::render(RenderInfo& ri) { KRNode::render(ri); + ri.reflectedObjects.push_back(this); if (ri.renderPass->getType() == RenderPassType::RENDER_PASS_ADDITIVE_PARTICLES) { if (m_spriteAlpha > 0.0f) { - if (m_spriteTexture.val.isBound()) { - // TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes + // TODO - Sprites are currently additive only. Need to expose this and allow for multiple blending modes - KRMeshManager::KRVBOData& vertices = m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; + KRMeshManager::KRVBOData& vertices = m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES; - // Render light sprite on transparency pass - PipelineInfo info{}; - std::string shader_name("sprite"); - info.shader_name = &shader_name; - info.pCamera = ri.camera; - info.point_lights = &ri.point_lights; - info.directional_lights = &ri.directional_lights; - info.spot_lights = &ri.spot_lights; - info.renderPass = ri.renderPass; - info.rasterMode = RasterMode::kAdditive; - info.cullMode = CullMode::kCullNone; - info.vertexAttributes = vertices.getVertexAttributes(); - info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; + // Render light sprite on transparency pass + PipelineInfo info{}; + std::string shader_name("sprite"); + info.shader_name = &shader_name; + info.pCamera = ri.camera; + info.point_lights = &ri.point_lights; + info.directional_lights = &ri.directional_lights; + info.spot_lights = &ri.spot_lights; + info.renderPass = ri.renderPass; + info.rasterMode = RasterMode::kAdditive; + info.cullMode = CullMode::kCullNone; + info.vertexAttributes = vertices.getVertexAttributes(); + info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_STRIP; - KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); - if (pShader) { - pShader->setImageBinding("diffuseTexture", m_spriteTexture.val.get(), m_pContext->getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - if (pShader->bind(ri, getModelMatrix())) { - m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); - vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); - } - } + KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info); + if (pShader && pShader->bind(ri, getModelMatrix())) { + m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &vertices, 1.0f); + vkCmdDraw(ri.commandBuffer, 4, 1, 0, 0); } } } + ri.reflectedObjects.pop_back(); } bool KRSprite::getShaderValue(ShaderValue value, float* output) const @@ -155,3 +152,14 @@ bool KRSprite::getShaderValue(ShaderValue value, float* output) const return KRNode::getShaderValue(value, output); } } + +bool KRSprite::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const +{ + if (name == "spriteTexture") { + *binding = &m_spriteTexture.val; + *sample = getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER; + return true; + } else { + return KRNode::getImageBinding(name, binding, sample); + } +} diff --git a/kraken/nodes/KRSprite.h b/kraken/nodes/KRSprite.h index 0d26dd4..22d69e7 100755 --- a/kraken/nodes/KRSprite.h +++ b/kraken/nodes/KRSprite.h @@ -60,6 +60,7 @@ public: protected: bool getShaderValue(ShaderValue value, float* output) const override; + bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final; KRNODE_PROPERTY(KRTextureBinding, m_spriteTexture, KRTexture::TEXTURE_USAGE_SPRITE, "sprite_texture"); KRNODE_PROPERTY(float, m_spriteAlpha, 1.f, "sprite_alpha"); diff --git a/kraken/resources/material/KRMaterial.cpp b/kraken/resources/material/KRMaterial.cpp index 552ea3f..d81d152 100755 --- a/kraken/resources/material/KRMaterial.cpp +++ b/kraken/resources/material/KRMaterial.cpp @@ -825,28 +825,6 @@ bool KRMaterial::bind(KRNode::RenderInfo& ri, ModelFormat modelFormat, __uint32_ } } - if (bDiffuseMap) { - pShader->setImageBinding("diffuseTexture", m_baseColorMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER); - } - - if (bSpecMap) { - pShader->setImageBinding("specularTexture", m_specularColorMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER); - } - - if (bNormalMap) { - pShader->setImageBinding("normalTexture", m_normalMap.texture.get(), getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER); - } - - if (bReflectionCubeMap) { - // Deprecated by reflection cubes.. - // pShader->setImageBinding("reflectionCubeTexture", m_reflectionCube.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - } - - if (bReflectionMap) { - // Deprecated by PBR model.. - // pShader->setImageBinding("reflectionTexture", m_reflection.texture.get(), getContext().getSamplerManager()->DEFAULT_CLAMPED_SAMPLER); - } - bool success = true; ri.reflectedObjects.push_back(this); if (!pShader->bind(ri, matModel)) { @@ -1178,3 +1156,59 @@ bool KRMaterial::getShaderValue(ShaderValue value, bool* output) const return false; } } + +bool KRMaterial::getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const +{ + // TODO - Need to implement sampler selection / generation system + if (name == "baseColorTexture") { + *binding = &m_baseColorMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "normalTexture") { + *binding = &m_normalMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "emissiveTexture") { + *binding = &m_emissiveMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "occlusionTexture") { + *binding = &m_occlusionMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "metalicRoughnessTexture") { + *binding = &m_metalicRoughnessMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "anisotropyTexture") { + *binding = &m_anisotropyMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "clearcoatTexture") { + *binding = &m_clearcoatMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "clearcoatNormalTexture") { + *binding = &m_clearcoatNormalMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "specularTexture") { + *binding = &m_specularMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "specularColorTexture") { + *binding = &m_specularColorMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "thicknessTexture") { + *binding = &m_thicknessMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else if (name == "transmissionTexture") { + *binding = &m_transmissionMap.texture; + *sample = getContext().getSamplerManager()->DEFAULT_WRAPPING_SAMPLER; + return true; + } else { + return KRReflectedObject::getImageBinding(name, binding, sample); + } +} \ No newline at end of file diff --git a/kraken/resources/material/KRMaterial.h b/kraken/resources/material/KRMaterial.h index aebb1e9..5748d8c 100755 --- a/kraken/resources/material/KRMaterial.h +++ b/kraken/resources/material/KRMaterial.h @@ -190,4 +190,5 @@ private: bool getShaderValue(ShaderValue value, KRResourceBinding* output) const final; bool getShaderValue(ShaderValue value, int64_t* output) const final; bool getShaderValue(ShaderValue value, bool* output) const final; + bool getImageBinding(const std::string& name, const KRTextureBinding** binding, KRSampler** sample) const final; };