diff --git a/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp b/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp index 17fcaf63f7..6c6ec34078 100644 --- a/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp +++ b/native/cocos/renderer/pipeline/PlanarShadowQueue.cpp @@ -22,11 +22,11 @@ THE SOFTWARE. ****************************************************************************/ +#include "PlanarShadowQueue.h" #include "Define.h" #include "InstancedBuffer.h" #include "PipelineSceneData.h" #include "PipelineStateManager.h" -#include "PlanarShadowQueue.h" #include "RenderInstancedQueue.h" #include "RenderPipeline.h" #include "core/geometry/AABB.h" @@ -153,7 +153,7 @@ void PlanarShadowQueue::destroy() { int PlanarShadowQueue::getShadowPassIndex(const scene::SubModel *subModel) const { int i = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { if (pass->getPhase() == _phaseID) { return i; } diff --git a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp index 11c7d8ed97..7738e05fda 100644 --- a/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ReflectionProbeBatchedQueue.cpp @@ -110,7 +110,7 @@ void ReflectionProbeBatchedQueue::clear() { void ReflectionProbeBatchedQueue::add(const scene::Model *model) { for (const auto &subModel : model->getSubModels()) { - //Filter transparent objects + // Filter transparent objects const bool isTransparent = subModel->getPass(0)->getBlendState()->targets[0].blend; if (isTransparent) { continue; @@ -187,7 +187,7 @@ bool ReflectionProbeBatchedQueue::isUseReflectMapPass(const scene::SubModel *sub int ReflectionProbeBatchedQueue::getDefaultPassIndex(const scene::SubModel *subModel) const { int i = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { if (pass->getPhase() == _phaseID) { return i; } @@ -198,7 +198,7 @@ int ReflectionProbeBatchedQueue::getDefaultPassIndex(const scene::SubModel *subM int ReflectionProbeBatchedQueue::getReflectMapPassIndex(const scene::SubModel *subModel) const { int i = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { if (pass->getPhase() == _phaseReflectMapID) { return i; } diff --git a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp index 94b51c5d12..befef224bd 100644 --- a/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp +++ b/native/cocos/renderer/pipeline/RenderAdditiveLightQueue.cpp @@ -486,7 +486,7 @@ bool RenderAdditiveLightQueue::getLightPassIndex(const scene::Model *model, ccst for (const auto &subModel : model->getSubModels()) { int lightPassIndex = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { if (pass->getPhase() == _phaseID) { hasValidLightPass = true; break; diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index 7801f3cffd..e79c49d1ea 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -158,7 +158,7 @@ void ShadowMapBatchedQueue::destroy() { int ShadowMapBatchedQueue::getShadowPassIndex(const scene::SubModel *subModel) const { int i = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { if (pass->getPhase() == _phaseID) { return i; } diff --git a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp index f5c413887c..bac169f08d 100644 --- a/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeExecutor.cpp @@ -2082,7 +2082,7 @@ void addRenderObject( const auto subModelCount = subModels.size(); for (uint32_t subModelIdx = 0; subModelIdx < subModelCount; ++subModelIdx) { const auto& subModel = subModels[subModelIdx]; - const auto& passes = subModel->getPasses(); + const auto& passes = *(subModel->getPasses()); const auto passCount = passes.size(); for (uint32_t passIdx = 0; passIdx < passCount; ++passIdx) { auto& pass = *passes[passIdx]; diff --git a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp index 8d7db93077..f3ba9a8290 100644 --- a/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/GbufferStage.cpp @@ -98,7 +98,7 @@ void GbufferStage::dispenseRenderObject2Queues() { const auto subModelCount = subModels.size(); for (subModelIdx = 0; subModelIdx < subModelCount; ++subModelIdx) { const auto &subModel = subModels[subModelIdx]; - const auto &passes = subModel->getPasses(); + const auto &passes = *(subModel->getPasses()); const auto passCount = passes.size(); for (passIdx = 0; passIdx < passCount; ++passIdx) { const auto &pass = passes[passIdx]; diff --git a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp index 5c1aace21e..d4ec5a806d 100644 --- a/native/cocos/renderer/pipeline/deferred/LightingStage.cpp +++ b/native/cocos/renderer/pipeline/deferred/LightingStage.cpp @@ -43,11 +43,11 @@ #include "gfx-base/GFXDevice.h" #include "pipeline/Define.h" #include "profiler/Profiler.h" +#include "scene/PointLight.h" +#include "scene/RangedDirectionalLight.h" #include "scene/RenderScene.h" #include "scene/SphereLight.h" #include "scene/SpotLight.h" -#include "scene/PointLight.h" -#include "scene/RangedDirectionalLight.h" namespace cc { namespace pipeline { @@ -263,8 +263,7 @@ void LightingStage::gatherLights(scene::Camera *camera) { if (sceneData->isHDR()) { tmpArray.w = light->getLuminanceHDR() * exposure * _lightMeterScale; - } - else { + } else { tmpArray.w = light->getLuminanceLDR(); } @@ -681,7 +680,7 @@ void LightingStage::putTransparentObj2Queue() { const auto *const model = ro.model; for (const auto &subModel : model->getSubModels()) { p = 0; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { // TODO(): need to fallback unlit and gizmo material. if (pass->getPhase() != _phaseID) continue; for (k = 0; k < _renderQueues.size(); k++) { @@ -970,7 +969,7 @@ void LightingStage::fgSsprPass(scene::Camera *camera) { const auto &subModels = model->getSubModels(); for (m = 0; m < subModels.size(); ++m) { const auto &subModel = subModels[m]; - const auto &passes = subModel->getPasses(); + const auto &passes = *(subModel->getPasses()); auto passCount = passes.size(); for (p = 0; p < passCount; ++p) { const auto &pass = passes[p]; diff --git a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp index 9837c1448a..2a96e05caf 100644 --- a/native/cocos/renderer/pipeline/forward/ForwardStage.cpp +++ b/native/cocos/renderer/pipeline/forward/ForwardStage.cpp @@ -108,7 +108,7 @@ void ForwardStage::dispenseRenderObject2Queues() { const auto subModelCount = subModels.size(); for (uint32_t subModelIdx = 0; subModelIdx < subModelCount; ++subModelIdx) { const auto &subModel = subModels[subModelIdx]; - const auto &passes = subModel->getPasses(); + const auto &passes = *(subModel->getPasses()); const auto passCount = passes.size(); for (uint32_t passIdx = 0; passIdx < passCount; ++passIdx) { const auto &pass = passes[passIdx]; diff --git a/native/cocos/scene/Model.cpp b/native/cocos/scene/Model.cpp index c85f8f2508..c5cfe23c18 100644 --- a/native/cocos/scene/Model.cpp +++ b/native/cocos/scene/Model.cpp @@ -38,10 +38,10 @@ #include "renderer/pipeline/custom/RenderInterfaceTypes.h" #include "scene/Model.h" #include "scene/Pass.h" +#include "scene/ReflectionProbe.h" +#include "scene/ReflectionProbeManager.h" #include "scene/RenderScene.h" #include "scene/SubModel.h" -#include "scene/ReflectionProbeManager.h" -#include "scene/ReflectionProbe.h" namespace { const cc::gfx::SamplerInfo LIGHTMAP_SAMPLER_HASH{ @@ -207,8 +207,8 @@ void Model::updateUBOs(uint32_t stamp) { _localBuffer->write(_lightmapUVParam, sizeof(float) * pipeline::UBOLocal::LIGHTINGMAP_UVPARAM); _localBuffer->write(_shadowBias, sizeof(float) * (pipeline::UBOLocal::LOCAL_SHADOW_BIAS)); - auto * probe = scene::ReflectionProbeManager::getInstance()->getReflectionProbeById(_reflectionProbeId); - auto * blendProbe = scene::ReflectionProbeManager::getInstance()->getReflectionProbeById(_reflectionProbeBlendId); + auto *probe = scene::ReflectionProbeManager::getInstance()->getReflectionProbeById(_reflectionProbeId); + auto *blendProbe = scene::ReflectionProbeManager::getInstance()->getReflectionProbeById(_reflectionProbeBlendId); if (probe) { if (probe->getProbeType() == scene::ReflectionProbe::ProbeType::PLANAR) { const Vec4 plane = {probe->getNode()->getUp().x, probe->getNode()->getUp().y, probe->getNode()->getUp().z, 1.F}; @@ -233,8 +233,8 @@ void Model::updateUBOs(uint32_t stamp) { const Vec4 boxSize = {boudingBox.x, boudingBox.y, boudingBox.z, static_cast(blendProbe->getCubeMap() ? blendProbe->getCubeMap()->mipmapLevel() + mipAndUseRGBE : 1 + mipAndUseRGBE)}; _localBuffer->write(boxSize, sizeof(float) * (pipeline::UBOLocal::REFLECTION_PROBE_BLEND_DATA2)); } else if (_reflectionProbeType == scene::UseReflectionProbeType::BLEND_PROBES_AND_SKYBOX) { - //blend with skybox - const Vec4 pos = { 0.F, 0.F, 0.F, _reflectionProbeBlendWeight }; + // blend with skybox + const Vec4 pos = {0.F, 0.F, 0.F, _reflectionProbeBlendWeight}; _localBuffer->write(pos, sizeof(float) * (pipeline::UBOLocal::REFLECTION_PROBE_BLEND_DATA1)); } } @@ -468,7 +468,7 @@ ccstd::vector Model::getMacroPatches(index_t subModelIndex) { } } - patches.push_back({CC_USE_REFLECTION_PROBE, static_cast(_reflectionProbeType) }); + patches.push_back({CC_USE_REFLECTION_PROBE, static_cast(_reflectionProbeType)}); if (_lightmap != nullptr) { bool stationary = false; @@ -516,7 +516,7 @@ void Model::updateAttributesAndBinding(index_t subModelIndex) { ccstd::vector attributes; ccstd::unordered_map attributeMap; - for (const auto &pass : subModel->getPasses()) { + for (const auto &pass : *(subModel->getPasses())) { gfx::Shader *shader = pass->getShaderVariant(subModel->getPatches()); for (const auto &attr : shader->getAttributes()) { if (attributeMap.find(attr.name) == attributeMap.end()) { diff --git a/native/cocos/scene/SubModel.cpp b/native/cocos/scene/SubModel.cpp index 709714e490..04db20f11e 100644 --- a/native/cocos/scene/SubModel.cpp +++ b/native/cocos/scene/SubModel.cpp @@ -92,7 +92,7 @@ void SubModel::update() { } } -void SubModel::setPasses(const std::shared_ptr>> &pPasses) { +void SubModel::setPasses(const SharedPassArray &pPasses) { if (!pPasses || pPasses->size() > MAX_PASS_COUNT) { debug::errorID(12004, MAX_PASS_COUNT); return; @@ -128,7 +128,7 @@ Pass *SubModel::getPass(uint32_t index) const { return passes[index]; } -void SubModel::initialize(RenderingSubMesh *subMesh, const std::shared_ptr>> &pPasses, const ccstd::vector &patches) { +void SubModel::initialize(RenderingSubMesh *subMesh, const SharedPassArray &pPasses, const ccstd::vector &patches) { _device = Root::getInstance()->getDevice(); CC_ASSERT(!pPasses->empty()); gfx::DescriptorSetInfo dsInfo; diff --git a/native/cocos/scene/SubModel.h b/native/cocos/scene/SubModel.h index 7f53b8acdb..3f2104f803 100644 --- a/native/cocos/scene/SubModel.h +++ b/native/cocos/scene/SubModel.h @@ -25,6 +25,8 @@ #pragma once #include +#include +#include "base/Ptr.h" #include "base/RefCounted.h" #include "core/assets/RenderingSubMesh.h" #include "renderer/gfx-base/GFXDescriptorSet.h" @@ -42,6 +44,8 @@ struct InstancedAttributeBlock { ccstd::vector attributes; }; +using SharedPassArray = std::shared_ptr>>; + class SubModel : public RefCounted { public: SubModel(); @@ -56,7 +60,7 @@ public: inline void setDescriptorSet(gfx::DescriptorSet *descriptorSet) { _descriptorSet = descriptorSet; } inline void setInputAssembler(gfx::InputAssembler *ia) { _inputAssembler = ia; } inline void setShaders(const ccstd::vector> &shaders) { _shaders = shaders; } - void setPasses(const std::shared_ptr>> &passes); + void setPasses(const SharedPassArray &passes); inline void setPriority(pipeline::RenderPriority priority) { _priority = priority; } inline void setOwner(Model *model) { _owner = model; } void setSubMesh(RenderingSubMesh *subMesh); @@ -68,7 +72,7 @@ public: inline gfx::DescriptorSet *getWorldBoundDescriptorSet() const { return _worldBoundDescriptorSet; } inline gfx::InputAssembler *getInputAssembler() const { return _inputAssembler; } inline const ccstd::vector> &getShaders() const { return _shaders; } - inline const ccstd::vector> &getPasses() const { return *_passes; } + inline const SharedPassArray &getPasses() const { return _passes; } inline const ccstd::vector &getPatches() const { return _patches; } inline pipeline::RenderPriority getPriority() const { return _priority; } inline RenderingSubMesh *getSubMesh() const { return _subMesh; } @@ -79,7 +83,7 @@ public: inline int32_t getInstancedSHIndex() const { return _instancedSHIndex; } int32_t getInstancedAttributeIndex(const ccstd::string &name) const; - void initialize(RenderingSubMesh *subMesh, const std::shared_ptr>> &passes, const ccstd::vector &patches); + void initialize(RenderingSubMesh *subMesh, const SharedPassArray &passes, const ccstd::vector &patches); void destroy(); void onPipelineStateChanged(); void onMacroPatchesStateChanged(const ccstd::vector &patches); @@ -114,7 +118,7 @@ protected: ccstd::vector _patches; ccstd::vector> _shaders; - std::shared_ptr>> _passes; + SharedPassArray _passes; int32_t _reflectionProbeType{0}; diff --git a/native/tools/swig-config/scene.i b/native/tools/swig-config/scene.i index fbba034dac..eeb2dc719d 100644 --- a/native/tools/swig-config/scene.i +++ b/native/tools/swig-config/scene.i @@ -481,7 +481,7 @@ using namespace cc; %attribute(cc::scene::Model, int32_t, reflectionProbeBlendId, getReflectionProbeBlendId, setReflectionProbeBlendId); %attribute(cc::scene::Model, float, reflectionProbeBlendWeight, getReflectionProbeBlendWeight, setReflectionProbeBlendWeight); -%attribute(cc::scene::SubModel, std::shared_ptr>> &, passes, getPasses, setPasses); +%attribute(cc::scene::SubModel, cc::scene::SharedPassArray &, passes, getPasses, setPasses); %attribute(cc::scene::SubModel, ccstd::vector> &, shaders, getShaders, setShaders); %attribute(cc::scene::SubModel, cc::RenderingSubMesh*, subMesh, getSubMesh, setSubMesh); %attribute(cc::scene::SubModel, cc::pipeline::RenderPriority, priority, getPriority, setPriority);