Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable probe blend #18292

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cocos/3d/reflection-probe/reflection-probe-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions cocos/render-scene/scene/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();

Expand Down
14 changes: 10 additions & 4 deletions cocos/rendering/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
Expand All @@ -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]);
Expand Down
10 changes: 6 additions & 4 deletions cocos/rendering/instanced-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -42,7 +42,7 @@ export interface IInstancedItem {
reflectionProbeCubemap: Texture;
reflectionProbePlanarMap: Texture;
useReflectionProbeType: number;
reflectionProbeBlendCubemap: Texture;
reflectionProbeBlendCubemap: Texture | null;
}

const INITIAL_CAPACITY = 32;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 9 additions & 7 deletions editor/assets/chunks/legacy/shading-standard-base.chunk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions native/cocos/renderer/pipeline/Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<uint32_t>(ModelLocalBindings::SAMPLER_REFLECTION_PROBE_BLEND_CUBE);
static constexpr uint32_t BINDING = static_cast<uint32_t>(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;
Expand Down
6 changes: 4 additions & 2 deletions native/cocos/renderer/pipeline/GlobalDescriptorSetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions native/cocos/renderer/pipeline/InstancedBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<uint8_t *>(CC_REALLOC(instance.data, newSize));
instance.vb->resize(newSize);
}
Expand All @@ -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<size_t>(instance.stride) * instance.drawInfo.instanceCount++, attrs.buffer.buffer()->getData(), stride);
_hasPendingModels = true;
return;
}
Expand Down
19 changes: 11 additions & 8 deletions native/cocos/scene/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypedArray> &attrs = subModel->getInstancedAttributeBlock().views;
const ccstd::vector<TypedArray> &attrs = subModel->getInstancedAttributeBlock().views;
subModel->updateInstancedWorldMatrix(worldMatrix, idx);
} else {
hasNonInstancingPass = true;
Expand All @@ -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<float>(probe->getCubeMap() ? probe->getCubeMap()->mipmapLevel() + mipAndUseRGBE : 1 + mipAndUseRGBE)};
Expand All @@ -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<float>(blendProbe->getCubeMap() ? blendProbe->getCubeMap()->mipmapLevel() + mipAndUseRGBE : 1 + mipAndUseRGBE)};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -468,7 +468,7 @@ ccstd::vector<IMacroPatch> Model::getMacroPatches(index_t subModelIndex) {
}
}

patches.push_back({CC_USE_REFLECTION_PROBE, static_cast<int32_t>(_reflectionProbeType)});
patches.emplace_back(CC_USE_REFLECTION_PROBE, static_cast<int32_t>(_reflectionProbeType));

if (_lightmap != nullptr) {
bool stationary = false;
Expand All @@ -495,7 +495,7 @@ ccstd::vector<IMacroPatch> Model::getMacroPatches(index_t subModelIndex) {
}
}
}
patches.push_back({CC_DISABLE_DIRECTIONAL_LIGHT, !_receiveDirLight});
patches.emplace_back(CC_DISABLE_DIRECTIONAL_LIGHT, !_receiveDirLight);

return patches;
}
Expand Down Expand Up @@ -651,7 +651,7 @@ void Model::updateReflectionProbePlanarMap(gfx::Texture *texture) {
bindingTexture = BuiltinResMgr::getInstance()->get<Texture2D>(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,
Expand Down Expand Up @@ -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<TextureCube>(ccstd::string("default-cube-texture"));
Expand Down
Loading