diff --git a/native/cocos/core/scene-graph/SceneGlobals.cpp b/native/cocos/core/scene-graph/SceneGlobals.cpp index 869e03614f..67f9d93f7b 100644 --- a/native/cocos/core/scene-graph/SceneGlobals.cpp +++ b/native/cocos/core/scene-graph/SceneGlobals.cpp @@ -43,6 +43,7 @@ SceneGlobals::SceneGlobals() { _fogInfo = ccnew scene::FogInfo(); _octreeInfo = ccnew scene::OctreeInfo(); _lightProbeInfo = ccnew gi::LightProbeInfo(); + _bakedWithStationaryMainLight = false; } void SceneGlobals::activate(Scene* scene) { @@ -98,4 +99,8 @@ void SceneGlobals::setLightProbeInfo(gi::LightProbeInfo *info) { _lightProbeInfo = info; } +void SceneGlobals::setBakedWithStationaryMainLight(bool value) { + _bakedWithStationaryMainLight = value; +} + } // namespace cc diff --git a/native/cocos/core/scene-graph/SceneGlobals.h b/native/cocos/core/scene-graph/SceneGlobals.h index d7acb2249f..0a0e72bdc5 100644 --- a/native/cocos/core/scene-graph/SceneGlobals.h +++ b/native/cocos/core/scene-graph/SceneGlobals.h @@ -55,6 +55,7 @@ public: inline scene::FogInfo *getFogInfo() const { return _fogInfo.get(); } inline scene::OctreeInfo *getOctreeInfo() const { return _octreeInfo.get(); } inline gi::LightProbeInfo *getLightProbeInfo() const { return _lightProbeInfo.get(); } + inline bool getBakedWithStationaryMainLight() const { return _bakedWithStationaryMainLight; } void setAmbientInfo(scene::AmbientInfo *info); void setShadowsInfo(scene::ShadowsInfo *info); @@ -62,6 +63,7 @@ public: void setFogInfo(scene::FogInfo *info); void setOctreeInfo(scene::OctreeInfo *info); void setLightProbeInfo(gi::LightProbeInfo *info); + void setBakedWithStationaryMainLight(bool value); private: IntrusivePtr _ambientInfo; @@ -70,6 +72,7 @@ private: IntrusivePtr _fogInfo; IntrusivePtr _octreeInfo; IntrusivePtr _lightProbeInfo; + bool _bakedWithStationaryMainLight; }; } // namespace cc diff --git a/native/cocos/scene/Model.cpp b/native/cocos/scene/Model.cpp index 0070d24ba7..4ca12a24a7 100644 --- a/native/cocos/scene/Model.cpp +++ b/native/cocos/scene/Model.cpp @@ -28,6 +28,8 @@ #include "core/Root.h" #include "core/TypedArray.h" #include "core/assets/Material.h" +#include "core/scene-graph/Scene.h" +#include "core/scene-graph/SceneGlobals.h" #include "gfx-base/GFXTexture.h" #include "gi/light-probe/LightProbe.h" #include "gi/light-probe/SH.h" @@ -62,6 +64,8 @@ const cc::gfx::SamplerInfo LIGHTMAP_SAMPLER_WITH_MIP_HASH{ const ccstd::vector SHADOW_MAP_PATCHES{{"CC_RECEIVE_SHADOW", true}}; const ccstd::vector LIGHT_PROBE_PATCHES{{"CC_USE_LIGHT_PROBE", true}}; const ccstd::string CC_USE_REFLECTION_PROBE = "CC_USE_REFLECTION_PROBE"; +const ccstd::vector STATIC_LIGHTMAP_PATHES{{"CC_USE_LIGHTMAP", 1}}; +const ccstd::vector STATIONARY_LIGHTMAP_PATHES{{"CC_USE_LIGHTMAP", 2}}; } // namespace namespace cc { @@ -430,6 +434,23 @@ ccstd::vector Model::getMacroPatches(index_t subModelIndex) { patches.push_back({CC_USE_REFLECTION_PROBE, _reflectionProbeType}); + if (_lightmap != nullptr) { + bool stationary = false; + if (getNode() != nullptr && getNode()->getScene() != nullptr) { + stationary = getNode()->getScene()->getSceneGlobals()->getBakedWithStationaryMainLight(); + } + + if (stationary) { + for (const auto &patch : STATIONARY_LIGHTMAP_PATHES) { + patches.push_back(patch); + } + } else { + for (const auto &patch : STATIC_LIGHTMAP_PATHES) { + patches.push_back(patch); + } + } + } + return patches; } diff --git a/native/tools/swig-config/scene.i b/native/tools/swig-config/scene.i index f9a45a920f..123830bf8a 100644 --- a/native/tools/swig-config/scene.i +++ b/native/tools/swig-config/scene.i @@ -536,6 +536,7 @@ using namespace cc; %attribute(cc::scene::ReflectionProbe, cc::Node*, previewSphere, getPreviewSphere, setPreviewSphere); %attribute(cc::scene::ReflectionProbe, cc::Node*, previewPlane, getPreviewPlane, setPreviewPlane); +%attribute(cc::SceneGlobals, bool, bakedWithStationaryMainLight, getBakedWithStationaryMainLight, setBakedWithStationaryMainLight); // ----- Import Section ------