Skip to content

Commit

Permalink
remove deferred reflection shaders (#18281)
Browse files Browse the repository at this point in the history
* remove deferred reflection shaders
* fix test shader
* remove reflectionTex
  • Loading branch information
star-e authored Feb 7, 2025
1 parent 243b622 commit 523d982
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 1,024 deletions.
53 changes: 4 additions & 49 deletions cocos/render-scene/scene/submodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
*/

import { RenderingSubMesh } from '../../asset/assets/rendering-sub-mesh';
import { RenderPriority, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_STORAGE_BINDING,
INST_MAT_WORLD, INST_SH, isEnableEffect,
import { RenderPriority,
INST_MAT_WORLD, INST_SH,
UBOSHEnum } from '../../rendering/define';
import { BatchingSchemes, IMacroPatch, Pass } from '../core/pass';
import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture, TextureType, TextureUsageBit, TextureInfo,
Format, Sampler, Filter, Address, Shader, SamplerInfo, deviceManager,
import { DescriptorSet, DescriptorSetInfo, Device, InputAssembler, Texture,
Sampler, Shader, deviceManager,
Attribute, Feature, FormatInfos, getTypedArrayConstructor } from '../../gfx';
import { errorID, Mat4, cclegacy } from '../../core';
import { getPhaseID } from '../../rendering/pass-phase';
import { Root } from '../../root';

const _dsInfo = new DescriptorSetInfo(null!);
Expand Down Expand Up @@ -59,8 +58,6 @@ export class SubModel {
protected _inputAssembler: InputAssembler | null = null;
protected _descriptorSet: DescriptorSet | null = null;
protected _worldBoundDescriptorSet: DescriptorSet | null = null;
protected _reflectionTex: Texture | null = null;
protected _reflectionSampler: Sampler | null = null;
protected _instancedAttributeBlock: IInstancedAttributeBlock = { buffer: null!, views: [], attributes: [] };
protected _instancedWorldMatrixIndex = -1;
protected _instancedSHIndex = -1;
Expand Down Expand Up @@ -239,44 +236,6 @@ export class SubModel {
this._flushPassInfo();

this.priority = RenderPriority.DEFAULT;

const r = cclegacy.rendering;
// initialize resources for reflection material
if (((!r || !r.enableEffectImport) && passes[0].phase === getPhaseID('reflection'))
|| (isEnableEffect() && passes[0].phaseID === r.getPhaseID(r.getPassID('default'), 'reflection'))) {
let texWidth = root.mainWindow!.width;
let texHeight = root.mainWindow!.height;
const minSize = 512;

if (texHeight < texWidth) {
texWidth = minSize * texWidth / texHeight;
texHeight = minSize;
} else {
texWidth = minSize;
texHeight = minSize * texHeight / texWidth;
}

this._reflectionTex = this._device.createTexture(new TextureInfo(
TextureType.TEX2D,
TextureUsageBit.STORAGE | TextureUsageBit.TRANSFER_SRC | TextureUsageBit.SAMPLED,
Format.RGBA8,
texWidth,
texHeight,
));

this.descriptorSet.bindTexture(UNIFORM_REFLECTION_TEXTURE_BINDING, this._reflectionTex);

this._reflectionSampler = this._device.getSampler(new SamplerInfo(
Filter.LINEAR,
Filter.LINEAR,
Filter.NONE,
Address.CLAMP,
Address.CLAMP,
Address.CLAMP,
));
this.descriptorSet.bindSampler(UNIFORM_REFLECTION_TEXTURE_BINDING, this._reflectionSampler);
this.descriptorSet.bindTexture(UNIFORM_REFLECTION_STORAGE_BINDING, this._reflectionTex);
}
}

/**
Expand Down Expand Up @@ -304,10 +263,6 @@ export class SubModel {

this._passes = null;
this._shaders = null;

if (this._reflectionTex) this._reflectionTex.destroy();
this._reflectionTex = null;
this._reflectionSampler = null;
}

/**
Expand Down
43 changes: 1 addition & 42 deletions cocos/rendering/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ export enum ModelLocalBindings {
SAMPLER_MORPH_TANGENT,
SAMPLER_LIGHTMAP,
SAMPLER_SPRITE,
SAMPLER_REFLECTION,

STORAGE_REFLECTION,

SAMPLER_REFLECTION_PROBE_CUBE,
SAMPLER_REFLECTION_PROBE_PLANAR,
Expand All @@ -161,7 +158,7 @@ export enum ModelLocalBindings {
COUNT,
}
const LOCAL_UBO_COUNT = ModelLocalBindings.SAMPLER_JOINTS;
const LOCAL_SAMPLER_COUNT = ModelLocalBindings.STORAGE_REFLECTION - LOCAL_UBO_COUNT;
const LOCAL_SAMPLER_COUNT = ModelLocalBindings.COUNT - LOCAL_UBO_COUNT;
const LOCAL_STORAGE_IMAGE_COUNT = ModelLocalBindings.COUNT - LOCAL_UBO_COUNT - LOCAL_SAMPLER_COUNT;

export enum SetIndex {
Expand Down Expand Up @@ -950,44 +947,6 @@ const UNIFORM_SPRITE_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL,
localDescriptorSetLayout.layouts[UNIFORM_SPRITE_TEXTURE_NAME] = UNIFORM_SPRITE_TEXTURE_LAYOUT;
localDescriptorSetLayout.bindings[UNIFORM_SPRITE_TEXTURE_BINDING] = UNIFORM_SPRITE_TEXTURE_DESCRIPTOR;

/**
* @en The sampler for reflection
* @zh 反射纹理采样器。
*/
const UNIFORM_REFLECTION_TEXTURE_NAME = 'cc_reflectionTexture';
export const UNIFORM_REFLECTION_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_REFLECTION;
const UNIFORM_REFLECTION_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(
UNIFORM_REFLECTION_TEXTURE_BINDING,
DescriptorType.SAMPLER_TEXTURE,
1,
ShaderStageFlagBit.FRAGMENT,
MemoryAccessBit.READ_ONLY,
ViewDimension.TEX2D,
);
const UNIFORM_REFLECTION_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_REFLECTION_TEXTURE_BINDING, UNIFORM_REFLECTION_TEXTURE_NAME, Type.SAMPLER2D, 1);
localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_TEXTURE_NAME] = UNIFORM_REFLECTION_TEXTURE_LAYOUT;
localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_TEXTURE_BINDING] = UNIFORM_REFLECTION_TEXTURE_DESCRIPTOR;

