mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
[optimization] Split csm ubo v3.6.0 (#12072)
* split csm ubo v3.6.0 * update * Modify *.meta file to ignore material upgrade * update * update * update 2 * use better struct padding and save memory * update mate * fix ci error * memory alignment * update * update 2 * chenge func name * update
This commit is contained in:
committed by
GitHub
parent
e7eeab9340
commit
d5f77d0af1
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING,
|
||||
supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING } from '../define';
|
||||
supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, UBOCSM } from '../define';
|
||||
import { Device, BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet } from '../../gfx';
|
||||
import { Camera } from '../../renderer/scene/camera';
|
||||
import { Mat4, Vec3, Vec4, Color } from '../../math';
|
||||
@@ -199,19 +199,22 @@ export class PipelineUBO {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public static updateShadowUBOView (pipeline: WebPipeline, shadowBufferView: Float32Array, camera: Camera) {
|
||||
public static updateShadowUBOView (pipeline: WebPipeline, shadowBufferView: Float32Array,
|
||||
csmBufferView: Float32Array, camera: Camera) {
|
||||
const device = pipeline.device;
|
||||
const mainLight = camera.scene!.mainLight;
|
||||
const sceneData = pipeline.pipelineSceneData;
|
||||
const shadowInfo = sceneData.shadows;
|
||||
const csmLayers = sceneData.csmLayers;
|
||||
const sv = shadowBufferView;
|
||||
const cv = csmBufferView;
|
||||
const csmSupported = sceneData.csmSupported;
|
||||
const packing = supportsR32FloatTexture(device) ? 0.0 : 1.0;
|
||||
|
||||
if (shadowInfo.enabled && mainLight) {
|
||||
if (shadowInfo.type === ShadowType.ShadowMap) {
|
||||
if (mainLight.shadowEnabled) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1 || !csmSupported) {
|
||||
const matShadowView = csmLayers.specialLayer.matShadowView;
|
||||
const matShadowProj = csmLayers.specialLayer.matShadowProj;
|
||||
const matShadowViewProj = csmLayers.specialLayer.matShadowViewProj;
|
||||
@@ -239,33 +242,33 @@ export class PipelineUBO {
|
||||
Vec4.toArray(sv, _vec4ShadowInfo, UBOShadow.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET);
|
||||
} else {
|
||||
for (let i = 0; i < mainLight.csmLevel; i++) {
|
||||
sv[UBOShadow.CSM_SPLITS_INFO_OFFSET + i] = csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance;
|
||||
cv[UBOCSM.CSM_SPLITS_INFO_OFFSET + i] = csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance;
|
||||
|
||||
const matShadowView = csmLayers.layers[i].matShadowView;
|
||||
Mat4.toArray(sv, matShadowView, UBOShadow.MAT_CSM_VIEW_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowView, UBOCSM.MAT_CSM_VIEW_OFFSET + 16 * i);
|
||||
|
||||
const matShadowViewProj = csmLayers.layers[i].matShadowViewProj;
|
||||
Mat4.toArray(sv, matShadowViewProj, UBOShadow.MAT_CSM_VIEW_PROJ_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowViewProj, UBOCSM.MAT_CSM_VIEW_PROJ_OFFSET + 16 * i);
|
||||
|
||||
const matShadowViewProjAtlas = csmLayers.layers[i].matShadowViewProjAtlas;
|
||||
Mat4.toArray(sv, matShadowViewProjAtlas, UBOShadow.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowViewProjAtlas, UBOCSM.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * i);
|
||||
|
||||
const matShadowProj = csmLayers.layers[i].matShadowProj;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m10;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m14;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 2 + 4 * i] = matShadowProj.m11;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 3 + 4 * i] = matShadowProj.m15;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m10;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m14;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 2 + 4 * i] = matShadowProj.m11;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 3 + 4 * i] = matShadowProj.m15;
|
||||
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m00;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m05;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 2 + 4 * i] = 1.0 / matShadowProj.m00;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 3 + 4 * i] = 1.0 / matShadowProj.m05;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m00;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m05;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 2 + 4 * i] = 1.0 / matShadowProj.m00;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 3 + 4 * i] = 1.0 / matShadowProj.m05;
|
||||
}
|
||||
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 0] = 0;
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 1] = this.getPCFRadius(shadowInfo, mainLight);
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 2] = 0;
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 3] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 0] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 1] = this.getPCFRadius(shadowInfo, mainLight);
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 2] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 3] = 0;
|
||||
|
||||
_vec4ShadowInfo.set(0, 0, 0, 1.0 - mainLight.shadowSaturation);
|
||||
Vec4.toArray(sv, _vec4ShadowInfo, UBOShadow.SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET);
|
||||
@@ -384,6 +387,7 @@ export class PipelineUBO {
|
||||
protected _globalUBO = new Float32Array(UBOGlobal.COUNT);
|
||||
protected _cameraUBO = new Float32Array(UBOCamera.COUNT);
|
||||
protected _shadowUBO = new Float32Array(UBOShadow.COUNT);
|
||||
protected _csmUBO = new Float32Array(UBOCSM.COUNT);
|
||||
static _combineSignY = 0;
|
||||
protected declare _device: Device;
|
||||
protected declare _pipeline: WebPipeline;
|
||||
@@ -433,6 +437,13 @@ export class PipelineUBO {
|
||||
UBOShadow.SIZE,
|
||||
));
|
||||
ds.bindBuffer(UBOShadow.BINDING, shadowUBO);
|
||||
const csmUBO = device.createBuffer(new BufferInfo(
|
||||
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
|
||||
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
|
||||
UBOCSM.SIZE,
|
||||
UBOCSM.SIZE,
|
||||
));
|
||||
ds.bindBuffer(UBOCSM.BINDING, csmUBO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -474,9 +485,10 @@ export class PipelineUBO {
|
||||
if (mainLight && shadowFrameBufferMap.has(mainLight)) {
|
||||
ds.bindTexture(UNIFORM_SHADOWMAP_BINDING, shadowFrameBufferMap.get(mainLight)!.colorTextures[0]!);
|
||||
}
|
||||
PipelineUBO.updateShadowUBOView(this._pipeline, this._shadowUBO, camera);
|
||||
PipelineUBO.updateShadowUBOView(this._pipeline, this._shadowUBO, this._csmUBO, camera);
|
||||
ds.update();
|
||||
cmdBuffer.updateBuffer(ds.getBuffer(UBOShadow.BINDING), this._shadowUBO);
|
||||
cmdBuffer.updateBuffer(ds.getBuffer(UBOCSM.BINDING), this._csmUBO);
|
||||
}
|
||||
|
||||
public updateShadowUBOLight (globalDS: DescriptorSet, light: Light, level = 0) {
|
||||
|
||||
@@ -114,6 +114,7 @@ export enum PipelineGlobalBindings {
|
||||
UBO_GLOBAL,
|
||||
UBO_CAMERA,
|
||||
UBO_SHADOW,
|
||||
UBO_CSM, // should reserve slot for this optional ubo
|
||||
|
||||
SAMPLER_SHADOWMAP,
|
||||
SAMPLER_ENVIRONMENT, // don't put this as the first sampler binding due to Mac GL driver issues: cubemap at texture unit 0 causes rendering issues
|
||||
@@ -256,11 +257,10 @@ globalDescriptorSetLayout.layouts[UBOCamera.NAME] = UBOCamera.LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UBOCamera.BINDING] = UBOCamera.DESCRIPTOR;
|
||||
|
||||
/**
|
||||
* @en The uniform buffer object for shadow
|
||||
* @zh 给阴影对象使用的 UBO
|
||||
* @en The uniform buffer object for 'cast shadow(fixed || csm)' && 'dir fixed area shadow' && 'spot shadow' && 'sphere shadow' && 'planar shadow'
|
||||
* @zh 这个 UBO 仅仅只给 'cast shadow(fixed || csm)' && 'dir fixed area shadow' && 'spot shadow' && 'sphere shadow' && 'planar shadow' 使用
|
||||
*/
|
||||
export class UBOShadow {
|
||||
public static readonly CSM_LEVEL_COUNT = 4;
|
||||
public static readonly MAT_LIGHT_PLANE_PROJ_OFFSET = 0;
|
||||
public static readonly MAT_LIGHT_VIEW_OFFSET = UBOShadow.MAT_LIGHT_PLANE_PROJ_OFFSET + 16;
|
||||
public static readonly MAT_LIGHT_VIEW_PROJ_OFFSET = UBOShadow.MAT_LIGHT_VIEW_OFFSET + 16;
|
||||
@@ -272,14 +272,7 @@ export class UBOShadow {
|
||||
public static readonly SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET = UBOShadow.SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET + 4;
|
||||
public static readonly SHADOW_COLOR_OFFSET = UBOShadow.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 4;
|
||||
public static readonly PLANAR_NORMAL_DISTANCE_INFO_OFFSET = UBOShadow.SHADOW_COLOR_OFFSET + 4;
|
||||
public static readonly MAT_CSM_VIEW_OFFSET = UBOShadow.PLANAR_NORMAL_DISTANCE_INFO_OFFSET + 4;
|
||||
public static readonly MAT_CSM_VIEW_PROJ_OFFSET = UBOShadow.MAT_CSM_VIEW_OFFSET + 16 * UBOShadow.CSM_LEVEL_COUNT;
|
||||
public static readonly MAT_CSM_VIEW_PROJ_ATLAS_OFFSET = UBOShadow.MAT_CSM_VIEW_PROJ_OFFSET + 16 * UBOShadow.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_PROJ_DEPTH_INFO_OFFSET = UBOShadow.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * UBOShadow.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_PROJ_INFO_OFFSET = UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 4 * UBOShadow.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_SPLITS_INFO_OFFSET = UBOShadow.CSM_PROJ_INFO_OFFSET + 4 * UBOShadow.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_INFO_OFFSET = UBOShadow.CSM_SPLITS_INFO_OFFSET + 4;
|
||||
public static readonly COUNT: number = UBOShadow.CSM_INFO_OFFSET + 4;
|
||||
public static readonly COUNT: number = UBOShadow.PLANAR_NORMAL_DISTANCE_INFO_OFFSET + 4;
|
||||
public static readonly SIZE = UBOShadow.COUNT * 4;
|
||||
public static readonly NAME = 'CCShadow';
|
||||
public static readonly BINDING = PipelineGlobalBindings.UBO_SHADOW;
|
||||
@@ -296,18 +289,43 @@ export class UBOShadow {
|
||||
new Uniform('cc_shadowLPNNInfo', Type.FLOAT4, 1),
|
||||
new Uniform('cc_shadowColor', Type.FLOAT4, 1),
|
||||
new Uniform('cc_planarNDInfo', Type.FLOAT4, 1),
|
||||
new Uniform('cc_matCSMView', Type.MAT4, UBOShadow.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_matCSMViewProj', Type.MAT4, UBOShadow.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_matCSMViewProjAtlas', Type.MAT4, UBOShadow.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmProjDepthInfo', Type.FLOAT4, UBOShadow.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmProjInfo', Type.FLOAT4, UBOShadow.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmSplitsInfo', Type.FLOAT4, 1),
|
||||
new Uniform('cc_csmInfo', Type.FLOAT4, 1),
|
||||
], 1);
|
||||
}
|
||||
globalDescriptorSetLayout.layouts[UBOShadow.NAME] = UBOShadow.LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UBOShadow.BINDING] = UBOShadow.DESCRIPTOR;
|
||||
|
||||
/**
|
||||
* @en The uniform buffer object only for dir csm shadow(level: 1 ~ 4)
|
||||
* @zh 级联阴影使用的UBO
|
||||
*/
|
||||
export class UBOCSM {
|
||||
public static readonly CSM_LEVEL_COUNT = 4;
|
||||
public static readonly MAT_CSM_VIEW_OFFSET = 0;
|
||||
public static readonly MAT_CSM_VIEW_PROJ_OFFSET = UBOCSM.MAT_CSM_VIEW_OFFSET + 16 * UBOCSM.CSM_LEVEL_COUNT;
|
||||
public static readonly MAT_CSM_VIEW_PROJ_ATLAS_OFFSET = UBOCSM.MAT_CSM_VIEW_PROJ_OFFSET + 16 * UBOCSM.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_PROJ_DEPTH_INFO_OFFSET = UBOCSM.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * UBOCSM.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_PROJ_INFO_OFFSET = UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 4 * UBOCSM.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_SPLITS_INFO_OFFSET = UBOCSM.CSM_PROJ_INFO_OFFSET + 4 * UBOCSM.CSM_LEVEL_COUNT;
|
||||
public static readonly CSM_INFO_OFFSET = UBOCSM.CSM_SPLITS_INFO_OFFSET + 4;
|
||||
public static readonly COUNT: number = UBOCSM.CSM_INFO_OFFSET + 4;
|
||||
public static readonly SIZE = UBOCSM.COUNT * 4;
|
||||
|
||||
public static readonly NAME = 'CCCSM';
|
||||
public static readonly BINDING = PipelineGlobalBindings.UBO_CSM;
|
||||
public static readonly DESCRIPTOR = new DescriptorSetLayoutBinding(UBOCSM.BINDING, DescriptorType.UNIFORM_BUFFER, 1, ShaderStageFlagBit.ALL);
|
||||
public static readonly LAYOUT = new UniformBlock(SetIndex.GLOBAL, UBOCSM.BINDING, UBOCSM.NAME, [
|
||||
new Uniform('cc_matCSMView', Type.MAT4, UBOCSM.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_matCSMViewProj', Type.MAT4, UBOCSM.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_matCSMViewProjAtlas', Type.MAT4, UBOCSM.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmProjDepthInfo', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmProjInfo', Type.FLOAT4, UBOCSM.CSM_LEVEL_COUNT),
|
||||
new Uniform('cc_csmSplitsInfo', Type.FLOAT4, 1),
|
||||
new Uniform('cc_csmInfo', Type.FLOAT4, 1),
|
||||
], 1);
|
||||
}
|
||||
globalDescriptorSetLayout.layouts[UBOCSM.NAME] = UBOCSM.LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UBOCSM.BINDING] = UBOCSM.DESCRIPTOR;
|
||||
|
||||
/* eslint-disable max-len */
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,6 +55,13 @@ export class PipelineSceneData {
|
||||
this._shadingScale = val;
|
||||
}
|
||||
|
||||
public get csmSupported () {
|
||||
return this._csmSupported;
|
||||
}
|
||||
public set csmSupported (val: boolean) {
|
||||
this._csmSupported = val;
|
||||
}
|
||||
|
||||
public fog: Fog = new Fog();
|
||||
public ambient: Ambient = new Ambient();
|
||||
public skybox: Skybox = new Skybox();
|
||||
@@ -85,6 +92,7 @@ export class PipelineSceneData {
|
||||
protected _occlusionQueryShader: Shader | null = null;
|
||||
protected _isHDR = true;
|
||||
protected _shadingScale = 1.0;
|
||||
protected _csmSupported = true;
|
||||
|
||||
constructor () {
|
||||
this._shadingScale = 1.0;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING,
|
||||
supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING } from './define';
|
||||
supportsR32FloatTexture, UNIFORM_SPOT_SHADOW_MAP_TEXTURE_BINDING, UBOCSM } from './define';
|
||||
import { Device, BufferInfo, BufferUsageBit, MemoryUsageBit, DescriptorSet, API } from '../gfx';
|
||||
import { Camera } from '../renderer/scene/camera';
|
||||
import { Mat4, Vec3, Vec4, Color } from '../math';
|
||||
@@ -201,19 +201,22 @@ export class PipelineUBO {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public static updateShadowUBOView (pipeline: RenderPipeline, shadowBufferView: Float32Array, camera: Camera) {
|
||||
public static updateShadowUBOView (pipeline: RenderPipeline, shadowBufferView: Float32Array,
|
||||
csmBufferView: Float32Array, camera: Camera) {
|
||||
const device = pipeline.device;
|
||||
const mainLight = camera.scene!.mainLight;
|
||||
const sceneData = pipeline.pipelineSceneData;
|
||||
const shadowInfo = sceneData.shadows;
|
||||
const csmLayers = sceneData.csmLayers;
|
||||
const sv = shadowBufferView;
|
||||
const cv = csmBufferView;
|
||||
const csmSupported = sceneData.csmSupported;
|
||||
const packing = supportsR32FloatTexture(device) ? 0.0 : 1.0;
|
||||
|
||||
if (mainLight && shadowInfo.enabled) {
|
||||
if (shadowInfo.type === ShadowType.ShadowMap) {
|
||||
if (mainLight.shadowEnabled) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1 || !csmSupported) {
|
||||
const matShadowView = csmLayers.specialLayer.matShadowView;
|
||||
const matShadowProj = csmLayers.specialLayer.matShadowProj;
|
||||
const matShadowViewProj = csmLayers.specialLayer.matShadowViewProj;
|
||||
@@ -241,33 +244,33 @@ export class PipelineUBO {
|
||||
Vec4.toArray(sv, _vec4ShadowInfo, UBOShadow.SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET);
|
||||
} else {
|
||||
for (let i = 0; i < mainLight.csmLevel; i++) {
|
||||
sv[UBOShadow.CSM_SPLITS_INFO_OFFSET + i] = csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance;
|
||||
cv[UBOCSM.CSM_SPLITS_INFO_OFFSET + i] = csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance;
|
||||
|
||||
const matShadowView = csmLayers.layers[i].matShadowView;
|
||||
Mat4.toArray(sv, matShadowView, UBOShadow.MAT_CSM_VIEW_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowView, UBOCSM.MAT_CSM_VIEW_OFFSET + 16 * i);
|
||||
|
||||
const matShadowViewProj = csmLayers.layers[i].matShadowViewProj;
|
||||
Mat4.toArray(sv, matShadowViewProj, UBOShadow.MAT_CSM_VIEW_PROJ_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowViewProj, UBOCSM.MAT_CSM_VIEW_PROJ_OFFSET + 16 * i);
|
||||
|
||||
const matShadowViewProjAtlas = csmLayers.layers[i].matShadowViewProjAtlas;
|
||||
Mat4.toArray(sv, matShadowViewProjAtlas, UBOShadow.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * i);
|
||||
Mat4.toArray(cv, matShadowViewProjAtlas, UBOCSM.MAT_CSM_VIEW_PROJ_ATLAS_OFFSET + 16 * i);
|
||||
|
||||
const matShadowProj = csmLayers.layers[i].matShadowProj;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m10;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m14;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 2 + 4 * i] = matShadowProj.m11;
|
||||
sv[UBOShadow.CSM_PROJ_DEPTH_INFO_OFFSET + 3 + 4 * i] = matShadowProj.m15;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m10;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m14;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 2 + 4 * i] = matShadowProj.m11;
|
||||
cv[UBOCSM.CSM_PROJ_DEPTH_INFO_OFFSET + 3 + 4 * i] = matShadowProj.m15;
|
||||
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m00;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m05;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 2 + 4 * i] = 1.0 / matShadowProj.m00;
|
||||
sv[UBOShadow.CSM_PROJ_INFO_OFFSET + 3 + 4 * i] = 1.0 / matShadowProj.m05;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 0 + 4 * i] = matShadowProj.m00;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 1 + 4 * i] = matShadowProj.m05;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 2 + 4 * i] = 1.0 / matShadowProj.m00;
|
||||
cv[UBOCSM.CSM_PROJ_INFO_OFFSET + 3 + 4 * i] = 1.0 / matShadowProj.m05;
|
||||
}
|
||||
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 0] = 0;
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 1] = this.getPCFRadius(shadowInfo, mainLight);
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 2] = 0;
|
||||
sv[UBOShadow.CSM_INFO_OFFSET + 3] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 0] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 1] = this.getPCFRadius(shadowInfo, mainLight);
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 2] = 0;
|
||||
cv[UBOCSM.CSM_INFO_OFFSET + 3] = 0;
|
||||
|
||||
_vec4ShadowInfo.set(0, 0, 0, 1.0 - mainLight.shadowSaturation);
|
||||
Vec4.toArray(sv, _vec4ShadowInfo, UBOShadow.SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET);
|
||||
@@ -391,6 +394,7 @@ export class PipelineUBO {
|
||||
protected _globalUBO = new Float32Array(UBOGlobal.COUNT);
|
||||
protected _cameraUBO = new Float32Array(UBOCamera.COUNT);
|
||||
protected _shadowUBO = new Float32Array(UBOShadow.COUNT);
|
||||
protected _csmUBO = new Float32Array(UBOCSM.COUNT);
|
||||
static _combineSignY = 0;
|
||||
protected declare _device: Device;
|
||||
protected declare _pipeline: RenderPipeline;
|
||||
@@ -440,6 +444,13 @@ export class PipelineUBO {
|
||||
UBOShadow.SIZE,
|
||||
));
|
||||
ds.bindBuffer(UBOShadow.BINDING, shadowUBO);
|
||||
const csmUBO = device.createBuffer(new BufferInfo(
|
||||
BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
|
||||
MemoryUsageBit.HOST | MemoryUsageBit.DEVICE,
|
||||
UBOCSM.SIZE,
|
||||
UBOCSM.SIZE,
|
||||
));
|
||||
ds.bindBuffer(UBOCSM.BINDING, csmUBO);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -481,9 +492,10 @@ export class PipelineUBO {
|
||||
if (mainLight && shadowFrameBufferMap.has(mainLight)) {
|
||||
ds.bindTexture(UNIFORM_SHADOWMAP_BINDING, shadowFrameBufferMap.get(mainLight)!.colorTextures[0]!);
|
||||
}
|
||||
PipelineUBO.updateShadowUBOView(this._pipeline, this._shadowUBO, camera);
|
||||
PipelineUBO.updateShadowUBOView(this._pipeline, this._shadowUBO, this._csmUBO, camera);
|
||||
ds.update();
|
||||
cmdBuffer[0].updateBuffer(ds.getBuffer(UBOShadow.BINDING), this._shadowUBO);
|
||||
cmdBuffer[0].updateBuffer(ds.getBuffer(UBOCSM.BINDING), this._csmUBO);
|
||||
}
|
||||
|
||||
public updateShadowUBOLight (globalDS: DescriptorSet, light: Light, level = 0) {
|
||||
|
||||
@@ -162,9 +162,10 @@ export class ShadowLayerVolume {
|
||||
orthoSizeWidth = orthoSizeHeight = Vec3.distance(this._lightViewFrustum.vertices[0], this._lightViewFrustum.vertices[6]);
|
||||
}
|
||||
|
||||
if (dirLight.csmLevel > 1 && dirLight.csmOptimizationMode
|
||||
const csmLevel = legacyCC.director.root.pipeline.pipelineSceneData.csmSupported ? dirLight.csmLevel : 1;
|
||||
if (csmLevel > 1 && dirLight.csmOptimizationMode
|
||||
=== CSMOptimizationMode.RemoveDuplicates) {
|
||||
if (this._level >= dirLight.csmLevel - 1) {
|
||||
if (this._level >= csmLevel - 1) {
|
||||
_maxLayerFarPlane = this._castLightViewBoundingBox.halfExtents.z;
|
||||
_maxLayerPosz = this._castLightViewBoundingBox.center.z;
|
||||
} else {
|
||||
@@ -310,7 +311,7 @@ export class CSMLayers {
|
||||
if (dirLight === null) { return; }
|
||||
|
||||
const shadowInfo = sceneData.shadows;
|
||||
const levelCount = dirLight.csmLevel;
|
||||
const levelCount = legacyCC.director.root.pipeline.pipelineSceneData.csmSupported ? dirLight.csmLevel : 1;
|
||||
const shadowDistance = dirLight.shadowDistance;
|
||||
|
||||
if (!shadowInfo.enabled || !dirLight.shadowEnabled) { return; }
|
||||
@@ -359,7 +360,7 @@ export class CSMLayers {
|
||||
const nd = 0.1;
|
||||
const fd = dirLight.shadowDistance;
|
||||
const ratio = fd / nd;
|
||||
const level = dirLight.csmLevel;
|
||||
const level = legacyCC.director.root.pipeline.pipelineSceneData.csmSupported ? dirLight.csmLevel : 1;
|
||||
const lambda = dirLight.csmLayerLambda;
|
||||
this._layers[0].splitCameraNear = nd;
|
||||
for (let i = 1; i < level; i++) {
|
||||
@@ -379,7 +380,7 @@ export class CSMLayers {
|
||||
}
|
||||
|
||||
private _calculateCSM (camera: Camera, dirLight: DirectionalLight, shadowInfo: Shadows) {
|
||||
const level = dirLight.csmLevel;
|
||||
const level = legacyCC.director.root.pipeline.pipelineSceneData.csmSupported ? dirLight.csmLevel : 1;
|
||||
const shadowMapWidth = level > 1 ? shadowInfo.size.x * 0.5 : shadowInfo.size.x;
|
||||
|
||||
if (shadowMapWidth < 0.0) { return; }
|
||||
|
||||
@@ -41,6 +41,10 @@ import { Camera } from '../../renderer/scene';
|
||||
import { SpotLight } from '../../renderer/scene/spot-light';
|
||||
|
||||
const _validLights: Light[] = [];
|
||||
// csm uniform used vectors count
|
||||
const CSM_UNIFORM_VECTORS = 61;
|
||||
// all global uniform used vectors count
|
||||
const GLOBAL_UNIFORM_VECTORS = 64;
|
||||
|
||||
/**
|
||||
* @en Shadow map render flow
|
||||
@@ -83,6 +87,11 @@ export class ShadowFlow extends RenderFlow {
|
||||
const isLinear = pipeline.device.gfxAPI === API.WEBGL ? 1 : 0;
|
||||
pipeline.macros.CC_SHADOWMAP_USE_LINEAR_DEPTH = isLinear;
|
||||
|
||||
// 0: UNIFORM_VECTORS_LESS_EQUAL_64, 1: UNIFORM_VECTORS_GREATER_EQUAL_125.
|
||||
pipeline.pipelineSceneData.csmSupported = pipeline.device.capabilities.maxFragmentUniformVectors
|
||||
>= (CSM_UNIFORM_VECTORS + GLOBAL_UNIFORM_VECTORS);
|
||||
pipeline.macros.CC_SUPPORT_CASCADED_SHADOW_MAP = pipeline.pipelineSceneData.csmSupported;
|
||||
|
||||
pipeline.onGlobalPipelineStateChanged();
|
||||
}
|
||||
|
||||
@@ -127,7 +136,8 @@ export class ShadowFlow extends RenderFlow {
|
||||
if (mainLight.shadowFixedArea) {
|
||||
this._renderStage(camera, mainLight, shadowFrameBuffer!, globalDS);
|
||||
} else {
|
||||
for (let i = 0; i < mainLight.csmLevel; i++) {
|
||||
const csmLevel = pipeline.pipelineSceneData.csmSupported ? mainLight.csmLevel : 1;
|
||||
for (let i = 0; i < csmLevel; i++) {
|
||||
this._renderStage(camera, mainLight, shadowFrameBuffer!, globalDS, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ export class ShadowStage extends RenderStage {
|
||||
switch (this._light.type) {
|
||||
case LightType.DIRECTIONAL: {
|
||||
const mainLight = this._light as DirectionalLight;
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1 || !pipelineSceneData.csmSupported) {
|
||||
this._renderArea.x = 0;
|
||||
this._renderArea.y = 0;
|
||||
this._renderArea.width = shadowMapSize.x;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
// used for replacing cc-shadow-map-base.chunk
|
||||
#include <builtin/uniforms/cc-shadow>
|
||||
#if CC_SUPPORT_CASCADED_SHADOW_MAP
|
||||
#include <builtin/uniforms/cc-csm>
|
||||
#endif
|
||||
#include <common/common-define>
|
||||
#include <common/math/coordinates>
|
||||
|
||||
@@ -211,50 +214,61 @@ float CCGetLinearDepth(vec3 worldPos) {
|
||||
return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
|
||||
}
|
||||
|
||||
|
||||
int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec4 matShadowViewLine0, out vec4 matShadowViewLine1, out vec4 matShadowViewLine2, out vec4 matShadowViewLine3, vec3 worldPos) {
|
||||
int layer = -1;
|
||||
for (int i = 0; i < NUMCASCADES; i++) {
|
||||
vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
|
||||
vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x >= (0.0 + cc_csmInfo.y) && clipPos.x <= (1.0 - cc_csmInfo.y) &&
|
||||
clipPos.y >= (0.0 + cc_csmInfo.y) && clipPos.y <= (1.0 - cc_csmInfo.y) &&
|
||||
clipPos.z >= 0.0 && clipPos.z <= 1.0 && layer < 0) {
|
||||
csmPos = cc_matCSMViewProjAtlas[i] * vec4(worldPos.xyz, 1.0);
|
||||
shadowProjDepthInfo = cc_csmProjDepthInfo[i];
|
||||
shadowProjInfo = cc_csmProjInfo[i];
|
||||
matShadowViewLine0 = cc_matCSMView[i][0];
|
||||
matShadowViewLine1 = cc_matCSMView[i][1];
|
||||
matShadowViewLine2 = cc_matCSMView[i][2];
|
||||
matShadowViewLine3 = cc_matCSMView[i][3];
|
||||
layer = i;
|
||||
#if CC_SUPPORT_CASCADED_SHADOW_MAP
|
||||
int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec4 matShadowViewLine0, out vec4 matShadowViewLine1, out vec4 matShadowViewLine2, out vec4 matShadowViewLine3, vec3 worldPos) {
|
||||
int layer = -1;
|
||||
for (int i = 0; i < NUMCASCADES; i++) {
|
||||
vec4 shadowPos = cc_matCSMViewProj[i] * vec4(worldPos.xyz, 1.0);
|
||||
vec3 clipPos = shadowPos.xyz / shadowPos.w * 0.5 + 0.5;
|
||||
if (clipPos.x >= (0.0 + cc_csmInfo.y) && clipPos.x <= (1.0 - cc_csmInfo.y) &&
|
||||
clipPos.y >= (0.0 + cc_csmInfo.y) && clipPos.y <= (1.0 - cc_csmInfo.y) &&
|
||||
clipPos.z >= 0.0 && clipPos.z <= 1.0 && layer < 0) {
|
||||
csmPos = cc_matCSMViewProjAtlas[i] * vec4(worldPos.xyz, 1.0);
|
||||
shadowProjDepthInfo = cc_csmProjDepthInfo[i];
|
||||
shadowProjInfo = cc_csmProjInfo[i];
|
||||
matShadowViewLine0 = cc_matCSMView[i][0];
|
||||
matShadowViewLine1 = cc_matCSMView[i][1];
|
||||
matShadowViewLine2 = cc_matCSMView[i][2];
|
||||
matShadowViewLine3 = cc_matCSMView[i][3];
|
||||
layer = i;
|
||||
}
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
return layer;
|
||||
}
|
||||
|
||||
float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias)
|
||||
{
|
||||
vec4 csmPos = vec4(1.0);
|
||||
vec4 shadowProjDepthInfo, shadowProjInfo;
|
||||
mat4 matLightView;
|
||||
int level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, matLightView[0], matLightView[1], matLightView[2], matLightView[3], worldPos);
|
||||
if (level < 0) { return 1.0; }
|
||||
float realtimeShadow = 1.0;
|
||||
float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias)
|
||||
{
|
||||
vec4 csmPos = vec4(1.0);
|
||||
vec4 shadowProjDepthInfo, shadowProjInfo;
|
||||
mat4 matLightView;
|
||||
int level = CCGetCSMLevel(csmPos, shadowProjDepthInfo, shadowProjInfo, matLightView[0], matLightView[1], matLightView[2], matLightView[3], worldPos);
|
||||
if (level < 0) { return 1.0; }
|
||||
float realtimeShadow = 1.0;
|
||||
|
||||
vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, matLightView, shadowProjInfo.xy);
|
||||
pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);
|
||||
|
||||
float pcf = cc_shadowWHPBInfo.z;
|
||||
if (pcf > 2.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft5X(pos);
|
||||
} else if (pcf > 1.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);
|
||||
} else if (pcf > 0.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft(pos);
|
||||
}else {
|
||||
realtimeShadow = CCGetDirLightShadowFactorHard(pos);
|
||||
vec4 pos = ApplyShadowDepthBias_FaceNormal(csmPos, N, shadowBias.y, matLightView, shadowProjInfo.xy);
|
||||
pos = ApplyShadowDepthBias_Orthographic(pos, shadowBias.x, shadowProjDepthInfo.x, shadowProjDepthInfo.y);
|
||||
|
||||
float pcf = cc_shadowWHPBInfo.z;
|
||||
if (pcf > 2.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft5X(pos);
|
||||
} else if (pcf > 1.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft3X(pos);
|
||||
} else if (pcf > 0.9) {
|
||||
realtimeShadow = CCGetDirLightShadowFactorSoft(pos);
|
||||
}else {
|
||||
realtimeShadow = CCGetDirLightShadowFactorHard(pos);
|
||||
}
|
||||
return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
|
||||
}
|
||||
return mix(realtimeShadow, 1.0, cc_shadowNFLSInfo.w);
|
||||
}
|
||||
#else
|
||||
int CCGetCSMLevel(out vec4 csmPos, out vec4 shadowProjDepthInfo, out vec4 shadowProjInfo, out vec4 matShadowViewLine0, out vec4 matShadowViewLine1, out vec4 matShadowViewLine2, out vec4 matShadowViewLine3, vec3 worldPos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
float CCCSMFactorBase(vec3 worldPos, vec3 N, vec2 shadowBias) {
|
||||
vec4 shadowPos = cc_matLightViewProj * vec4(worldPos, 1.0);
|
||||
return CCShadowFactorBase(shadowPos, N, shadowBias);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"ver": "1.0.6",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "d4c26490-0a2d-4b6a-9a52-55b5741f18a4",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
#pragma define NUMCASCADES 4
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 3) uniform CCCSM {
|
||||
highp mat4 cc_matCSMView[NUMCASCADES];
|
||||
highp mat4 cc_matCSMViewProj[NUMCASCADES];
|
||||
highp mat4 cc_matCSMViewProjAtlas[NUMCASCADES];
|
||||
highp vec4 cc_csmProjDepthInfo[NUMCASCADES];
|
||||
highp vec4 cc_csmProjInfo[NUMCASCADES];
|
||||
highp vec4 cc_csmSplitsInfo; // x-> level_1 far, y-> level_2 far, z-> level_3 far, w-> level_4 far
|
||||
highp vec4 cc_csmInfo; // y-> radius
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "c3e3500f-370c-4da1-92f9-d0d9fd806bd8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
#pragma define-meta CC_USE_DIFFUSEMAP range([0, 2])
|
||||
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 6) uniform samplerCube cc_diffuseMap;
|
||||
layout(set = 0, binding = 7) uniform samplerCube cc_diffuseMap;
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
#pragma define-meta CC_USE_IBL range([0, 2])
|
||||
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 4) uniform samplerCube cc_environment;
|
||||
layout(set = 0, binding = 5) uniform samplerCube cc_environment;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 3) uniform highp sampler2D cc_shadowMap;
|
||||
layout(set = 0, binding = 4) uniform highp sampler2D cc_shadowMap;
|
||||
|
||||
#pragma builtin(global)
|
||||
layout(set = 0, binding = 5) uniform highp sampler2D cc_spotShadowMap;
|
||||
layout(set = 0, binding = 6) uniform highp sampler2D cc_spotShadowMap;
|
||||
|
||||
@@ -14,11 +14,4 @@ layout(set = 0, binding = 2) uniform CCShadow {
|
||||
mediump vec4 cc_shadowLPNNInfo; // x -> lightType(L); y -> isPacking(P); z -> normalBias(N); w -> CSM level(N);
|
||||
lowp vec4 cc_shadowColor;
|
||||
mediump vec4 cc_planarNDInfo; // xyz -> normalized plane (N); w -> plane (D);
|
||||
highp mat4 cc_matCSMView[NUMCASCADES];
|
||||
highp mat4 cc_matCSMViewProj[NUMCASCADES];
|
||||
highp mat4 cc_matCSMViewProjAtlas[NUMCASCADES];
|
||||
highp vec4 cc_csmProjDepthInfo[NUMCASCADES];
|
||||
highp vec4 cc_csmProjInfo[NUMCASCADES];
|
||||
highp vec4 cc_csmSplitsInfo; // x-> level_1 far, y-> level_2 far, z-> level_3 far, w-> level_4 far
|
||||
highp vec4 cc_csmInfo; // y-> radius
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"ver": "1.0.6",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "b2e7c003-9c9f-40ee-82c6-32d920a759e8",
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
|
||||
// Uniforms--Tex
|
||||
#include <builtin/uniforms/cc-shadow>
|
||||
#if CC_SUPPORT_CASCADED_SHADOW_MAP
|
||||
#include <builtin/uniforms/cc-csm>
|
||||
#endif
|
||||
#if CC_USE_IBL
|
||||
#include <builtin/uniforms/cc-environment>
|
||||
#if CC_USE_DIFFUSEMAP
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"ver": "1.0.6",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "a6451dbc-fc4c-4a10-84f5-072c6e982fa5",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"ver": "1.0.6",
|
||||
"importer": "effect-header",
|
||||
"imported": true,
|
||||
"uuid": "c66380b2-694f-40bd-afd8-91a2e58d904d",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "1baf0fc9-befa-459c-8bdd-af1a450a0319",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "1d08ef62-a503-4ce2-8b9a-46c90873f7d3",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "a7612b54-35e3-4238-a1a9-4a7b54635839",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "2ec11458-f855-4978-b14d-f3ed5cf697fa",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "f648964e-8d32-41fc-9ac9-7a1e714dd17b",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ver": "1.5.7",
|
||||
"ver": "1.5.8",
|
||||
"importer": "effect",
|
||||
"imported": true,
|
||||
"uuid": "9361fd90-ba52-4f84-aa93-6e878fd576ca",
|
||||
|
||||
@@ -158,11 +158,28 @@ const gfx::UniformBlock UBOShadow::LAYOUT = {
|
||||
{"cc_shadowLPNNInfo", gfx::Type::FLOAT4, 1},
|
||||
{"cc_shadowColor", gfx::Type::FLOAT4, 1},
|
||||
{"cc_planarNDInfo", gfx::Type::FLOAT4, 1},
|
||||
{"cc_matCSMView", gfx::Type::MAT4, UBOShadow::CSM_LEVEL_COUNT},
|
||||
{"cc_matCSMViewProj", gfx::Type::MAT4, UBOShadow::CSM_LEVEL_COUNT},
|
||||
{"cc_matCSMViewProjAtlas", gfx::Type::MAT4, UBOShadow::CSM_LEVEL_COUNT},
|
||||
{"cc_csmProjDepthInfo", gfx::Type::FLOAT4, UBOShadow::CSM_LEVEL_COUNT},
|
||||
{"cc_csmProjInfo", gfx::Type::FLOAT4, UBOShadow::CSM_LEVEL_COUNT},
|
||||
},
|
||||
1,
|
||||
};
|
||||
|
||||
const ccstd::string UBOCSM::NAME = "CCCSM";
|
||||
const gfx::DescriptorSetLayoutBinding UBOCSM::DESCRIPTOR = {
|
||||
UBOCSM::BINDING,
|
||||
gfx::DescriptorType::UNIFORM_BUFFER,
|
||||
1,
|
||||
gfx::ShaderStageFlagBit::ALL,
|
||||
{},
|
||||
};
|
||||
const gfx::UniformBlock UBOCSM::LAYOUT = {
|
||||
globalSet,
|
||||
UBOCSM::BINDING,
|
||||
UBOCSM::NAME,
|
||||
{
|
||||
{"cc_matCSMView", gfx::Type::MAT4, UBOCSM::CSM_LEVEL_COUNT},
|
||||
{"cc_matCSMViewProj", gfx::Type::MAT4, UBOCSM::CSM_LEVEL_COUNT},
|
||||
{"cc_matCSMViewProjAtlas", gfx::Type::MAT4, UBOCSM::CSM_LEVEL_COUNT},
|
||||
{"cc_csmProjDepthInfo", gfx::Type::FLOAT4, UBOCSM::CSM_LEVEL_COUNT},
|
||||
{"cc_csmProjInfo", gfx::Type::FLOAT4, UBOCSM::CSM_LEVEL_COUNT},
|
||||
{"cc_csmSplitsInfo", gfx::Type::FLOAT4, 1},
|
||||
{"cc_csmInfo", gfx::Type::FLOAT4, 1},
|
||||
},
|
||||
|
||||
@@ -224,6 +224,7 @@ enum class CC_DLL PipelineGlobalBindings {
|
||||
UBO_GLOBAL,
|
||||
UBO_CAMERA,
|
||||
UBO_SHADOW,
|
||||
UBO_CSM, // should reserve slot for this optional ubo
|
||||
|
||||
SAMPLER_SHADOWMAP,
|
||||
SAMPLER_ENVIRONMENT,
|
||||
@@ -459,7 +460,6 @@ struct CC_DLL UBOCamera {
|
||||
};
|
||||
|
||||
struct CC_DLL UBOShadow {
|
||||
static constexpr uint32_t CSM_LEVEL_COUNT = 4;
|
||||
static constexpr uint32_t MAT_LIGHT_PLANE_PROJ_OFFSET = 0;
|
||||
static constexpr uint32_t MAT_LIGHT_VIEW_OFFSET = MAT_LIGHT_PLANE_PROJ_OFFSET + 16;
|
||||
static constexpr uint32_t MAT_LIGHT_VIEW_PROJ_OFFSET = UBOShadow::MAT_LIGHT_VIEW_OFFSET + 16;
|
||||
@@ -471,14 +471,7 @@ struct CC_DLL UBOShadow {
|
||||
static constexpr uint32_t SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET = UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t SHADOW_COLOR_OFFSET = UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t PLANAR_NORMAL_DISTANCE_INFO_OFFSET = UBOShadow::SHADOW_COLOR_OFFSET + 4;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_LEVELS_OFFSET = UBOShadow::PLANAR_NORMAL_DISTANCE_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_PROJ_LEVELS_OFFSET = UBOShadow::MAT_CSM_VIEW_LEVELS_OFFSET + 16 * UBOShadow::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET = UBOShadow::MAT_CSM_VIEW_PROJ_LEVELS_OFFSET + 16 * UBOShadow::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET = UBOShadow::MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET + 16 * UBOShadow::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_PROJ_INFO_LEVELS_OFFSET = UBOShadow::CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET + 4 * UBOShadow::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_SPLITS_INFO_OFFSET = UBOShadow::CSM_PROJ_INFO_LEVELS_OFFSET + 4 * UBOShadow::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_INFO_OFFSET = UBOShadow::CSM_SPLITS_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t COUNT = UBOShadow::CSM_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t COUNT = UBOShadow::PLANAR_NORMAL_DISTANCE_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t SIZE = UBOShadow::COUNT * 4;
|
||||
static constexpr uint32_t BINDING = static_cast<uint32_t>(PipelineGlobalBindings::UBO_SHADOW);
|
||||
static const gfx::DescriptorSetLayoutBinding DESCRIPTOR;
|
||||
@@ -486,6 +479,23 @@ struct CC_DLL UBOShadow {
|
||||
static const ccstd::string NAME;
|
||||
};
|
||||
|
||||
struct CC_DLL UBOCSM {
|
||||
static constexpr uint32_t CSM_LEVEL_COUNT = 4;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_LEVELS_OFFSET = 0;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_PROJ_LEVELS_OFFSET = UBOCSM::MAT_CSM_VIEW_LEVELS_OFFSET + 16 * UBOCSM::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET = UBOCSM::MAT_CSM_VIEW_PROJ_LEVELS_OFFSET + 16 * UBOCSM::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET = UBOCSM::MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET + 16 * UBOCSM::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_PROJ_INFO_LEVELS_OFFSET = UBOCSM::CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET + 4 * UBOCSM::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_SPLITS_INFO_OFFSET = UBOCSM::CSM_PROJ_INFO_LEVELS_OFFSET + 4 * UBOCSM::CSM_LEVEL_COUNT;
|
||||
static constexpr uint32_t CSM_INFO_OFFSET = UBOCSM::CSM_SPLITS_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t COUNT = UBOCSM::CSM_INFO_OFFSET + 4;
|
||||
static constexpr uint32_t SIZE = UBOCSM::COUNT * 4;
|
||||
static constexpr uint32_t BINDING = static_cast<uint32_t>(PipelineGlobalBindings::UBO_CSM);
|
||||
static const gfx::DescriptorSetLayoutBinding DESCRIPTOR;
|
||||
static const gfx::UniformBlock LAYOUT;
|
||||
static const ccstd::string NAME;
|
||||
};
|
||||
|
||||
struct CC_DLL DescriptorSetLayoutInfos {
|
||||
gfx::DescriptorSetLayoutBindingList bindings;
|
||||
ccstd::unordered_map<ccstd::string, gfx::UniformBlock> blocks;
|
||||
|
||||
@@ -181,6 +181,8 @@ void GlobalDSManager::setDescriptorSetLayout() {
|
||||
globalDescriptorSetLayout.bindings[UBOCamera::BINDING] = UBOCamera::DESCRIPTOR;
|
||||
globalDescriptorSetLayout.blocks[UBOShadow::NAME] = UBOShadow::LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UBOShadow::BINDING] = UBOShadow::DESCRIPTOR;
|
||||
globalDescriptorSetLayout.blocks[UBOCSM::NAME] = UBOCSM::LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[UBOCSM::BINDING] = UBOCSM::DESCRIPTOR;
|
||||
globalDescriptorSetLayout.samplers[SHADOWMAP::NAME] = SHADOWMAP::LAYOUT;
|
||||
globalDescriptorSetLayout.bindings[SHADOWMAP::BINDING] = SHADOWMAP::DESCRIPTOR;
|
||||
globalDescriptorSetLayout.samplers[ENVIRONMENT::NAME] = ENVIRONMENT::LAYOUT;
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
inline void clearValidPunctualLights() { _validPunctualLights.clear(); }
|
||||
inline float getShadingScale() const { return _shadingScale; }
|
||||
inline void setShadingScale(float val) { _shadingScale = val; }
|
||||
inline bool getCSMSupported() const { return _csmSupported; }
|
||||
inline void setCSMSupported(bool val) { _csmSupported = val; }
|
||||
|
||||
protected:
|
||||
void initOcclusionQuery();
|
||||
@@ -92,26 +94,17 @@ protected:
|
||||
|
||||
static constexpr uint32_t GEOMETRY_RENDERER_TECHNIQUE_COUNT{6};
|
||||
|
||||
RenderObjectList _renderObjects;
|
||||
// `scene::Light *`: weak reference
|
||||
ccstd::vector<const scene::Light *> _validPunctualLights;
|
||||
IntrusivePtr<gfx::Buffer> _occlusionQueryVertexBuffer;
|
||||
IntrusivePtr<gfx::Buffer> _occlusionQueryIndicesBuffer;
|
||||
IntrusivePtr<gfx::InputAssembler> _occlusionQueryInputAssembler;
|
||||
|
||||
IntrusivePtr<Material> _occlusionQueryMaterial{nullptr};
|
||||
IntrusivePtr<Material> _debugRendererMaterial{nullptr};
|
||||
|
||||
gfx::Shader *_occlusionQueryShader{nullptr}; // weak reference
|
||||
scene::Pass *_occlusionQueryPass{nullptr}; // weak reference
|
||||
|
||||
ccstd::vector<IntrusivePtr<Material>> _geometryRendererMaterials;
|
||||
ccstd::vector<scene::Pass *> _geometryRendererPasses; // weak reference
|
||||
ccstd::vector<gfx::Shader *> _geometryRendererShaders; // weak reference
|
||||
|
||||
IntrusivePtr<Material> _debugRendererMaterial{nullptr};
|
||||
gfx::Shader *_debugRendererShader{nullptr}; // weak reference
|
||||
scene::Pass *_debugRendererPass{nullptr}; // weak reference
|
||||
gfx::Device *_device{nullptr}; // weak reference
|
||||
|
||||
gfx::Shader *_debugRendererShader{nullptr}; // weak reference
|
||||
scene::Pass *_debugRendererPass{nullptr}; // weak reference
|
||||
gfx::Device *_device{nullptr}; // weak reference
|
||||
// manage memory manually
|
||||
scene::Fog *_fog{nullptr};
|
||||
// manage memory manually
|
||||
@@ -124,9 +117,20 @@ protected:
|
||||
scene::Octree *_octree{nullptr};
|
||||
// manage memory manually
|
||||
CSMLayers *_csmLayers{nullptr};
|
||||
|
||||
bool _isHDR{true};
|
||||
bool _csmSupported{true};
|
||||
|
||||
float _shadingScale{1.0F};
|
||||
|
||||
RenderObjectList _renderObjects;
|
||||
|
||||
ccstd::vector<IntrusivePtr<Material>> _geometryRendererMaterials;
|
||||
// `scene::Light *`: weak reference
|
||||
ccstd::vector<const scene::Light *> _validPunctualLights;
|
||||
ccstd::vector<scene::Pass *> _geometryRendererPasses; // weak reference
|
||||
ccstd::vector<gfx::Shader *> _geometryRendererShaders; // weak reference
|
||||
|
||||
ccstd::unordered_map<const scene::Light *, IntrusivePtr<gfx::Framebuffer>> _shadowFrameBufferMap;
|
||||
};
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out
|
||||
}
|
||||
|
||||
void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, ccstd::array<float, UBOShadow::COUNT> *shadowBufferView,
|
||||
const scene::Camera *camera) {
|
||||
ccstd::array<float, UBOCSM::COUNT> *csmBufferView, const scene::Camera *camera) {
|
||||
const scene::RenderScene *const scene = camera->getScene();
|
||||
const scene::DirectionalLight *mainLight = scene->getMainLight();
|
||||
gfx::Device *device = gfx::Device::getInstance();
|
||||
@@ -201,13 +201,15 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, ccstd::arr
|
||||
const CSMLayers *csmLayers = sceneData->getCSMLayers();
|
||||
scene::Shadows *const shadowInfo = sceneData->getShadows();
|
||||
ccstd::array<float, UBOShadow::COUNT> &sv = *shadowBufferView;
|
||||
ccstd::array<float, UBOCSM::COUNT> &cv = *csmBufferView;
|
||||
const bool hFTexture = supportsR32FloatTexture(device);
|
||||
const float packing = hFTexture ? 0.0F : 1.0F;
|
||||
const bool csmSupported = sceneData->getCSMSupported();
|
||||
|
||||
if (shadowInfo->isEnabled() && mainLight) {
|
||||
if (shadowInfo->getType() == scene::ShadowType::SHADOW_MAP) {
|
||||
if (mainLight->isShadowEnabled()) {
|
||||
if (mainLight->isShadowFixedArea() || mainLight->getCSMLevel() == scene::CSMLevel::LEVEL_1) {
|
||||
if (mainLight->isShadowFixedArea() || mainLight->getCSMLevel() == scene::CSMLevel::LEVEL_1 || !csmSupported) {
|
||||
const Mat4 &matShadowView = csmLayers->getSpecialLayer()->getMatShadowView();
|
||||
const Mat4 &matShadowProj = csmLayers->getSpecialLayer()->getMatShadowProj();
|
||||
const Mat4 &matShadowViewProj = csmLayers->getSpecialLayer()->getMatShadowViewProj();
|
||||
@@ -232,29 +234,29 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, ccstd::arr
|
||||
memcpy(sv.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos));
|
||||
} else {
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(mainLight->getCSMLevel()); ++i) {
|
||||
sv[UBOShadow::CSM_SPLITS_INFO_OFFSET + i] = csmLayers->getLayers()[i]->getSplitCameraFar() / mainLight->getShadowDistance();
|
||||
cv[UBOCSM::CSM_SPLITS_INFO_OFFSET + i] = csmLayers->getLayers()[i]->getSplitCameraFar() / mainLight->getShadowDistance();
|
||||
|
||||
const Mat4 &matShadowView = csmLayers->getLayers()[i]->getMatShadowView();
|
||||
memcpy(sv.data() + UBOShadow::MAT_CSM_VIEW_LEVELS_OFFSET + i * 16, matShadowView.m, sizeof(matShadowView));
|
||||
memcpy(cv.data() + UBOCSM::MAT_CSM_VIEW_LEVELS_OFFSET + i * 16, matShadowView.m, sizeof(matShadowView));
|
||||
|
||||
const Mat4 &matShadowViewProj = csmLayers->getLayers()[i]->getMatShadowViewProj();
|
||||
memcpy(sv.data() + UBOShadow::MAT_CSM_VIEW_PROJ_LEVELS_OFFSET + i * 16, matShadowViewProj.m, sizeof(matShadowViewProj));
|
||||
memcpy(cv.data() + UBOCSM::MAT_CSM_VIEW_PROJ_LEVELS_OFFSET + i * 16, matShadowViewProj.m, sizeof(matShadowViewProj));
|
||||
|
||||
const Mat4 &matShadowViewProjAtlas = csmLayers->getLayers()[i]->getMatShadowViewProjAtlas();
|
||||
memcpy(sv.data() + UBOShadow::MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET + i * 16, matShadowViewProjAtlas.m, sizeof(matShadowViewProjAtlas));
|
||||
memcpy(cv.data() + UBOCSM::MAT_CSM_VIEW_PROJ_ATLAS_LEVELS_OFFSET + i * 16, matShadowViewProjAtlas.m, sizeof(matShadowViewProjAtlas));
|
||||
|
||||
const Mat4 &matShadowProj = csmLayers->getLayers()[i]->getMatShadowProj();
|
||||
const float shadowProjDepthInfos[4] = {matShadowProj.m[10], matShadowProj.m[14], matShadowProj.m[11], matShadowProj.m[15]};
|
||||
memcpy(sv.data() + UBOShadow::CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET + i * 4, &shadowProjDepthInfos, sizeof(shadowProjDepthInfos));
|
||||
memcpy(cv.data() + UBOCSM::CSM_PROJ_DEPTH_INFO_LEVELS_OFFSET + i * 4, &shadowProjDepthInfos, sizeof(shadowProjDepthInfos));
|
||||
|
||||
const float shadowProjInfos[4] = {matShadowProj.m[00], matShadowProj.m[05], 1.0F / matShadowProj.m[00], 1.0F / matShadowProj.m[05]};
|
||||
memcpy(sv.data() + UBOShadow::CSM_PROJ_INFO_LEVELS_OFFSET + i * 4, &shadowProjInfos, sizeof(shadowProjInfos));
|
||||
memcpy(cv.data() + UBOCSM::CSM_PROJ_INFO_LEVELS_OFFSET + i * 4, &shadowProjInfos, sizeof(shadowProjInfos));
|
||||
}
|
||||
|
||||
sv[UBOShadow::CSM_INFO_OFFSET + 0] = 0.0F;
|
||||
sv[UBOShadow::CSM_INFO_OFFSET + 1] = getPCFRadius(shadowInfo, mainLight);
|
||||
sv[UBOShadow::CSM_INFO_OFFSET + 2] = 0.0F;
|
||||
sv[UBOShadow::CSM_INFO_OFFSET + 3] = 0.0F;
|
||||
cv[UBOCSM::CSM_INFO_OFFSET + 0] = 0.0F;
|
||||
cv[UBOCSM::CSM_INFO_OFFSET + 1] = getPCFRadius(shadowInfo, mainLight);
|
||||
cv[UBOCSM::CSM_INFO_OFFSET + 2] = 0.0F;
|
||||
cv[UBOCSM::CSM_INFO_OFFSET + 3] = 0.0F;
|
||||
|
||||
const float shadowNFLSInfos[4] = {0.0F, 0.0F, 0.0F, 1.0F - mainLight->getShadowSaturation()};
|
||||
memcpy(sv.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos));
|
||||
@@ -443,6 +445,16 @@ void PipelineUBO::activate(gfx::Device *device, RenderPipeline *pipeline) {
|
||||
descriptorSet->bindBuffer(UBOShadow::BINDING, shadowUBO);
|
||||
_ubos.push_back(shadowUBO);
|
||||
|
||||
auto *csmUBO = _device->createBuffer({
|
||||
gfx::BufferUsageBit::UNIFORM | gfx::BufferUsageBit::TRANSFER_DST,
|
||||
gfx::MemoryUsageBit::DEVICE,
|
||||
UBOCSM::SIZE,
|
||||
UBOCSM::SIZE,
|
||||
gfx::BufferFlagBit::NONE,
|
||||
});
|
||||
descriptorSet->bindBuffer(UBOCSM::BINDING, csmUBO);
|
||||
_ubos.push_back(csmUBO);
|
||||
|
||||
_shadowUBOUpdated = false;
|
||||
}
|
||||
|
||||
@@ -514,9 +526,10 @@ void PipelineUBO::updateShadowUBO(const scene::Camera *camera) {
|
||||
}
|
||||
}
|
||||
}
|
||||
updateShadowUBOView(_pipeline, &_shadowUBO, camera);
|
||||
updateShadowUBOView(_pipeline, &_shadowUBO, &_csmUBO, camera);
|
||||
ds->update();
|
||||
cmdBuffer->updateBuffer(ds->getBuffer(UBOShadow::BINDING), _shadowUBO.data(), UBOShadow::SIZE);
|
||||
cmdBuffer->updateBuffer(ds->getBuffer(UBOCSM::BINDING), _csmUBO.data(), UBOCSM::SIZE);
|
||||
}
|
||||
|
||||
void PipelineUBO::updateShadowUBOLight(gfx::DescriptorSet *globalDS, const scene::Light *light, uint32_t level) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
static void updateGlobalUBOView(const scene::Camera *camera, ccstd::array<float, UBOGlobal::COUNT> *bufferView);
|
||||
static void updateCameraUBOView(const RenderPipeline *pipeline, float *output, const scene::Camera *camera);
|
||||
static void updateShadowUBOView(const RenderPipeline *pipeline, ccstd::array<float, UBOShadow::COUNT> *shadowBufferView,
|
||||
const scene::Camera *camera);
|
||||
ccstd::array<float, UBOCSM::COUNT> *csmBufferView, const scene::Camera *camera);
|
||||
static void updateShadowUBOLightView(const RenderPipeline *pipeline, ccstd::array<float, UBOShadow::COUNT> *shadowBufferView,
|
||||
const scene::Light *light, uint32_t level);
|
||||
static uint8_t getCombineSignY();
|
||||
@@ -69,19 +69,21 @@ private:
|
||||
RenderPipeline *_pipeline{nullptr};
|
||||
// weak reference
|
||||
gfx::Device *_device{nullptr};
|
||||
// weak reference, it is recorded in _ubos
|
||||
gfx::Buffer *_cameraBuffer{nullptr};
|
||||
|
||||
uint32_t _currentCameraUBOOffset{0};
|
||||
uint32_t _alignedCameraUBOSize{0};
|
||||
|
||||
bool _shadowUBOUpdated{false};
|
||||
|
||||
ccstd::array<float, UBOGlobal::COUNT> _globalUBO;
|
||||
ccstd::array<float, UBOShadow::COUNT> _shadowUBO;
|
||||
ccstd::array<float, UBOCSM::COUNT> _csmUBO;
|
||||
|
||||
// manage memory manually
|
||||
ccstd::vector<gfx::Buffer *> _ubos;
|
||||
ccstd::vector<float> _cameraUBOs;
|
||||
|
||||
// weak reference, it is recorded in _ubos
|
||||
gfx::Buffer *_cameraBuffer{nullptr};
|
||||
uint32_t _currentCameraUBOOffset{0};
|
||||
uint32_t _alignedCameraUBOSize{0};
|
||||
bool _shadowUBOUpdated{false};
|
||||
};
|
||||
|
||||
} // namespace pipeline
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "CSMLayers.h"
|
||||
#include "core/Root.h"
|
||||
#include "gfx-base/GFXDevice.h"
|
||||
#include "math/Quaternion.h"
|
||||
#include "pipeline/PipelineSceneData.h"
|
||||
#include "pipeline/RenderPipeline.h"
|
||||
#include "pipeline/custom/RenderInterfaceTypes.h"
|
||||
#include "scene/RenderScene.h"
|
||||
#include "scene/Shadow.h"
|
||||
|
||||
@@ -39,6 +41,7 @@ ShadowTransformInfo::ShadowTransformInfo(uint32_t level):_level(level) {
|
||||
void ShadowTransformInfo::createMatrix(const geometry::Frustum &splitFrustum, const scene::DirectionalLight *dirLight, float shadowMapWidth, bool isOnlyCulling) {
|
||||
const float invisibleOcclusionRange = dirLight->getShadowInvisibleOcclusionRange();
|
||||
const gfx::Device *device = gfx::Device::getInstance();
|
||||
const Root *root = Root::getInstance();
|
||||
geometry::Frustum::copy(&_lightViewFrustum, splitFrustum);
|
||||
const float projectionSinY = device->getCapabilities().clipSpaceSignY;
|
||||
const float clipSpaceMinZ = device->getCapabilities().clipSpaceMinZ;
|
||||
@@ -64,9 +67,10 @@ void ShadowTransformInfo::createMatrix(const geometry::Frustum &splitFrustum, co
|
||||
orthoSizeWidth = orthoSizeHeight = _lightViewFrustum.vertices[0].distance(_lightViewFrustum.vertices[6]);
|
||||
}
|
||||
|
||||
if (dirLight->getCSMLevel() != scene::CSMLevel::LEVEL_1 && dirLight->getCSMOptimizationMode() ==
|
||||
const auto csmLevel = root->getPipeline()->getPipelineSceneData()->getCSMSupported() ? dirLight->getCSMLevel() : scene::CSMLevel::LEVEL_1;
|
||||
if (csmLevel != scene::CSMLevel::LEVEL_1 && dirLight->getCSMOptimizationMode() ==
|
||||
scene::CSMOptimizationMode::REMOVE_DUPLICATES) {
|
||||
if (_level >= static_cast<uint32_t>(dirLight->getCSMLevel()) - 1U) {
|
||||
if (_level >= static_cast<uint32_t>(csmLevel) - 1U) {
|
||||
_maxLayerFarPlane = _castLightViewBoundingBox.halfExtents.z;
|
||||
_maxLayerPosz = _castLightViewBoundingBox.center.z;
|
||||
} else {
|
||||
@@ -168,11 +172,13 @@ void CSMLayers::update(const PipelineSceneData *sceneData, const scene::Camera *
|
||||
|
||||
const scene::Shadows *shadowInfo = sceneData->getShadows();
|
||||
const scene::RenderScene *const scene = camera->getScene();
|
||||
const Root *root = Root::getInstance();
|
||||
scene::DirectionalLight *dirLight = scene->getMainLight();
|
||||
|
||||
CC_ASSERT(dirLight);
|
||||
|
||||
const auto levelCount = static_cast<uint32_t>(dirLight->getCSMLevel());
|
||||
const auto levelCount = root->getPipeline()->getPipelineSceneData()->getCSMSupported() ?
|
||||
static_cast<uint32_t>(dirLight->getCSMLevel()) : 1U;
|
||||
CC_ASSERT(levelCount <= static_cast<uint32_t>(scene::CSMLevel::LEVEL_4));
|
||||
const float shadowDistance = dirLight->getShadowDistance();
|
||||
|
||||
@@ -220,10 +226,12 @@ void CSMLayers::updateFixedArea(const scene::DirectionalLight *dirLight) const {
|
||||
}
|
||||
|
||||
void CSMLayers::splitFrustumLevels(scene::DirectionalLight *dirLight) {
|
||||
const Root *root = Root::getInstance();
|
||||
constexpr float nd = 0.1F;
|
||||
const float fd = dirLight->getShadowDistance();
|
||||
const float ratio = fd / nd;
|
||||
const auto level = static_cast<uint32_t>(dirLight->getCSMLevel());
|
||||
const auto level = root->getPipeline()->getPipelineSceneData()->getCSMSupported() ?
|
||||
static_cast<uint32_t>(dirLight->getCSMLevel()) : 1U;
|
||||
const float lambda = dirLight->getCSMLayerLambda();
|
||||
_layers.at(0)->setSplitCameraNear(nd);
|
||||
for (uint32_t i = 1; i < level; ++i) {
|
||||
@@ -242,7 +250,9 @@ void CSMLayers::splitFrustumLevels(scene::DirectionalLight *dirLight) {
|
||||
}
|
||||
|
||||
void CSMLayers::calculateCSM(const scene::Camera *camera, const scene::DirectionalLight *dirLight, const scene::Shadows *shadowInfo) {
|
||||
const auto level = dirLight->getCSMLevel();
|
||||
const Root *root = Root::getInstance();
|
||||
const auto level = root->getPipeline()->getPipelineSceneData()->getCSMSupported() ?
|
||||
dirLight->getCSMLevel() : scene::CSMLevel::LEVEL_1;
|
||||
const float shadowMapWidth = level != scene::CSMLevel::LEVEL_1 ? shadowInfo->getSize().x * 0.5F : shadowInfo->getSize().x;
|
||||
|
||||
if (shadowMapWidth < 0.999F) {
|
||||
|
||||
@@ -77,6 +77,12 @@ void ShadowFlow::activate(RenderPipeline *pipeline) {
|
||||
const int32_t isLinear = 0;
|
||||
pipeline->setValue("CC_SHADOWMAP_USE_LINEAR_DEPTH", isLinear);
|
||||
|
||||
// 0: UNIFORM_VECTORS_LESS_EQUAL_64, 1: UNIFORM_VECTORS_GREATER_EQUAL_125.
|
||||
const auto csmSupported = pipeline->getDevice()->getCapabilities().maxFragmentUniformVectors >=
|
||||
CSM_UNIFORM_VECTORS + GLOBAL_UNIFORM_VECTORS;
|
||||
pipeline->getPipelineSceneData()->setCSMSupported(csmSupported);
|
||||
pipeline->setValue("CC_SUPPORT_CASCADED_SHADOW_MAP", csmSupported);
|
||||
|
||||
pipeline->onGlobalPipelineStateChanged();
|
||||
}
|
||||
|
||||
@@ -117,7 +123,8 @@ void ShadowFlow::render(scene::Camera *camera) {
|
||||
if (mainLight->isShadowFixedArea()) {
|
||||
renderStage(globalDS, camera, mainLight, shadowFrameBuffer);
|
||||
} else {
|
||||
for (uint32_t i = 0; i < static_cast<uint32_t>(mainLight->getCSMLevel()); ++i) {
|
||||
const auto level = _pipeline->getPipelineSceneData()->getCSMSupported() ? static_cast<uint32_t>(mainLight->getCSMLevel()) : 1U;
|
||||
for (uint32_t i = 0; i < level; ++i) {
|
||||
renderStage(globalDS, camera, mainLight, shadowFrameBuffer, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ private:
|
||||
void initShadowFrameBuffer(const RenderPipeline* pipeline, const scene::Light* light);
|
||||
|
||||
static RenderFlowInfo initInfo;
|
||||
// csm uniform used vectors count.
|
||||
static const uint32_t CSM_UNIFORM_VECTORS = 61U;
|
||||
// all global uniform used vectors count.
|
||||
static const uint32_t GLOBAL_UNIFORM_VECTORS = 64U;
|
||||
|
||||
// weak reference
|
||||
gfx::RenderPass *_renderPass{nullptr};
|
||||
|
||||
@@ -93,7 +93,7 @@ void ShadowStage::render(scene::Camera *camera) {
|
||||
switch (_light->getType()) {
|
||||
case scene::LightType::DIRECTIONAL: {
|
||||
const auto* mainLight = static_cast<const scene::DirectionalLight *>(_light);
|
||||
if (mainLight->isShadowFixedArea() || mainLight->getCSMLevel() == scene::CSMLevel::LEVEL_1) {
|
||||
if (mainLight->isShadowFixedArea() || mainLight->getCSMLevel() == scene::CSMLevel::LEVEL_1 || !sceneData->getCSMSupported()) {
|
||||
_renderArea.x = 0;
|
||||
_renderArea.y = 0;
|
||||
_renderArea.width = static_cast<uint32_t>(shadowMapSize.x);
|
||||
|
||||
@@ -57,7 +57,7 @@ skip = ForwardPipeline::[getOrCreateRenderPass getLightsUBO getValidLights getLi
|
||||
PostProcessStage::[initialize activate destroy render getUIPhase getUIPhase],
|
||||
GlobalDSManager::[activate destroy],
|
||||
GeometryRenderer::[activate render destroy],
|
||||
PipelineSceneData::[(g|s)etRenderObjects (g|s)etShadowObjects getShadowFramebufferMap getCSMLayers],
|
||||
PipelineSceneData::[(g|s)etRenderObjects (g|s)etShadowObjects getShadowFramebufferMap getCSMLayers (g|s)etCSMSupported],
|
||||
CSMLayers::[update (g|s)etCastShadowObjects addCastShadowObject clearCastShadowObjects (g|s)etLayerObjects addLayerObject clearLayerObjects getLayers getSpecialLayer]
|
||||
|
||||
rename_functions =
|
||||
|
||||
Reference in New Issue
Block a user