Skip to content

Commit

Permalink
disable probe blend
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Feb 7, 2025
1 parent 50d86d0 commit 1fa80cb
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 29 deletions.
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
4 changes: 3 additions & 1 deletion native/cocos/renderer/pipeline/InstancedBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ 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);
gfx::Texture *reflectionProbeBlendCubemap = ENABLE_PROBE_BLEND
? descriptorSet->getTexture(REFLECTIONPROBEBLENDCUBEMAP::BINDING)
: nullptr;
uint32_t reflectionProbeType = subModel->getReflectionProbeType();

Check failure on line 72 in native/cocos/renderer/pipeline/InstancedBuffer.cpp

View workflow job for this annotation

GitHub Actions / ClangTidy Android

variable 'reflectionProbeType' of type 'uint32_t' (aka 'unsigned int') can be declared 'const' (misc-const-correctness)
auto *shader = shaderImplant;
if (!shader) {
Expand Down
3 changes: 3 additions & 0 deletions native/cocos/scene/Model.cpp
Original file line number Diff line number Diff line change
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

0 comments on commit 1fa80cb

Please sign in to comment.