From 184c8a9c9175da0ea6a49367df1fc082f45f5dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=90=89=E6=9E=97?= <798080536@qq.com> Date: Tue, 22 Nov 2022 18:22:52 +0800 Subject: [PATCH] refactor light probe data (#13484) * refactor light probe data --- cocos/gi/light-probe/light-probe-group.ts | 7 +++-- cocos/render-scene/scene/model.ts | 2 +- cocos/rendering/custom/define.ts | 3 +- native/cocos/bindings/auto/jsb_gi_auto.cpp | 34 +++++++++------------- native/cocos/gi/light-probe/LightProbe.cpp | 25 +++++++++++----- native/cocos/gi/light-probe/LightProbe.h | 29 +++++++++--------- native/cocos/scene/Model.cpp | 4 +-- native/tools/swig-config/gi.i | 4 +-- 8 files changed, 59 insertions(+), 49 deletions(-) diff --git a/cocos/gi/light-probe/light-probe-group.ts b/cocos/gi/light-probe/light-probe-group.ts index fdf01bbc1e..f7071461dc 100644 --- a/cocos/gi/light-probe/light-probe-group.ts +++ b/cocos/gi/light-probe/light-probe-group.ts @@ -89,9 +89,10 @@ export class LightProbeGroup extends Component { get method () { return this._method; } - set method (val) { - this._method = val; - } + // Support this feature later. + // set method (val) { + // this._method = val; + // } /** * @en Minimum position of the light probe group diff --git a/cocos/render-scene/scene/model.ts b/cocos/render-scene/scene/model.ts index eb3a59123f..5e97f5d93d 100644 --- a/cocos/render-scene/scene/model.ts +++ b/cocos/render-scene/scene/model.ts @@ -40,7 +40,7 @@ import { Attribute, DescriptorSet, Device, Buffer, BufferInfo, import { UBOLocal, UBOSH, UBOWorldBound, UNIFORM_LIGHTMAP_TEXTURE_BINDING, UNIFORM_REFLECTION_PROBE_CUBEMAP_BINDING, UNIFORM_REFLECTION_PROBE_TEXTURE_BINDING } from '../../rendering/define'; import { Root } from '../../root'; import { TextureCube } from '../../asset/assets'; -import { ShadowType } from '.'; +import { ShadowType } from './shadows'; const m4_1 = new Mat4(); diff --git a/cocos/rendering/custom/define.ts b/cocos/rendering/custom/define.ts index df8779a5de..a533753765 100644 --- a/cocos/rendering/custom/define.ts +++ b/cocos/rendering/custom/define.ts @@ -170,7 +170,8 @@ export function buildFxaaPass (camera: Camera, ppl.addDepthStencil(fxaaPassDSName, Format.DEPTH_STENCIL, width, height, ResourceResidency.MANAGED); } const fxaaPassIdx = 0; - const fxaaPass = ppl.addRasterPass(width, height, 'fxaa', `CameraFxaaPass${cameraID}`); + const fxaaPass = ppl.addRasterPass(width, height, 'fxaa'); + fxaaPass.name = `CameraFxaaPass${cameraID}`; fxaaPass.setViewport(new Viewport(area.x, area.y, width, height)); if (ppl.containsResource(inputRT)) { const computeView = new ComputeView(); diff --git a/native/cocos/bindings/auto/jsb_gi_auto.cpp b/native/cocos/bindings/auto/jsb_gi_auto.cpp index 7870d8d672..242c827d15 100644 --- a/native/cocos/bindings/auto/jsb_gi_auto.cpp +++ b/native/cocos/bindings/auto/jsb_gi_auto.cpp @@ -2344,17 +2344,14 @@ static bool js_cc_gi_LightProbes_data_set(se::State& s) const auto& args = s.args(); size_t argc = args.size(); cc::gi::LightProbes *arg1 = (cc::gi::LightProbes *) NULL ; - cc::gi::LightProbesData *arg2 = 0 ; - cc::gi::LightProbesData temp2 ; + cc::gi::LightProbesData *arg2 = (cc::gi::LightProbesData *) NULL ; arg1 = SE_THIS_OBJECT(s); if (nullptr == arg1) return true; - ok &= sevalue_to_native(args[0], &temp2, s.thisObject()); - SE_PRECONDITION2(ok, false, "Error processing arguments"); - arg2 = &temp2; - - cc_gi_LightProbes_data_set(arg1,*arg2); + ok &= sevalue_to_native(args[0], &arg2, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + cc_gi_LightProbes_data_set(arg1,arg2); return true; @@ -2369,11 +2366,11 @@ static bool js_cc_gi_LightProbes_data_get(se::State& s) arg1 = SE_THIS_OBJECT(s); if (nullptr == arg1) return true; - result = (cc::gi::LightProbesData *) &cc_gi_LightProbes_data_get(arg1); + result = (cc::gi::LightProbesData *)cc_gi_LightProbes_data_get(arg1); - ok &= nativevalue_to_se(*result, s.rval(), s.thisObject()); + ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); SE_PRECONDITION2(ok, false, "Error processing arguments"); - SE_HOLD_RETURN_VALUE(*result, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); return true; @@ -3194,17 +3191,14 @@ static bool js_cc_gi_LightProbeInfo_data_set(se::State& s) const auto& args = s.args(); size_t argc = args.size(); cc::gi::LightProbeInfo *arg1 = (cc::gi::LightProbeInfo *) NULL ; - cc::gi::LightProbesData *arg2 = 0 ; - cc::gi::LightProbesData temp2 ; + cc::gi::LightProbesData *arg2 = (cc::gi::LightProbesData *) NULL ; arg1 = SE_THIS_OBJECT(s); if (nullptr == arg1) return true; - ok &= sevalue_to_native(args[0], &temp2, s.thisObject()); - SE_PRECONDITION2(ok, false, "Error processing arguments"); - arg2 = &temp2; - - cc_gi_LightProbeInfo_data_set(arg1,*arg2); + ok &= sevalue_to_native(args[0], &arg2, s.thisObject()); + SE_PRECONDITION2(ok, false, "Error processing arguments"); + cc_gi_LightProbeInfo_data_set(arg1,arg2); return true; @@ -3219,11 +3213,11 @@ static bool js_cc_gi_LightProbeInfo_data_get(se::State& s) arg1 = SE_THIS_OBJECT(s); if (nullptr == arg1) return true; - result = (cc::gi::LightProbesData *) &cc_gi_LightProbeInfo_data_get(arg1); + result = (cc::gi::LightProbesData *)cc_gi_LightProbeInfo_data_get(arg1); - ok &= nativevalue_to_se(*result, s.rval(), s.thisObject()); + ok &= nativevalue_to_se(result, s.rval(), s.thisObject()); SE_PRECONDITION2(ok, false, "Error processing arguments"); - SE_HOLD_RETURN_VALUE(*result, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); return true; diff --git a/native/cocos/gi/light-probe/LightProbe.cpp b/native/cocos/gi/light-probe/LightProbe.cpp index 1885d99d63..ee8759462d 100644 --- a/native/cocos/gi/light-probe/LightProbe.cpp +++ b/native/cocos/gi/light-probe/LightProbe.cpp @@ -27,10 +27,10 @@ #include "LightProbe.h" #include "PolynomialSolver.h" #include "core/Root.h" +#include "core/scene-graph/Scene.h" #include "math/Math.h" #include "math/Utils.h" #include "renderer/pipeline/custom/RenderInterfaceTypes.h" -#include "core/scene-graph/Scene.h" namespace cc { namespace gi { @@ -200,14 +200,18 @@ void LightProbes::initialize(LightProbeInfo *info) { _data = info->getData(); } -void LightProbeInfo::activate(Scene* scene, LightProbes *resource) { +void LightProbeInfo::activate(Scene *scene, LightProbes *resource) { _scene = scene; _resource = resource; _resource->initialize(this); } void LightProbeInfo::clearSHCoefficients() { - auto &probes = _data.getProbes(); + if (!_data) { + return; + } + + auto &probes = _data->getProbes(); for (auto &probe : probes) { probe.coefficients.clear(); } @@ -215,7 +219,7 @@ void LightProbeInfo::clearSHCoefficients() { clearAllSHUBOs(); } -bool LightProbeInfo::addNode(Node* node) { +bool LightProbeInfo::addNode(Node *node) { if (!node) { return false; } @@ -256,6 +260,13 @@ void LightProbeInfo::syncData(Node *node, const ccstd::vector &probes) { } void LightProbeInfo::update(bool updateTet) { + if (!_data) { + _data = new LightProbesData(); + if (_resource) { + _resource->setData(_data); + } + } + ccstd::vector points; for (auto &item : _nodes) { @@ -271,15 +282,15 @@ void LightProbeInfo::update(bool updateTet) { auto pointCount = points.size(); if (pointCount < 4) { resetAllTetraIndices(); - _data.reset(); + _data->reset(); return; } - _data.updateProbes(points); + _data->updateProbes(points); if (updateTet) { resetAllTetraIndices(); - _data.updateTetrahedrons(); + _data->updateTetrahedrons(); } } diff --git a/native/cocos/gi/light-probe/LightProbe.h b/native/cocos/gi/light-probe/LightProbe.h index 5126f5a7ff..f62702bf99 100644 --- a/native/cocos/gi/light-probe/LightProbe.h +++ b/native/cocos/gi/light-probe/LightProbe.h @@ -29,6 +29,7 @@ #include "Delaunay.h" #include "SH.h" #include "base/Macros.h" +#include "base/Ptr.h" #include "base/RefCounted.h" #include "base/std/container/vector.h" #include "math/Vec3.h" @@ -42,7 +43,7 @@ namespace gi { class LightProbeInfo; -class LightProbesData { +class LightProbesData : public RefCounted { public: LightProbesData() = default; @@ -82,7 +83,11 @@ public: void initialize(LightProbeInfo *info); inline bool empty() const { - return _data.empty(); + if (!_data) { + return true; + } + + return _data->empty(); } inline void setGIScale(float val) { _giScale = val; } @@ -106,8 +111,8 @@ public: inline void setShowConvex(bool val) { _showConvex = val; } inline bool isShowConvex() const { return _showConvex; } - inline void setData(const LightProbesData &data) { _data = data; } - inline const LightProbesData &getData() const { return _data; } + inline void setData(LightProbesData *data) { _data = data; } + inline LightProbesData *getData() const { return _data.get(); } float _giScale{1.0F}; uint32_t _giSamples{1024U}; @@ -116,14 +121,14 @@ public: bool _showProbe{true}; bool _showWireframe{true}; bool _showConvex{false}; - LightProbesData _data; + IntrusivePtr _data; }; struct ILightProbeNode { Node *node{nullptr}; ccstd::vector probes; - explicit ILightProbeNode(Node* n) + explicit ILightProbeNode(Node *n) : node(n) {} }; @@ -132,9 +137,9 @@ public: LightProbeInfo() = default; ~LightProbeInfo() override = default; - void activate(Scene* scene, LightProbes *resource); + void activate(Scene *scene, LightProbes *resource); void clearSHCoefficients(); - inline bool isUniqueNode() const { return _nodes.size() == 1;} + inline bool isUniqueNode() const { return _nodes.size() == 1; } bool addNode(Node *node); bool removeNode(Node *node); void syncData(Node *node, const ccstd::vector &probes); @@ -224,16 +229,14 @@ public: } inline bool isShowConvex() const { return _showConvex; } - inline void setData(const LightProbesData &data) { + inline void setData(LightProbesData *data) { _data = data; if (_resource) { _resource->setData(data); } } - inline const LightProbesData &getData() const { return _data; } - - // add addGroup, removeGroup, update after the component module is ported to cpp + inline LightProbesData *getData() const { return _data.get(); } //cjh JSB need to bind the property, so need to make it public float _giScale{1.0F}; @@ -243,7 +246,7 @@ public: bool _showProbe{true}; bool _showWireframe{true}; bool _showConvex{false}; - LightProbesData _data; + IntrusivePtr _data; private: void clearAllSHUBOs(); diff --git a/native/cocos/scene/Model.cpp b/native/cocos/scene/Model.cpp index 74a00e518c..69bbf9275f 100644 --- a/native/cocos/scene/Model.cpp +++ b/native/cocos/scene/Model.cpp @@ -389,8 +389,8 @@ void Model::updateSHUBOs() { const auto *lightProbes = pipeline->getPipelineSceneData()->getLightProbes(); _lastWorldBoundCenter.set(center); - _tetrahedronIndex = lightProbes->getData().getInterpolationWeights(center, _tetrahedronIndex, weights); - bool result = lightProbes->getData().getInterpolationSHCoefficients(_tetrahedronIndex, weights, coefficients); + _tetrahedronIndex = lightProbes->getData()->getInterpolationWeights(center, _tetrahedronIndex, weights); + bool result = lightProbes->getData()->getInterpolationSHCoefficients(_tetrahedronIndex, weights, coefficients); if (!result) { return; } diff --git a/native/tools/swig-config/gi.i b/native/tools/swig-config/gi.i index 3d48999f5e..08577c36b0 100644 --- a/native/tools/swig-config/gi.i +++ b/native/tools/swig-config/gi.i @@ -94,7 +94,7 @@ using namespace cc::gi; %attribute(cc::gi::LightProbes, bool, showProbe, isShowProbe, setShowProbe); %attribute(cc::gi::LightProbes, bool, showWireframe, isShowWireframe, setShowWireframe); %attribute(cc::gi::LightProbes, bool, showConvex, isShowConvex, setShowConvex); -%attribute(cc::gi::LightProbes, cc::gi::LightProbesData&, data, getData, setData); +%attribute(cc::gi::LightProbes, cc::gi::LightProbesData*, data, getData, setData); %attribute(cc::gi::LightProbeInfo, float, giScale, getGIScale, setGIScale); %attribute(cc::gi::LightProbeInfo, uint32_t, giSamples, getGISamples, setGISamples); @@ -103,7 +103,7 @@ using namespace cc::gi; %attribute(cc::gi::LightProbeInfo, bool, showProbe, isShowProbe, setShowProbe); %attribute(cc::gi::LightProbeInfo, bool, showWireframe, isShowWireframe, setShowWireframe); %attribute(cc::gi::LightProbeInfo, bool, showConvex, isShowConvex, setShowConvex); -%attribute(cc::gi::LightProbeInfo, cc::gi::LightProbesData&, data, getData, setData); +%attribute(cc::gi::LightProbeInfo, cc::gi::LightProbesData*, data, getData, setData); // ----- Import Section ------ // Brief: Import header files which are depended by 'Include Section'