mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Add lightmap shader macos for native model (#13774)
* terrain support stationary light map fixed terrain light map shader compile error * fixed brush invalid material cause missing lighting map uniform * Add lightmap shader macros for model * fixed compile error * Add bakedStationaryMainLight jsb property for scene globals
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<scene::AmbientInfo> _ambientInfo;
|
||||
@@ -70,6 +72,7 @@ private:
|
||||
IntrusivePtr<scene::FogInfo> _fogInfo;
|
||||
IntrusivePtr<scene::OctreeInfo> _octreeInfo;
|
||||
IntrusivePtr<gi::LightProbeInfo> _lightProbeInfo;
|
||||
bool _bakedWithStationaryMainLight;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -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<cc::scene::IMacroPatch> SHADOW_MAP_PATCHES{{"CC_RECEIVE_SHADOW", true}};
|
||||
const ccstd::vector<cc::scene::IMacroPatch> LIGHT_PROBE_PATCHES{{"CC_USE_LIGHT_PROBE", true}};
|
||||
const ccstd::string CC_USE_REFLECTION_PROBE = "CC_USE_REFLECTION_PROBE";
|
||||
const ccstd::vector<cc::scene::IMacroPatch> STATIC_LIGHTMAP_PATHES{{"CC_USE_LIGHTMAP", 1}};
|
||||
const ccstd::vector<cc::scene::IMacroPatch> STATIONARY_LIGHTMAP_PATHES{{"CC_USE_LIGHTMAP", 2}};
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
@@ -430,6 +434,23 @@ ccstd::vector<IMacroPatch> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ------
|
||||
|
||||
Reference in New Issue
Block a user