/**
* @en The storage image for reflection
* @zh 反射纹理存储。
*/
const UNIFORM_REFLECTION_STORAGE_NAME = 'cc_reflectionStorage';
export const UNIFORM_REFLECTION_STORAGE_BINDING = ModelLocalBindings.STORAGE_REFLECTION;
const UNIFORM_REFLECTION_STORAGE_DESCRIPTOR = new DescriptorSetLayoutBinding(
UNIFORM_REFLECTION_STORAGE_BINDING,
DescriptorType.STORAGE_IMAGE,
1,
ShaderStageFlagBit.COMPUTE,
MemoryAccessBit.READ_WRITE,
ViewDimension.TEX2D,
SampleType.FLOAT,
Format.RGBA8,
);
const UNIFORM_REFLECTION_STORAGE_LAYOUT = new UniformStorageImage(SetIndex.LOCAL, UNIFORM_REFLECTION_STORAGE_BINDING, UNIFORM_REFLECTION_STORAGE_NAME, Type.IMAGE2D, 1);
localDescriptorSetLayout.layouts[UNIFORM_REFLECTION_STORAGE_NAME] = UNIFORM_REFLECTION_STORAGE_LAYOUT;
localDescriptorSetLayout.bindings[UNIFORM_REFLECTION_STORAGE_BINDING] = UNIFORM_REFLECTION_STORAGE_DESCRIPTOR;

/**
* @en The sampler for reflection probe cubemap
* @zh 反射探针立方体贴图纹理采样器。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.

#pragma builtin(local)
layout(set = 2, binding = 15) uniform samplerCube cc_reflectionProbeCubemap;
layout(set = 2, binding = 13) uniform samplerCube cc_reflectionProbeCubemap;

#pragma builtin(local)
layout(set = 2, binding = 16) uniform sampler2D cc_reflectionProbePlanarMap;
layout(set = 2, binding = 14) uniform sampler2D cc_reflectionProbePlanarMap;

#pragma builtin(local)
layout(set = 2, binding = 17) uniform sampler2D cc_reflectionProbeDataMap;
layout(set = 2, binding = 15) uniform sampler2D cc_reflectionProbeDataMap;

#pragma builtin(local)
layout(set = 2, binding = 18) uniform samplerCube cc_reflectionProbeBlendCubemap;
layout(set = 2, binding = 16) uniform samplerCube cc_reflectionProbeBlendCubemap;
Loading

0 comments on commit 523d982

Please sign in to comment.