mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
fix planar reflection update submodel macro patches (#15316)
This commit is contained in:
@@ -515,7 +515,7 @@ export class Pass {
|
||||
* @zh 结合指定的编译宏组合获取当前 Pass 的 Shader Variant
|
||||
* @param patches The macro patches
|
||||
*/
|
||||
public getShaderVariant (patches: IMacroPatch[] | null = null): Shader | null {
|
||||
public getShaderVariant (patches: Readonly<IMacroPatch[] | null> = null): Shader | null {
|
||||
if (!this._shader && !this.tryCompile()) {
|
||||
console.warn('pass resources incomplete');
|
||||
return null;
|
||||
|
||||
@@ -337,7 +337,7 @@ export class Shadows {
|
||||
* @param patches The macro patches for the shader
|
||||
* @returns The shader for the planar shadow
|
||||
*/
|
||||
public getPlanarShader (patches: IMacroPatch[] | null): Shader | null {
|
||||
public getPlanarShader (patches: Readonly<IMacroPatch[] | null>): Shader | null {
|
||||
if (!this._material) {
|
||||
this._material = new Material();
|
||||
this._material.initialize({ effectName: 'pipeline/planar-shadow' });
|
||||
|
||||
@@ -159,7 +159,7 @@ export class SubModel {
|
||||
* @en The macro patches for the shaders
|
||||
* @zh 着色器程序所用的宏定义组合
|
||||
*/
|
||||
get patches (): IMacroPatch[] | null {
|
||||
get patches (): Readonly<IMacroPatch[] | null> {
|
||||
return this._patches;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ export class RenderReflectionProbeQueue {
|
||||
private _shaderArray: Shader[] = [];
|
||||
private _rgbeSubModelsArray: SubModel[]=[]
|
||||
private _instancedQueue: RenderInstancedQueue;
|
||||
private _patches: IMacroPatch[] = [];
|
||||
|
||||
public constructor (pipeline: PipelineRuntime) {
|
||||
this._pipeline = pipeline;
|
||||
@@ -151,12 +152,13 @@ export class RenderReflectionProbeQueue {
|
||||
const batchingScheme = pass.batchingScheme;
|
||||
|
||||
if (!bUseReflectPass) {
|
||||
let patches: IMacroPatch[] | null = subModel.patches;
|
||||
this._patches = [];
|
||||
this._patches = this._patches.concat(subModel.patches!);
|
||||
const useRGBEPatchs: IMacroPatch[] = [
|
||||
{ name: CC_USE_RGBE_OUTPUT, value: true },
|
||||
];
|
||||
patches = patches ? patches.concat(useRGBEPatchs) : useRGBEPatchs;
|
||||
subModel.onMacroPatchesStateChanged(patches);
|
||||
this._patches = this._patches.concat(useRGBEPatchs);
|
||||
subModel.onMacroPatchesStateChanged(this._patches);
|
||||
this._rgbeSubModelsArray.push(subModel);
|
||||
}
|
||||
|
||||
@@ -199,18 +201,19 @@ export class RenderReflectionProbeQueue {
|
||||
}
|
||||
public resetRGBEMacro () {
|
||||
for (let i = 0; i < this._rgbeSubModelsArray.length; i++) {
|
||||
this._patches = [];
|
||||
const subModel = this._rgbeSubModelsArray[i];
|
||||
// eslint-disable-next-line prefer-const
|
||||
let patches: IMacroPatch[] | null = subModel.patches;
|
||||
if (!patches) continue;
|
||||
for (let j = 0; j < patches.length; j++) {
|
||||
const patch = patches[j];
|
||||
this._patches = this._patches.concat(subModel.patches!);
|
||||
if (!this._patches) continue;
|
||||
for (let j = 0; j < this._patches.length; j++) {
|
||||
const patch = this._patches[j];
|
||||
if (patch.name === CC_USE_RGBE_OUTPUT) {
|
||||
patches.splice(j, 1);
|
||||
this._patches.splice(j, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
subModel.onMacroPatchesStateChanged(patches);
|
||||
subModel.onMacroPatchesStateChanged(this._patches);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +130,12 @@ void ReflectionProbeBatchedQueue::add(const scene::Model *model) {
|
||||
const auto batchingScheme = pass->getBatchingScheme();
|
||||
|
||||
if (!bUseReflectPass) {
|
||||
auto patches = const_cast<ccstd::vector<cc::scene::IMacroPatch> &>(subModel->getPatches());
|
||||
patches.emplace_back(MACRO_PATCH_RGBE_OUTPUT);
|
||||
subModel->onMacroPatchesStateChanged(patches);
|
||||
_patches.clear();
|
||||
for (const auto &patch : subModel->getPatches()) {
|
||||
_patches.push_back(patch);
|
||||
}
|
||||
_patches.emplace_back(MACRO_PATCH_RGBE_OUTPUT);
|
||||
subModel->onMacroPatchesStateChanged(_patches);
|
||||
_rgbeSubModels.emplace_back(subModel);
|
||||
}
|
||||
|
||||
@@ -148,7 +151,7 @@ void ReflectionProbeBatchedQueue::add(const scene::Model *model) {
|
||||
}
|
||||
}
|
||||
|
||||
void ReflectionProbeBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) const {
|
||||
void ReflectionProbeBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::RenderPass *renderPass, gfx::CommandBuffer *cmdBuffer) {
|
||||
_instancedQueue->recordCommandBuffer(device, renderPass, cmdBuffer);
|
||||
|
||||
for (size_t i = 0; i < _subModels.size(); i++) {
|
||||
@@ -167,13 +170,16 @@ void ReflectionProbeBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::
|
||||
resetMacro();
|
||||
if (_instancedQueue) _instancedQueue->clear();
|
||||
}
|
||||
void ReflectionProbeBatchedQueue::resetMacro() const {
|
||||
void ReflectionProbeBatchedQueue::resetMacro() {
|
||||
for (const auto &subModel : _rgbeSubModels) {
|
||||
auto patches = const_cast<ccstd::vector<cc::scene::IMacroPatch> &>(subModel->getPatches());
|
||||
for (auto iter = patches.begin(); iter != patches.end(); iter++) {
|
||||
_patches.clear();
|
||||
for (const auto &patch : subModel->getPatches()) {
|
||||
_patches.push_back(patch);
|
||||
}
|
||||
for (auto iter = _patches.begin(); iter != _patches.end(); iter++) {
|
||||
if (iter->name == CC_USE_RGBE_OUTPUT) {
|
||||
patches.erase(iter);
|
||||
const_cast<scene::SubModel *>(subModel)->onMacroPatchesStateChanged(patches);
|
||||
_patches.erase(iter);
|
||||
const_cast<scene::SubModel *>(subModel)->onMacroPatchesStateChanged(_patches);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "Define.h"
|
||||
#include "cocos/base/Macros.h"
|
||||
#include "scene/Define.h"
|
||||
namespace cc {
|
||||
namespace scene {
|
||||
class Camera;
|
||||
@@ -48,9 +49,9 @@ public:
|
||||
void clear();
|
||||
void gatherRenderObjects(const scene::Camera *, gfx::CommandBuffer *, const scene::ReflectionProbe *probe);
|
||||
void add(const scene::Model *);
|
||||
void recordCommandBuffer(gfx::Device *, gfx::RenderPass *, gfx::CommandBuffer *) const;
|
||||
void recordCommandBuffer(gfx::Device *, gfx::RenderPass *, gfx::CommandBuffer *);
|
||||
|
||||
void resetMacro() const;
|
||||
void resetMacro();
|
||||
|
||||
bool isUseReflectMapPass(const scene::SubModel *subModel) const;
|
||||
|
||||
@@ -71,6 +72,7 @@ private:
|
||||
uint32_t _phaseID{0};
|
||||
uint32_t _phaseReflectMapID{0};
|
||||
ccstd::vector<const scene::SubModel *> _rgbeSubModels;
|
||||
ccstd::vector<scene::IMacroPatch> _patches;
|
||||
};
|
||||
|
||||
} // namespace pipeline
|
||||
|
||||
Reference in New Issue
Block a user