diff --git a/cocos/3d/reflection-probe/reflection-probe-manager.ts b/cocos/3d/reflection-probe/reflection-probe-manager.ts index 0db046614e..bae124d2d4 100644 --- a/cocos/3d/reflection-probe/reflection-probe-manager.ts +++ b/cocos/3d/reflection-probe/reflection-probe-manager.ts @@ -33,6 +33,7 @@ import { Texture } from '../../gfx'; import { Camera, Model } from '../../render-scene/scene'; import { ProbeType, ReflectionProbe } from '../../render-scene/scene/reflection-probe'; import { Layers } from '../../scene-graph/layers'; +import { ENABLE_PROBE_BLEND } from '../../rendering/define'; const REFLECTION_PROBE_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, Layers.BitMask.UI_3D, Layers.BitMask.GIZMOS, Layers.BitMask.EDITOR, Layers.BitMask.SCENE_GIZMO, Layers.BitMask.PROFILER, Layers.Enum.IGNORE_RAYCAST]); @@ -653,7 +654,7 @@ export class ReflectionProbeManager { if (!meshRender) { return; } - if (blendProbe) { + if (ENABLE_PROBE_BLEND && blendProbe) { meshRender.updateReflectionProbeBlendId(blendProbe.getProbeId()); meshRender.updateProbeBlendCubemap(blendProbe.cubemap); meshRender.updateReflectionProbeBlendWeight(this._calculateBlendWeight(model, probe, blendProbe)); diff --git a/cocos/render-scene/scene/model.ts b/cocos/render-scene/scene/model.ts index 936335b769..272c94ca13 100644 --- a/cocos/render-scene/scene/model.ts +++ b/cocos/render-scene/scene/model.ts @@ -41,6 +41,7 @@ import { UBOLocalEnum, UBOSH, UBOSHEnum, UBOWorldBound, UNIFORM_LIGHTMAP_TEXTURE_BINDING, UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING, UNIFORM_REFLECTION_PROBE_CUBEMAP_BINDING, UNIFORM_REFLECTION_PROBE_DATA_MAP_BINDING, UNIFORM_REFLECTION_PROBE_TEXTURE_BINDING, + ENABLE_PROBE_BLEND, } from '../../rendering/define'; import { Root } from '../../root'; import { TextureCube } from '../../asset/assets'; @@ -1014,6 +1015,9 @@ export class Model { * @param texture probe cubemap */ public updateReflectionProbeBlendCubemap (texture: TextureCube | null): void { + if (!ENABLE_PROBE_BLEND) { // Disable probe blend for WebGPU + return; + } this._localDataUpdated = true; this.onMacroPatchesStateChanged(); diff --git a/cocos/rendering/define.ts b/cocos/rendering/define.ts index 127022adf0..1f5f2eabbe 100644 --- a/cocos/rendering/define.ts +++ b/cocos/rendering/define.ts @@ -153,7 +153,7 @@ export enum ModelLocalBindings { SAMPLER_REFLECTION_PROBE_CUBE, SAMPLER_REFLECTION_PROBE_PLANAR, SAMPLER_REFLECTION_PROBE_DATA_MAP, - SAMPLER_REFLECTION_PROBE_BLEND_CUBE, + // SAMPLER_REFLECTION_PROBE_BLEND_CUBE, // Disable for WebGPU COUNT, } @@ -1024,7 +1024,7 @@ localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_PROBE_DATA_MAP_BINDING] = U * @zh 用于blend的反射探针立方体贴图纹理采样器。 */ const UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_NAME = 'cc_reflectionProbeBlendCubemap'; -export const UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING = ModelLocalBindings.SAMPLER_REFLECTION_PROBE_BLEND_CUBE; +export const UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING = ModelLocalBindings.SAMPLER_REFLECTION_PROBE_DATA_MAP + 1; // SAMPLER_REFLECTION_PROBE_BLEND_CUBE const UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_DESCRIPTOR = new DescriptorSetLayoutBinding( UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING, DescriptorType.SAMPLER_TEXTURE, @@ -1040,8 +1040,14 @@ const UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_LAYOUT = new UniformSamplerTexture( Type.SAMPLER_CUBE, 1, ); -localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_NAME] = UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_LAYOUT; -localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING] = UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_DESCRIPTOR; +/** + * @engineInternal + */ +export const ENABLE_PROBE_BLEND = false; +if (ENABLE_PROBE_BLEND) { + localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_NAME] = UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_LAYOUT; + localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING] = UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_DESCRIPTOR; +} export const CAMERA_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, Layers.BitMask.GIZMOS, Layers.BitMask.EDITOR, Layers.BitMask.SCENE_GIZMO, Layers.BitMask.PROFILER]); diff --git a/cocos/rendering/instanced-buffer.ts b/cocos/rendering/instanced-buffer.ts index 5ea76ec2dc..41a74af3a1 100644 --- a/cocos/rendering/instanced-buffer.ts +++ b/cocos/rendering/instanced-buffer.ts @@ -25,7 +25,7 @@ import { Pass } from '../render-scene'; import { SubModel } from '../render-scene/scene'; import { UNIFORM_LIGHTMAP_TEXTURE_BINDING, UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING, UNIFORM_REFLECTION_PROBE_CUBEMAP_BINDING, - UNIFORM_REFLECTION_PROBE_TEXTURE_BINDING } from './define'; + UNIFORM_REFLECTION_PROBE_TEXTURE_BINDING, ENABLE_PROBE_BLEND } from './define'; import { BufferUsageBit, MemoryUsageBit, Device, Texture, InputAssembler, InputAssemblerInfo, Attribute, Buffer, BufferInfo, CommandBuffer, Shader, DescriptorSet } from '../gfx'; @@ -42,7 +42,7 @@ export interface IInstancedItem { reflectionProbeCubemap: Texture; reflectionProbePlanarMap: Texture; useReflectionProbeType: number; - reflectionProbeBlendCubemap: Texture; + reflectionProbeBlendCubemap: Texture | null; } const INITIAL_CAPACITY = 32; @@ -77,7 +77,9 @@ export class InstancedBuffer { const lightingMap = subModelDescriptorSet.getTexture(UNIFORM_LIGHTMAP_TEXTURE_BINDING); const reflectionProbeCubemap = subModelDescriptorSet.getTexture(UNIFORM_REFLECTION_PROBE_CUBEMAP_BINDING); const reflectionProbePlanarMap = subModelDescriptorSet.getTexture(UNIFORM_REFLECTION_PROBE_TEXTURE_BINDING); - const reflectionProbeBlendCubemap = subModelDescriptorSet.getTexture(UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING); + const reflectionProbeBlendCubemap = ENABLE_PROBE_BLEND + ? subModelDescriptorSet.getTexture(UNIFORM_REFLECTION_PROBE_BLEND_CUBEMAP_BINDING) + : null; const useReflectionProbeType = subModel.useReflectionProbeType; let shader = shaderImplant; if (!shader) { @@ -102,7 +104,7 @@ export class InstancedBuffer { if (instance.reflectionProbePlanarMap.objectID !== reflectionProbePlanarMap.objectID) { continue; } - if (instance.reflectionProbeBlendCubemap.objectID !== reflectionProbeBlendCubemap.objectID) { + if (ENABLE_PROBE_BLEND && instance.reflectionProbeBlendCubemap!.objectID !== reflectionProbeBlendCubemap!.objectID) { continue; } diff --git a/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk b/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk index 8905121dc2..2524b3a699 100644 --- a/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk +++ b/editor/assets/chunks/builtin/uniforms/cc-reflection-probe.chunk @@ -9,5 +9,6 @@ layout(set = 2, binding = 14) uniform sampler2D cc_reflectionProbePlanarMap; #pragma builtin(local) layout(set = 2, binding = 15) uniform sampler2D cc_reflectionProbeDataMap; -#pragma builtin(local) -layout(set = 2, binding = 16) uniform samplerCube cc_reflectionProbeBlendCubemap; +// Disable proble blend for WebGPU +// #pragma builtin(local) +// layout(set = 2, binding = 16) uniform samplerCube cc_reflectionProbeBlendCubemap; diff --git a/editor/assets/chunks/legacy/shading-standard-base.chunk b/editor/assets/chunks/legacy/shading-standard-base.chunk index 08ed385c87..67419a0332 100644 --- a/editor/assets/chunks/legacy/shading-standard-base.chunk +++ b/editor/assets/chunks/legacy/shading-standard-base.chunk @@ -263,14 +263,16 @@ vec4 CCStandardShadingBase (StandardSurface s, vec4 shadowPos) { #else env = mix(skyBoxEnv, env, fixedR.w); #endif - } else { - vec3 centerPosBlend, boxHalfSizeBlend; - float mipCountBlend; - GetBlendCubeReflectionProbeData(centerPosBlend, boxHalfSizeBlend, mipCountBlend, s.reflectionProbeBlendId); - vec4 fixedRBlend = CalculateBoxProjectedDirection(R, s.position, centerPosBlend, boxHalfSizeBlend); - vec3 probe1 = SampleReflectionProbe(cc_reflectionProbeBlendCubemap, fixedRBlend.xyz, s.roughness, mipCountBlend, isBlendReflectProbeUsingRGBE(s.reflectionProbeBlendId)); - env = mix(env, probe1, s.reflectionProbeBlendFactor); } + // Disable probe blend for WebGPU + // else { + // vec3 centerPosBlend, boxHalfSizeBlend; + // float mipCountBlend; + // GetBlendCubeReflectionProbeData(centerPosBlend, boxHalfSizeBlend, mipCountBlend, s.reflectionProbeBlendId); + // vec4 fixedRBlend = CalculateBoxProjectedDirection(R, s.position, centerPosBlend, boxHalfSizeBlend); + // vec3 probe1 = SampleReflectionProbe(cc_reflectionProbeBlendCubemap, fixedRBlend.xyz, s.roughness, mipCountBlend, isBlendReflectProbeUsingRGBE(s.reflectionProbeBlendId)); + // env = mix(env, probe1, s.reflectionProbeBlendFactor); + // } } #endif #endif diff --git a/editor/assets/chunks/lighting-models/model-functions/standard-common.chunk b/editor/assets/chunks/lighting-models/model-functions/standard-common.chunk index f2d4c75844..0133ed55fd 100644 --- a/editor/assets/chunks/lighting-models/model-functions/standard-common.chunk +++ b/editor/assets/chunks/lighting-models/model-functions/standard-common.chunk @@ -206,13 +206,15 @@ vec3 CalculateEnvironmentSpecular(in LightingIntermediateData lightingData, floa vec4 fixedR = CalculateBoxProjectedDirection(R, worldPos, centerPos, boxHalfSize); envSpec = mix(skyBoxEnv, envSpec, fixedR.w); #endif - }else{ - vec3 centerPosBlend, boxHalfSizeBlend; - float mipCountBlend; - GetBlendCubeReflectionProbeData(centerPosBlend, boxHalfSizeBlend, mipCountBlend, FSInput_reflectionProbeBlendId); - vec3 probeBlend = SampleEnvironmentSpecular(cc_reflectionProbeBlendCubemap, lightingData, mipCountBlend, worldPos, centerPosBlend, boxHalfSizeBlend, isBlendReflectProbeUsingRGBE(FSInput_reflectionProbeBlendId)); - envSpec = mix(envSpec, probeBlend, blendFactor); } + // Disable probe blend for WebGPU + // else { + // vec3 centerPosBlend, boxHalfSizeBlend; + // float mipCountBlend; + // GetBlendCubeReflectionProbeData(centerPosBlend, boxHalfSizeBlend, mipCountBlend, FSInput_reflectionProbeBlendId); + // vec3 probeBlend = SampleEnvironmentSpecular(cc_reflectionProbeBlendCubemap, lightingData, mipCountBlend, worldPos, centerPosBlend, boxHalfSizeBlend, isBlendReflectProbeUsingRGBE(FSInput_reflectionProbeBlendId)); + // envSpec = mix(envSpec, probeBlend, blendFactor); + // } } #endif #elif CC_USE_IBL diff --git a/native/cocos/renderer/pipeline/Define.h b/native/cocos/renderer/pipeline/Define.h index 01d8603a7d..29a0af261d 100644 --- a/native/cocos/renderer/pipeline/Define.h +++ b/native/cocos/renderer/pipeline/Define.h @@ -264,7 +264,8 @@ enum class CC_DLL ModelLocalBindings { SAMPLER_REFLECTION_PROBE_CUBE, SAMPLER_REFLECTION_PROBE_PLANAR, SAMPLER_REFLECTION_PROBE_DATA_MAP, - SAMPLER_REFLECTION_PROBE_BLEND_CUBE, + // SAMPLER_REFLECTION_PROBE_BLEND_CUBE, // Disable for WebGPU + COUNT, }; CC_ENUM_CONVERSION_OPERATOR(ModelLocalBindings) @@ -670,8 +671,10 @@ struct CC_DLL REFLECTIONPROBEDATAMAP { static const ccstd::string NAME; }; +constexpr bool ENABLE_PROBE_BLEND = false; + struct CC_DLL REFLECTIONPROBEBLENDCUBEMAP { - static constexpr uint32_t BINDING = static_cast(ModelLocalBindings::SAMPLER_REFLECTION_PROBE_BLEND_CUBE); + static constexpr uint32_t BINDING = static_cast(ModelLocalBindings::SAMPLER_REFLECTION_PROBE_DATA_MAP) + 1; // SAMPLER_REFLECTION_PROBE_BLEND_CUBE static const gfx::DescriptorSetLayoutBinding DESCRIPTOR; static const gfx::UniformSamplerTexture LAYOUT; static const ccstd::string NAME; diff --git a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp index 1f90d6217f..2d60148ce8 100644 --- a/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp +++ b/native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp @@ -233,8 +233,10 @@ void GlobalDSManager::setDescriptorSetLayout() { localDescriptorSetLayout.bindings[REFLECTIONPROBEPLANARMAP::BINDING] = REFLECTIONPROBEPLANARMAP::DESCRIPTOR; localDescriptorSetLayout.samplers[REFLECTIONPROBEDATAMAP::NAME] = REFLECTIONPROBEDATAMAP::LAYOUT; localDescriptorSetLayout.bindings[REFLECTIONPROBEDATAMAP::BINDING] = REFLECTIONPROBEDATAMAP::DESCRIPTOR; - localDescriptorSetLayout.samplers[REFLECTIONPROBEBLENDCUBEMAP::NAME] = REFLECTIONPROBEBLENDCUBEMAP::LAYOUT; - localDescriptorSetLayout.bindings[REFLECTIONPROBEBLENDCUBEMAP::BINDING] = REFLECTIONPROBEBLENDCUBEMAP::DESCRIPTOR; + if (ENABLE_PROBE_BLEND) { + localDescriptorSetLayout.samplers[REFLECTIONPROBEBLENDCUBEMAP::NAME] = REFLECTIONPROBEBLENDCUBEMAP::LAYOUT; + localDescriptorSetLayout.bindings[REFLECTIONPROBEBLENDCUBEMAP::BINDING] = REFLECTIONPROBEBLENDCUBEMAP::DESCRIPTOR; + } } } // namespace pipeline diff --git a/native/cocos/renderer/pipeline/InstancedBuffer.cpp b/native/cocos/renderer/pipeline/InstancedBuffer.cpp index a26cc71c0b..7d81252b46 100644 --- a/native/cocos/renderer/pipeline/InstancedBuffer.cpp +++ b/native/cocos/renderer/pipeline/InstancedBuffer.cpp @@ -66,8 +66,10 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh auto *lightingMap = descriptorSet->getTexture(LIGHTMAPTEXTURE::BINDING); auto *reflectionProbeCubemap = descriptorSet->getTexture(REFLECTIONPROBECUBEMAP::BINDING); auto *reflectionProbePlanarMap = descriptorSet->getTexture(REFLECTIONPROBEPLANARMAP::BINDING); - auto *reflectionProbeBlendCubemap = descriptorSet->getTexture(REFLECTIONPROBEBLENDCUBEMAP::BINDING); - uint32_t reflectionProbeType = subModel->getReflectionProbeType(); + gfx::Texture *reflectionProbeBlendCubemap = ENABLE_PROBE_BLEND + ? descriptorSet->getTexture(REFLECTIONPROBEBLENDCUBEMAP::BINDING) + : nullptr; + const uint32_t reflectionProbeType = subModel->getReflectionProbeType(); auto *shader = shaderImplant; if (!shader) { shader = subModel->getShader(passIdx); @@ -102,6 +104,7 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh if (instance.drawInfo.instanceCount >= instance.capacity) { // resize buffers instance.capacity <<= 1; const auto newSize = instance.stride * instance.capacity; + // NOLINTNEXTLINE(bugprone-suspicious-realloc-usage) instance.data = static_cast(CC_REALLOC(instance.data, newSize)); instance.vb->resize(newSize); } @@ -111,7 +114,7 @@ void InstancedBuffer::merge(scene::SubModel *subModel, uint32_t passIdx, gfx::Sh if (instance.descriptorSet != descriptorSet) { instance.descriptorSet = descriptorSet; } - memcpy(instance.data + instance.stride * instance.drawInfo.instanceCount++, attrs.buffer.buffer()->getData(), stride); + memcpy(instance.data + static_cast(instance.stride) * instance.drawInfo.instanceCount++, attrs.buffer.buffer()->getData(), stride); _hasPendingModels = true; return; } diff --git a/native/cocos/scene/Model.cpp b/native/cocos/scene/Model.cpp index 4f9ef50393..f0915d6d94 100644 --- a/native/cocos/scene/Model.cpp +++ b/native/cocos/scene/Model.cpp @@ -191,7 +191,7 @@ void Model::updateUBOs(uint32_t stamp) { for (const auto &subModel : _subModels) { const auto idx = subModel->getInstancedWorldMatrixIndex(); if (idx >= 0) { - ccstd::vector &attrs = subModel->getInstancedAttributeBlock().views; + const ccstd::vector &attrs = subModel->getInstancedAttributeBlock().views; subModel->updateInstancedWorldMatrix(worldMatrix, idx); } else { hasNonInstancingPass = true; @@ -216,7 +216,7 @@ void Model::updateUBOs(uint32_t stamp) { const Vec4 depthScale = {1.F, 0.F, 0.F, 1.F}; _localBuffer->write(depthScale, sizeof(float) * (pipeline::UBOLocal::REFLECTION_PROBE_DATA2)); } else { - uint16_t mipAndUseRGBE = probe->isRGBE() ? 1000 : 0; + const uint16_t mipAndUseRGBE = probe->isRGBE() ? 1000 : 0; const Vec4 pos = {probe->getNode()->getWorldPosition().x, probe->getNode()->getWorldPosition().y, probe->getNode()->getWorldPosition().z, 0.F}; _localBuffer->write(pos, sizeof(float) * (pipeline::UBOLocal::REFLECTION_PROBE_DATA1)); const Vec4 boxSize = {probe->getBoudingSize().x, probe->getBoudingSize().y, probe->getBoudingSize().z, static_cast(probe->getCubeMap() ? probe->getCubeMap()->mipmapLevel() + mipAndUseRGBE : 1 + mipAndUseRGBE)}; @@ -225,9 +225,9 @@ void Model::updateUBOs(uint32_t stamp) { if (_reflectionProbeType == scene::UseReflectionProbeType::BLEND_PROBES || _reflectionProbeType == scene::UseReflectionProbeType::BLEND_PROBES_AND_SKYBOX) { if (blendProbe) { - uint16_t mipAndUseRGBE = blendProbe->isRGBE() ? 1000 : 0; + const uint16_t mipAndUseRGBE = blendProbe->isRGBE() ? 1000 : 0; const Vec3 worldPos = blendProbe->getNode()->getWorldPosition(); - Vec3 boudingBox = blendProbe->getBoudingSize(); + const Vec3 boudingBox = blendProbe->getBoudingSize(); const Vec4 pos = {worldPos.x, worldPos.y, worldPos.z, _reflectionProbeBlendWeight}; _localBuffer->write(pos, sizeof(float) * (pipeline::UBOLocal::REFLECTION_PROBE_BLEND_DATA1)); const Vec4 boxSize = {boudingBox.x, boudingBox.y, boudingBox.z, static_cast(blendProbe->getCubeMap() ? blendProbe->getCubeMap()->mipmapLevel() + mipAndUseRGBE : 1 + mipAndUseRGBE)}; @@ -431,7 +431,7 @@ void Model::updateSHUBOs() { _lastWorldBoundCenter.set(center); _tetrahedronIndex = lightProbes->getData()->getInterpolationWeights(center, _tetrahedronIndex, weights); - bool result = lightProbes->getData()->getInterpolationSHCoefficients(_tetrahedronIndex, weights, coefficients); + const bool result = lightProbes->getData()->getInterpolationSHCoefficients(_tetrahedronIndex, weights, coefficients); if (!result) { return; } @@ -468,7 +468,7 @@ ccstd::vector Model::getMacroPatches(index_t subModelIndex) { } } - patches.push_back({CC_USE_REFLECTION_PROBE, static_cast(_reflectionProbeType)}); + patches.emplace_back(CC_USE_REFLECTION_PROBE, static_cast(_reflectionProbeType)); if (_lightmap != nullptr) { bool stationary = false; @@ -495,7 +495,7 @@ ccstd::vector Model::getMacroPatches(index_t subModelIndex) { } } } - patches.push_back({CC_DISABLE_DIRECTIONAL_LIGHT, !_receiveDirLight}); + patches.emplace_back(CC_DISABLE_DIRECTIONAL_LIGHT, !_receiveDirLight); return patches; } @@ -651,7 +651,7 @@ void Model::updateReflectionProbePlanarMap(gfx::Texture *texture) { bindingTexture = BuiltinResMgr::getInstance()->get(ccstd::string("empty-texture"))->getGFXTexture(); } if (bindingTexture) { - gfx::SamplerInfo info{ + const gfx::SamplerInfo info{ cc::gfx::Filter::LINEAR, cc::gfx::Filter::LINEAR, cc::gfx::Filter::NONE, @@ -687,6 +687,9 @@ void Model::updateReflectionProbeDataMap(Texture2D *texture) { } void Model::updateReflectionProbeBlendCubemap(TextureCube *texture) { + if constexpr (!pipeline::ENABLE_PROBE_BLEND) { // Disable probe blend for WebGPU + return; + } _localDataUpdated = true; if (texture == nullptr) { texture = BuiltinResMgr::getInstance()->get(ccstd::string("default-cube-texture"));