@zephyr3d/scene 0.9.15 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/engine.js +3 -1
- package/dist/app/engine.js.map +1 -1
- package/dist/asset/assetmanager.js +1 -0
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/camera/camera.js +87 -0
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +152 -4
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/material/meshmaterial.js +8 -1
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/shader/helper.js +6 -0
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/skin.js +263 -0
- package/dist/material/skin.js.map +1 -0
- package/dist/posteffect/compositor.js +3 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/skinsss.js +194 -0
- package/dist/posteffect/skinsss.js.map +1 -0
- package/dist/posteffect/ssr.js +26 -49
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1 -0
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +2 -40
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +1 -0
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/drawable_mixin.js +1 -0
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +1 -0
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +1 -0
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +1 -0
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +4 -1
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +1 -0
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +1 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +41 -41
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +78 -8
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/scene/basesprite.js +1 -0
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +1 -0
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +1 -0
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +6 -4
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +1 -0
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/msdftext.js +1 -0
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +1 -0
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +1 -0
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +1 -0
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +1 -0
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +1 -0
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +1 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +1 -0
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +504 -1
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +1 -0
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +1 -0
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +1 -0
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +181 -0
- package/dist/shadow/pcss.js.map +1 -0
- package/dist/shadow/shader.js +1 -0
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +86 -8
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +1 -0
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +1 -0
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +1 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +1 -0
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +122 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +1 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +82 -21
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +195 -3
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +1 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +1 -0
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +1 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +1 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +1 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +1 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +1 -0
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +1 -0
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/values.js +1 -0
- package/dist/values.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { ShadowImpl } from './shadow_impl.js';
|
|
3
|
+
import { computeShadowMapDepth, computeReceiverPlaneDepthBias, filterShadowPCSS } from '../shaders/shadow.js';
|
|
4
|
+
import { decodeNormalizedFloatFromRGBA } from '../shaders/misc.js';
|
|
5
|
+
import { LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
6
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
7
|
+
import { computeShadowBiasCSM, computeShadowBias } from './shader.js';
|
|
8
|
+
import { getDevice } from '../app/api.js';
|
|
9
|
+
|
|
10
|
+
/** @internal */ class PCSS extends ShadowImpl {
|
|
11
|
+
_lightRadius;
|
|
12
|
+
_blockerSampleCount;
|
|
13
|
+
_filterSampleCount;
|
|
14
|
+
_maxFilterRadius;
|
|
15
|
+
_temporalJitter;
|
|
16
|
+
constructor(lightRadius, blockerSampleCount, filterSampleCount, maxFilterRadius, temporalJitter){
|
|
17
|
+
super();
|
|
18
|
+
this._lightRadius = lightRadius ?? 8;
|
|
19
|
+
this._blockerSampleCount = blockerSampleCount ?? 24;
|
|
20
|
+
this._filterSampleCount = filterSampleCount ?? 32;
|
|
21
|
+
this._maxFilterRadius = maxFilterRadius ?? 32;
|
|
22
|
+
this._temporalJitter = temporalJitter ?? true;
|
|
23
|
+
}
|
|
24
|
+
get lightRadius() {
|
|
25
|
+
return this._lightRadius;
|
|
26
|
+
}
|
|
27
|
+
set lightRadius(val) {
|
|
28
|
+
this._lightRadius = Math.max(0, Number(val) || 0);
|
|
29
|
+
}
|
|
30
|
+
get blockerSampleCount() {
|
|
31
|
+
return this._blockerSampleCount;
|
|
32
|
+
}
|
|
33
|
+
set blockerSampleCount(val) {
|
|
34
|
+
this._blockerSampleCount = Math.min(Math.max(1, Number(val) >> 0), 64);
|
|
35
|
+
}
|
|
36
|
+
get filterSampleCount() {
|
|
37
|
+
return this._filterSampleCount;
|
|
38
|
+
}
|
|
39
|
+
set filterSampleCount(val) {
|
|
40
|
+
this._filterSampleCount = Math.min(Math.max(1, Number(val) >> 0), 64);
|
|
41
|
+
}
|
|
42
|
+
get maxFilterRadius() {
|
|
43
|
+
return this._maxFilterRadius;
|
|
44
|
+
}
|
|
45
|
+
set maxFilterRadius(val) {
|
|
46
|
+
this._maxFilterRadius = Math.max(1, Number(val) || 1);
|
|
47
|
+
}
|
|
48
|
+
get temporalJitter() {
|
|
49
|
+
return this._temporalJitter;
|
|
50
|
+
}
|
|
51
|
+
set temporalJitter(val) {
|
|
52
|
+
this._temporalJitter = !!val;
|
|
53
|
+
}
|
|
54
|
+
getType() {
|
|
55
|
+
return 'pcss';
|
|
56
|
+
}
|
|
57
|
+
dispose() {}
|
|
58
|
+
resourceDirty() {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
getShadowMapBorder(_shadowMapParams) {
|
|
62
|
+
return this._lightRadius > 0 ? Math.ceil(Math.max(this._lightRadius, this._maxFilterRadius) + 2) : 0;
|
|
63
|
+
}
|
|
64
|
+
getShadowMapClearColor(_shadowMapParams) {
|
|
65
|
+
return new Vector4(1, 1, 1, 1);
|
|
66
|
+
}
|
|
67
|
+
getShadowMap(shadowMapParams) {
|
|
68
|
+
return shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0];
|
|
69
|
+
}
|
|
70
|
+
doUpdateResources(shadowMapParams) {
|
|
71
|
+
shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
|
|
72
|
+
shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(false) ?? null;
|
|
73
|
+
}
|
|
74
|
+
postRenderShadowMap() {}
|
|
75
|
+
getDepthScale() {
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
setDepthScale(_val) {}
|
|
79
|
+
getShaderHash() {
|
|
80
|
+
return `${Number(this._temporalJitter)}`;
|
|
81
|
+
}
|
|
82
|
+
getShadowMapColorFormat(_shadowMapParams) {
|
|
83
|
+
const device = getDevice();
|
|
84
|
+
if (device.type === 'webgl') {
|
|
85
|
+
return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : device.getDeviceCaps().textureCaps.supportFloatColorBuffer ? 'rgba32f' : 'rgba8unorm';
|
|
86
|
+
}
|
|
87
|
+
return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'r16f' : device.getDeviceCaps().textureCaps.supportFloatColorBuffer ? 'r32f' : 'rgba8unorm';
|
|
88
|
+
}
|
|
89
|
+
getParams(out) {
|
|
90
|
+
out.setXYZW(this._lightRadius, this._blockerSampleCount, this._filterSampleCount, this._maxFilterRadius);
|
|
91
|
+
}
|
|
92
|
+
getShadowMapDepthFormat(_shadowMapParams) {
|
|
93
|
+
return getDevice().type === 'webgl' ? 'd24s8' : 'd32f';
|
|
94
|
+
}
|
|
95
|
+
computeShadowMapDepth(shadowMapParams, scope, worldPos) {
|
|
96
|
+
return computeShadowMapDepth(scope, worldPos, shadowMapParams.shadowMap.format);
|
|
97
|
+
}
|
|
98
|
+
computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
|
|
99
|
+
const funcNameComputeShadowCSM = 'lib_computeShadowCSM';
|
|
100
|
+
const pb = scope.$builder;
|
|
101
|
+
const that = this;
|
|
102
|
+
pb.func(funcNameComputeShadowCSM, [
|
|
103
|
+
pb.vec4('shadowVertex'),
|
|
104
|
+
pb.float('NdotL'),
|
|
105
|
+
pb.int('split')
|
|
106
|
+
], function() {
|
|
107
|
+
this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
|
|
108
|
+
this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
|
|
109
|
+
this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
|
|
110
|
+
this.$l.shadow = pb.float(1);
|
|
111
|
+
this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
|
|
112
|
+
this.$if(this.inShadow, function() {
|
|
113
|
+
this.$l.shadowBias = computeShadowBiasCSM(this, this.NdotL, this.split);
|
|
114
|
+
this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
|
|
115
|
+
this.shadow = filterShadowPCSS(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, this.shadowCoord, this.receiverPlaneDepthBias, this.split, that._temporalJitter, shadowMapParams.numShadowCascades);
|
|
116
|
+
});
|
|
117
|
+
this.$return(this.shadow);
|
|
118
|
+
});
|
|
119
|
+
return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split);
|
|
120
|
+
}
|
|
121
|
+
computeShadow(shadowMapParams, scope, shadowVertex, NdotL) {
|
|
122
|
+
const funcNameComputeShadow = 'lib_computeShadow';
|
|
123
|
+
const pb = scope.$builder;
|
|
124
|
+
const that = this;
|
|
125
|
+
pb.func(funcNameComputeShadow, [
|
|
126
|
+
pb.vec4('shadowVertex'),
|
|
127
|
+
pb.float('NdotL')
|
|
128
|
+
], function() {
|
|
129
|
+
if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
|
|
130
|
+
this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderHelper.getLightPositionAndRangeForShadow(this).xyz);
|
|
131
|
+
this.$l.distance = pb.div(pb.length(this.dir), ShaderHelper.getLightPositionAndRangeForShadow(this).w);
|
|
132
|
+
this.$l.shadowBias = computeShadowBias(shadowMapParams.lightType, this, this.distance, this.NdotL, true);
|
|
133
|
+
this.$return(that.samplePointShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias));
|
|
134
|
+
}
|
|
135
|
+
this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
|
|
136
|
+
this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
|
|
137
|
+
this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
|
|
138
|
+
this.$l.shadow = pb.float(1);
|
|
139
|
+
if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {
|
|
140
|
+
this.$l.nearFar = ShaderHelper.getShadowCameraParams(this).xy;
|
|
141
|
+
this.shadowCoord.z = ShaderHelper.nonLinearDepthToLinearNormalized(this, this.shadowCoord.z, this.nearFar);
|
|
142
|
+
}
|
|
143
|
+
this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
|
|
144
|
+
this.$if(this.inShadow, function() {
|
|
145
|
+
if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {
|
|
146
|
+
this.$l.shadowBias = computeShadowBias(shadowMapParams.lightType, this, this.shadowCoord.z, this.NdotL, true);
|
|
147
|
+
} else {
|
|
148
|
+
this.$l.shadowBias = computeShadowBias(shadowMapParams.lightType, this, this.shadowCoord.z, this.NdotL, false);
|
|
149
|
+
}
|
|
150
|
+
this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
|
|
151
|
+
this.shadow = filterShadowPCSS(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, this.shadowCoord, this.receiverPlaneDepthBias, undefined, that._temporalJitter);
|
|
152
|
+
});
|
|
153
|
+
this.$return(this.shadow);
|
|
154
|
+
});
|
|
155
|
+
return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL);
|
|
156
|
+
}
|
|
157
|
+
useNativeShadowMap(_shadowMapParams) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
/** @internal */ samplePointShadowMap(shadowMapParams, scope, coords, z, bias) {
|
|
161
|
+
const funcNameSampleShadowMap = 'lib_samplePointShadowMapPCSS';
|
|
162
|
+
const pb = scope.$builder;
|
|
163
|
+
pb.func(funcNameSampleShadowMap, [
|
|
164
|
+
pb.vec3('coords'),
|
|
165
|
+
pb.float('z'),
|
|
166
|
+
pb.float('bias')
|
|
167
|
+
], function() {
|
|
168
|
+
const floatDepthTexture = shadowMapParams.shadowMap.format !== 'rgba8unorm';
|
|
169
|
+
this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);
|
|
170
|
+
if (!floatDepthTexture) {
|
|
171
|
+
this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
|
|
172
|
+
}
|
|
173
|
+
this.$l.distance = pb.sub(this.z, this.bias);
|
|
174
|
+
this.$return(pb.step(this.distance, this.shadowTex.x));
|
|
175
|
+
});
|
|
176
|
+
return pb.getGlobalScope()[funcNameSampleShadowMap](coords, z, bias);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { PCSS };
|
|
181
|
+
//# sourceMappingURL=pcss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pcss.js","sources":["../../src/shadow/pcss.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport type { PBInsideFunctionScope, PBShaderExp, TextureFormat } from '@zephyr3d/device';\r\nimport { ShadowImpl } from './shadow_impl';\r\nimport type { ShadowMapParams, ShadowMapType } from './shadowmapper';\r\nimport { computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowPCSS } from '../shaders/shadow';\r\nimport { decodeNormalizedFloatFromRGBA } from '../shaders/misc';\r\nimport { LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values';\r\nimport { ShaderHelper } from '../material/shader/helper';\r\nimport { computeShadowBias, computeShadowBiasCSM } from './shader';\r\nimport { getDevice } from '../app/api';\r\n\r\n/** @internal */\r\nexport class PCSS extends ShadowImpl {\r\n protected _lightRadius: number;\r\n protected _blockerSampleCount: number;\r\n protected _filterSampleCount: number;\r\n protected _maxFilterRadius: number;\r\n protected _temporalJitter: boolean;\r\n constructor(\r\n lightRadius?: number,\r\n blockerSampleCount?: number,\r\n filterSampleCount?: number,\r\n maxFilterRadius?: number,\r\n temporalJitter?: boolean\r\n ) {\r\n super();\r\n this._lightRadius = lightRadius ?? 8;\r\n this._blockerSampleCount = blockerSampleCount ?? 24;\r\n this._filterSampleCount = filterSampleCount ?? 32;\r\n this._maxFilterRadius = maxFilterRadius ?? 32;\r\n this._temporalJitter = temporalJitter ?? true;\r\n }\r\n get lightRadius() {\r\n return this._lightRadius;\r\n }\r\n set lightRadius(val) {\r\n this._lightRadius = Math.max(0, Number(val) || 0);\r\n }\r\n get blockerSampleCount() {\r\n return this._blockerSampleCount;\r\n }\r\n set blockerSampleCount(val) {\r\n this._blockerSampleCount = Math.min(Math.max(1, Number(val) >> 0), 64);\r\n }\r\n get filterSampleCount() {\r\n return this._filterSampleCount;\r\n }\r\n set filterSampleCount(val) {\r\n this._filterSampleCount = Math.min(Math.max(1, Number(val) >> 0), 64);\r\n }\r\n get maxFilterRadius() {\r\n return this._maxFilterRadius;\r\n }\r\n set maxFilterRadius(val) {\r\n this._maxFilterRadius = Math.max(1, Number(val) || 1);\r\n }\r\n get temporalJitter() {\r\n return this._temporalJitter;\r\n }\r\n set temporalJitter(val) {\r\n this._temporalJitter = !!val;\r\n }\r\n getType() {\r\n return 'pcss' as const;\r\n }\r\n dispose() {}\r\n resourceDirty() {\r\n return false;\r\n }\r\n getShadowMapBorder(_shadowMapParams: ShadowMapParams) {\r\n return this._lightRadius > 0 ? Math.ceil(Math.max(this._lightRadius, this._maxFilterRadius) + 2) : 0;\r\n }\r\n getShadowMapClearColor(_shadowMapParams: ShadowMapParams) {\r\n return new Vector4(1, 1, 1, 1);\r\n }\r\n getShadowMap(shadowMapParams: ShadowMapParams) {\r\n return shadowMapParams.shadowMapFramebuffer!.getColorAttachments()[0] as ShadowMapType;\r\n }\r\n doUpdateResources(shadowMapParams: ShadowMapParams) {\r\n shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);\r\n shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(false) ?? null;\r\n }\r\n postRenderShadowMap() {}\r\n getDepthScale() {\r\n return 1;\r\n }\r\n setDepthScale(_val: number) {}\r\n getShaderHash() {\r\n return `${Number(this._temporalJitter)}`;\r\n }\r\n getShadowMapColorFormat(_shadowMapParams: ShadowMapParams): Nullable<TextureFormat> {\r\n const device = getDevice();\r\n if (device.type === 'webgl') {\r\n return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer\r\n ? 'rgba16f'\r\n : device.getDeviceCaps().textureCaps.supportFloatColorBuffer\r\n ? 'rgba32f'\r\n : 'rgba8unorm';\r\n }\r\n return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer\r\n ? 'r16f'\r\n : device.getDeviceCaps().textureCaps.supportFloatColorBuffer\r\n ? 'r32f'\r\n : 'rgba8unorm';\r\n }\r\n getParams(out: Vector4) {\r\n out.setXYZW(this._lightRadius, this._blockerSampleCount, this._filterSampleCount, this._maxFilterRadius);\r\n }\r\n getShadowMapDepthFormat(_shadowMapParams: ShadowMapParams): TextureFormat {\r\n return getDevice().type === 'webgl' ? 'd24s8' : 'd32f';\r\n }\r\n computeShadowMapDepth(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp\r\n ) {\r\n return computeShadowMapDepth(scope, worldPos, shadowMapParams.shadowMap!.format);\r\n }\r\n computeShadowCSM(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n split: PBShaderExp\r\n ) {\r\n const funcNameComputeShadowCSM = 'lib_computeShadowCSM';\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func(\r\n funcNameComputeShadowCSM,\r\n [pb.vec4('shadowVertex'), pb.float('NdotL'), pb.int('split')],\r\n function () {\r\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\r\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\r\n this.$l.inShadow = pb.all(\r\n pb.bvec2(\r\n pb.all(\r\n pb.bvec4(\r\n pb.greaterThanEqual(this.shadowCoord.x, 0),\r\n pb.lessThanEqual(this.shadowCoord.x, 1),\r\n pb.greaterThanEqual(this.shadowCoord.y, 0),\r\n pb.lessThanEqual(this.shadowCoord.y, 1)\r\n )\r\n ),\r\n pb.lessThanEqual(this.shadowCoord.z, 1)\r\n )\r\n );\r\n this.$l.shadow = pb.float(1);\r\n this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);\r\n this.$if(this.inShadow, function () {\r\n this.$l.shadowBias = computeShadowBiasCSM(this, this.NdotL, this.split);\r\n this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);\r\n this.shadow = filterShadowPCSS(\r\n this,\r\n shadowMapParams.lightType,\r\n shadowMapParams.shadowMap!.format,\r\n this.shadowCoord,\r\n this.receiverPlaneDepthBias,\r\n this.split,\r\n that._temporalJitter,\r\n shadowMapParams.numShadowCascades\r\n );\r\n });\r\n this.$return(this.shadow);\r\n }\r\n );\r\n return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split) as PBShaderExp;\r\n }\r\n computeShadow(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp\r\n ) {\r\n const funcNameComputeShadow = 'lib_computeShadow';\r\n const pb = scope.$builder;\r\n const that = this;\r\n pb.func(funcNameComputeShadow, [pb.vec4('shadowVertex'), pb.float('NdotL')], function () {\r\n if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {\r\n this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderHelper.getLightPositionAndRangeForShadow(this).xyz);\r\n this.$l.distance = pb.div(\r\n pb.length(this.dir),\r\n ShaderHelper.getLightPositionAndRangeForShadow(this).w\r\n );\r\n this.$l.shadowBias = computeShadowBias(\r\n shadowMapParams.lightType,\r\n this,\r\n this.distance,\r\n this.NdotL,\r\n true\r\n );\r\n this.$return(\r\n that.samplePointShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias)\r\n );\r\n }\r\n this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);\r\n this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);\r\n this.$l.inShadow = pb.all(\r\n pb.bvec2(\r\n pb.all(\r\n pb.bvec4(\r\n pb.greaterThanEqual(this.shadowCoord.x, 0),\r\n pb.lessThanEqual(this.shadowCoord.x, 1),\r\n pb.greaterThanEqual(this.shadowCoord.y, 0),\r\n pb.lessThanEqual(this.shadowCoord.y, 1)\r\n )\r\n ),\r\n pb.lessThanEqual(this.shadowCoord.z, 1)\r\n )\r\n );\r\n this.$l.shadow = pb.float(1);\r\n if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {\r\n this.$l.nearFar = ShaderHelper.getShadowCameraParams(this).xy;\r\n this.shadowCoord.z = ShaderHelper.nonLinearDepthToLinearNormalized(\r\n this,\r\n this.shadowCoord.z,\r\n this.nearFar\r\n );\r\n }\r\n this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);\r\n this.$if(this.inShadow, function () {\r\n if (shadowMapParams.lightType === LIGHT_TYPE_SPOT) {\r\n this.$l.shadowBias = computeShadowBias(\r\n shadowMapParams.lightType,\r\n this,\r\n this.shadowCoord.z,\r\n this.NdotL,\r\n true\r\n );\r\n } else {\r\n this.$l.shadowBias = computeShadowBias(\r\n shadowMapParams.lightType,\r\n this,\r\n this.shadowCoord.z,\r\n this.NdotL,\r\n false\r\n );\r\n }\r\n this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);\r\n this.shadow = filterShadowPCSS(\r\n this,\r\n shadowMapParams.lightType,\r\n shadowMapParams.shadowMap!.format,\r\n this.shadowCoord,\r\n this.receiverPlaneDepthBias,\r\n undefined,\r\n that._temporalJitter\r\n );\r\n });\r\n this.$return(this.shadow);\r\n });\r\n return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL) as PBShaderExp;\r\n }\r\n useNativeShadowMap(_shadowMapParams: ShadowMapParams) {\r\n return false;\r\n }\r\n /** @internal */\r\n samplePointShadowMap(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n coords: PBShaderExp,\r\n z: PBShaderExp,\r\n bias: PBShaderExp\r\n ) {\r\n const funcNameSampleShadowMap = 'lib_samplePointShadowMapPCSS';\r\n const pb = scope.$builder;\r\n pb.func(funcNameSampleShadowMap, [pb.vec3('coords'), pb.float('z'), pb.float('bias')], function () {\r\n const floatDepthTexture = shadowMapParams.shadowMap!.format !== 'rgba8unorm';\r\n this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);\r\n if (!floatDepthTexture) {\r\n this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);\r\n }\r\n this.$l.distance = pb.sub(this.z, this.bias);\r\n this.$return(pb.step(this.distance, this.shadowTex.x));\r\n });\r\n return pb.getGlobalScope()[funcNameSampleShadowMap](coords, z, bias) as PBShaderExp;\r\n }\r\n}\r\n"],"names":["PCSS","ShadowImpl","_lightRadius","_blockerSampleCount","_filterSampleCount","_maxFilterRadius","_temporalJitter","lightRadius","blockerSampleCount","filterSampleCount","maxFilterRadius","temporalJitter","val","Math","max","Number","min","getType","dispose","resourceDirty","getShadowMapBorder","_shadowMapParams","ceil","getShadowMapClearColor","Vector4","getShadowMap","shadowMapParams","shadowMapFramebuffer","getColorAttachments","doUpdateResources","shadowMap","shadowMapSampler","getDefaultSampler","postRenderShadowMap","getDepthScale","setDepthScale","_val","getShaderHash","getShadowMapColorFormat","device","getDevice","type","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","supportFloatColorBuffer","getParams","out","setXYZW","getShadowMapDepthFormat","computeShadowMapDepth","scope","worldPos","format","computeShadowCSM","shadowVertex","NdotL","split","funcNameComputeShadowCSM","pb","$builder","that","func","vec4","float","int","$l","shadowCoord","div","w","add","mul","inShadow","all","bvec2","bvec4","greaterThanEqual","x","lessThanEqual","y","z","shadow","receiverPlaneDepthBias","computeReceiverPlaneDepthBias","$if","shadowBias","computeShadowBiasCSM","sub","filterShadowPCSS","lightType","numShadowCascades","$return","getGlobalScope","computeShadow","funcNameComputeShadow","LIGHT_TYPE_POINT","dir","xyz","ShaderHelper","getLightPositionAndRangeForShadow","distance","length","computeShadowBias","samplePointShadowMap","LIGHT_TYPE_SPOT","nearFar","getShadowCameraParams","xy","nonLinearDepthToLinearNormalized","undefined","useNativeShadowMap","coords","bias","funcNameSampleShadowMap","vec3","floatDepthTexture","shadowTex","textureSampleLevel","decodeNormalizedFloatFromRGBA","step"],"mappings":";;;;;;;;;AAYA,iBACO,MAAMA,IAAaC,SAAAA,UAAAA,CAAAA;IACdC,YAAqB;IACrBC,mBAA4B;IAC5BC,kBAA2B;IAC3BC,gBAAyB;IACzBC,eAAyB;IACnC,WACEC,CAAAA,WAAoB,EACpBC,kBAA2B,EAC3BC,iBAA0B,EAC1BC,eAAwB,EACxBC,cAAwB,CACxB;QACA,KAAK,EAAA;QACL,IAAI,CAACT,YAAY,GAAGK,WAAe,IAAA,CAAA;QACnC,IAAI,CAACJ,mBAAmB,GAAGK,kBAAsB,IAAA,EAAA;QACjD,IAAI,CAACJ,kBAAkB,GAAGK,iBAAqB,IAAA,EAAA;QAC/C,IAAI,CAACJ,gBAAgB,GAAGK,eAAmB,IAAA,EAAA;QAC3C,IAAI,CAACJ,eAAe,GAAGK,cAAkB,IAAA,IAAA;AAC3C;AACA,IAAA,IAAIJ,WAAc,GAAA;QAChB,OAAO,IAAI,CAACL,YAAY;AAC1B;IACA,IAAIK,WAAAA,CAAYK,GAAG,EAAE;QACnB,IAAI,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AAC,GAAGyC,8BAA8B,IAAI,EAAE,IAAI,CAACF,SAAS,CAAA;AACvE;AACA,YAAA,IAAI,CAAClD,EAAE,CAACkC,QAAQ,GAAGzC,EAAG4B,CAAAA,GAAG,CAAC,IAAI,CAACP,CAAC,EAAE,IAAI,CAACgC,IAAI,CAAA;AAC3C,YAAA,IAAI,CAACrB,OAAO,CAAChC,EAAAA,CAAG4D,IAAI,CAAC,IAAI,CAACnB,QAAQ,EAAE,IAAI,CAACgB,SAAS,CAACvC,CAAC,CAAA,CAAA;AACtD,SAAA,CAAA;AACA,QAAA,OAAOlB,GAAGiC,cAAc,EAAE,CAACqB,uBAAwB,CAAA,CAACF,QAAQ/B,CAAGgC,EAAAA,IAAAA,CAAAA;AACjE;AACF;;;;"}
|
package/dist/shadow/shader.js
CHANGED
|
@@ -4,6 +4,7 @@ import '../material/blinn.js';
|
|
|
4
4
|
import '../material/unlit.js';
|
|
5
5
|
import '../material/particle.js';
|
|
6
6
|
import '../material/subsurfaceprofile.js';
|
|
7
|
+
import '../material/skin.js';
|
|
7
8
|
import '@zephyr3d/device';
|
|
8
9
|
import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_SPOT, LIGHT_TYPE_POINT } from '../values.js';
|
|
9
10
|
import '@zephyr3d/base';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.js","sources":["../../src/shadow/shader.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from '../material';\r\nimport { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values';\r\n\r\nfunction getShadowReceiverBiasFactors(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff) {\r\n // Thin masked geometry such as layered hair cards needs a tighter receiver bias,\r\n // otherwise nearby layers lose self-shadow before the shadow map is even sampled.\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n return pb.vec2(pb.mix(0.22, 0.4, cutoff), pb.mix(0.05, 0.16, cutoff)) as PBShaderExp;\r\n }\r\n return pb.vec2(1, 1) as PBShaderExp;\r\n}\r\n\r\nfunction isMaskedPerspectiveShadowLight(scope: PBInsideFunctionScope, lightType: number) {\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n return !!alphaCutoff && (lightType === LIGHT_TYPE_SPOT || lightType === LIGHT_TYPE_POINT);\r\n}\r\n\r\nfunction getShadowReceiverNoL(scope: PBInsideFunctionScope, NdotL: PBShaderExp, lightType?: number) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff) {\r\n // Layered masked cards should not explode slope bias at grazing angles.\r\n // This is especially visible for back / rim spot lights on hair cards.\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n if (lightType != null && isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n return pb.max(NdotL, pb.mix(0.85, 0.95, cutoff)) as PBShaderExp;\r\n }\r\n return pb.max(NdotL, pb.mix(0.45, 0.65, cutoff)) as PBShaderExp;\r\n }\r\n return NdotL as PBShaderExp;\r\n}\r\n\r\nfunction getShadowReceiverPerspectiveBiasScale(\r\n scope: PBInsideFunctionScope,\r\n lightType: number,\r\n linearDepth: PBShaderExp,\r\n farNearRatio: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff && isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n // Perspective shadow cameras (spot / point) can over-amplify receiver bias at depth.\r\n // Keep masked layered geometry in a much tighter range so hair cards can still self-occlude.\r\n const cappedFarNearRatio = pb.min(farNearRatio, pb.mix(1.15, 1.6, cutoff));\r\n return pb.mix(1, cappedFarNearRatio, linearDepth) as PBShaderExp;\r\n }\r\n return pb.mix(1, farNearRatio, linearDepth) as PBShaderExp;\r\n}\r\n\r\nexport function computeShadowBiasCSM(scope: PBInsideFunctionScope, NdotL: PBShaderExp, split: PBShaderExp) {\r\n const pb = scope.$builder;\r\n const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);\r\n const splitFlags = pb.vec4(\r\n pb.float(pb.equal(split, 0)),\r\n pb.float(pb.equal(split, 1)),\r\n pb.float(pb.equal(split, 2)),\r\n pb.float(pb.equal(split, 3))\r\n );\r\n const depthBiasScale = pb.dot(ShaderHelper.getDepthBiasScales(scope), splitFlags);\r\n const receiverBiasFactors = getShadowReceiverBiasFactors(scope);\r\n const receiverNoL = getShadowReceiverNoL(scope, NdotL);\r\n return pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL)), depthBiasScale),\r\n pb.vec2(1, 1)\r\n );\r\n}\r\n\r\nexport function computeShadowBias(\r\n lightType: number,\r\n scope: PBInsideFunctionScope,\r\n z: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n linear: boolean\r\n) {\r\n const pb = scope.$builder;\r\n const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);\r\n const receiverBiasFactors = getShadowReceiverBiasFactors(scope);\r\n const receiverNoL = getShadowReceiverNoL(scope, NdotL, lightType);\r\n if (lightType === LIGHT_TYPE_DIRECTIONAL) {\r\n return pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL))),\r\n pb.vec2(1, 1)\r\n );\r\n } else {\r\n const nearFar = ShaderHelper.getShadowCameraParams(scope).xy;\r\n const linearDepth = linear ? z : ShaderHelper.nonLinearDepthToLinearNormalized(scope, z, nearFar);\r\n const biasScaleFactor = getShadowReceiverPerspectiveBiasScale(\r\n scope,\r\n lightType,\r\n linearDepth,\r\n depthBiasParam.w\r\n );\r\n let bias = pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL)), biasScaleFactor),\r\n pb.vec2(1, 1)\r\n );\r\n if (isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff!;\r\n bias = pb.mul(bias, pb.mix(0.12, 0.22, pb.clamp(alphaCutoff, 0, 1))) as PBShaderExp;\r\n }\r\n return bias;\r\n }\r\n}\r\n"],"names":["getShadowReceiverBiasFactors","scope","pb","$builder","alphaCutoff","zAlphaCutoff","cutoff","clamp","vec2","mix","isMaskedPerspectiveShadowLight","lightType","LIGHT_TYPE_SPOT","LIGHT_TYPE_POINT","getShadowReceiverNoL","NdotL","max","getShadowReceiverPerspectiveBiasScale","linearDepth","farNearRatio","cappedFarNearRatio","min","computeShadowBiasCSM","split","depthBiasParam","ShaderHelper","getDepthBiasValues","splitFlags","vec4","float","equal","depthBiasScale","dot","getDepthBiasScales","receiverBiasFactors","receiverNoL","mul","xy","sub","computeShadowBias","z","linear","LIGHT_TYPE_DIRECTIONAL","nearFar","getShadowCameraParams","nonLinearDepthToLinearNormalized","biasScaleFactor","w","bias"],"mappings":"
|
|
1
|
+
{"version":3,"file":"shader.js","sources":["../../src/shadow/shader.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from '../material';\r\nimport { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values';\r\n\r\nfunction getShadowReceiverBiasFactors(scope: PBInsideFunctionScope) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff) {\r\n // Thin masked geometry such as layered hair cards needs a tighter receiver bias,\r\n // otherwise nearby layers lose self-shadow before the shadow map is even sampled.\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n return pb.vec2(pb.mix(0.22, 0.4, cutoff), pb.mix(0.05, 0.16, cutoff)) as PBShaderExp;\r\n }\r\n return pb.vec2(1, 1) as PBShaderExp;\r\n}\r\n\r\nfunction isMaskedPerspectiveShadowLight(scope: PBInsideFunctionScope, lightType: number) {\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n return !!alphaCutoff && (lightType === LIGHT_TYPE_SPOT || lightType === LIGHT_TYPE_POINT);\r\n}\r\n\r\nfunction getShadowReceiverNoL(scope: PBInsideFunctionScope, NdotL: PBShaderExp, lightType?: number) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff) {\r\n // Layered masked cards should not explode slope bias at grazing angles.\r\n // This is especially visible for back / rim spot lights on hair cards.\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n if (lightType != null && isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n return pb.max(NdotL, pb.mix(0.85, 0.95, cutoff)) as PBShaderExp;\r\n }\r\n return pb.max(NdotL, pb.mix(0.45, 0.65, cutoff)) as PBShaderExp;\r\n }\r\n return NdotL as PBShaderExp;\r\n}\r\n\r\nfunction getShadowReceiverPerspectiveBiasScale(\r\n scope: PBInsideFunctionScope,\r\n lightType: number,\r\n linearDepth: PBShaderExp,\r\n farNearRatio: PBShaderExp\r\n) {\r\n const pb = scope.$builder;\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff;\r\n if (alphaCutoff && isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n const cutoff = pb.clamp(alphaCutoff, 0, 1);\r\n // Perspective shadow cameras (spot / point) can over-amplify receiver bias at depth.\r\n // Keep masked layered geometry in a much tighter range so hair cards can still self-occlude.\r\n const cappedFarNearRatio = pb.min(farNearRatio, pb.mix(1.15, 1.6, cutoff));\r\n return pb.mix(1, cappedFarNearRatio, linearDepth) as PBShaderExp;\r\n }\r\n return pb.mix(1, farNearRatio, linearDepth) as PBShaderExp;\r\n}\r\n\r\nexport function computeShadowBiasCSM(scope: PBInsideFunctionScope, NdotL: PBShaderExp, split: PBShaderExp) {\r\n const pb = scope.$builder;\r\n const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);\r\n const splitFlags = pb.vec4(\r\n pb.float(pb.equal(split, 0)),\r\n pb.float(pb.equal(split, 1)),\r\n pb.float(pb.equal(split, 2)),\r\n pb.float(pb.equal(split, 3))\r\n );\r\n const depthBiasScale = pb.dot(ShaderHelper.getDepthBiasScales(scope), splitFlags);\r\n const receiverBiasFactors = getShadowReceiverBiasFactors(scope);\r\n const receiverNoL = getShadowReceiverNoL(scope, NdotL);\r\n return pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL)), depthBiasScale),\r\n pb.vec2(1, 1)\r\n );\r\n}\r\n\r\nexport function computeShadowBias(\r\n lightType: number,\r\n scope: PBInsideFunctionScope,\r\n z: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n linear: boolean\r\n) {\r\n const pb = scope.$builder;\r\n const depthBiasParam = ShaderHelper.getDepthBiasValues(scope);\r\n const receiverBiasFactors = getShadowReceiverBiasFactors(scope);\r\n const receiverNoL = getShadowReceiverNoL(scope, NdotL, lightType);\r\n if (lightType === LIGHT_TYPE_DIRECTIONAL) {\r\n return pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL))),\r\n pb.vec2(1, 1)\r\n );\r\n } else {\r\n const nearFar = ShaderHelper.getShadowCameraParams(scope).xy;\r\n const linearDepth = linear ? z : ShaderHelper.nonLinearDepthToLinearNormalized(scope, z, nearFar);\r\n const biasScaleFactor = getShadowReceiverPerspectiveBiasScale(\r\n scope,\r\n lightType,\r\n linearDepth,\r\n depthBiasParam.w\r\n );\r\n let bias = pb.dot(\r\n pb.mul(depthBiasParam.xy, receiverBiasFactors, pb.vec2(1, pb.sub(1, receiverNoL)), biasScaleFactor),\r\n pb.vec2(1, 1)\r\n );\r\n if (isMaskedPerspectiveShadowLight(scope, lightType)) {\r\n const alphaCutoff = (scope as PBInsideFunctionScope & { zAlphaCutoff?: PBShaderExp }).zAlphaCutoff!;\r\n bias = pb.mul(bias, pb.mix(0.12, 0.22, pb.clamp(alphaCutoff, 0, 1))) as PBShaderExp;\r\n }\r\n return bias;\r\n }\r\n}\r\n"],"names":["getShadowReceiverBiasFactors","scope","pb","$builder","alphaCutoff","zAlphaCutoff","cutoff","clamp","vec2","mix","isMaskedPerspectiveShadowLight","lightType","LIGHT_TYPE_SPOT","LIGHT_TYPE_POINT","getShadowReceiverNoL","NdotL","max","getShadowReceiverPerspectiveBiasScale","linearDepth","farNearRatio","cappedFarNearRatio","min","computeShadowBiasCSM","split","depthBiasParam","ShaderHelper","getDepthBiasValues","splitFlags","vec4","float","equal","depthBiasScale","dot","getDepthBiasScales","receiverBiasFactors","receiverNoL","mul","xy","sub","computeShadowBias","z","linear","LIGHT_TYPE_DIRECTIONAL","nearFar","getShadowCameraParams","nonLinearDepthToLinearNormalized","biasScaleFactor","w","bias"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,6BAA6BC,KAA4B,EAAA;IAChE,MAAMC,EAAAA,GAAKD,MAAME,QAAQ;IACzB,MAAMC,WAAAA,GAAc,KAACH,CAAiEI,YAAY;AAClG,IAAA,IAAID,WAAa,EAAA;;;AAGf,QAAA,MAAME,MAASJ,GAAAA,EAAAA,CAAGK,KAAK,CAACH,aAAa,CAAG,EAAA,CAAA,CAAA;AACxC,QAAA,OAAOF,EAAGM,CAAAA,IAAI,CAACN,EAAAA,CAAGO,GAAG,CAAC,IAAM,EAAA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AAAA,GAAIf,aAAaoB,gCAAgC,CAAC5C,OAAOuC,CAAGG,EAAAA,OAAAA,CAAAA;AACzF,QAAA,MAAMG,kBAAkB7B,qCACtBhB,CAAAA,KAAAA,EACAU,SACAO,EAAAA,WAAAA,EACAM,eAAeuB,CAAC,CAAA;QAElB,IAAIC,IAAAA,GAAO9C,EAAG8B,CAAAA,GAAG,CACf9B,EAAAA,CAAGkC,GAAG,CAACZ,cAAAA,CAAea,EAAE,EAAEH,mBAAqBhC,EAAAA,EAAAA,CAAGM,IAAI,CAAC,CAAA,EAAGN,EAAGoC,CAAAA,GAAG,CAAC,CAAA,EAAGH,eAAeW,eACnF5C,CAAAA,EAAAA,EAAAA,CAAGM,IAAI,CAAC,CAAG,EAAA,CAAA,CAAA,CAAA;QAEb,IAAIE,8BAAAA,CAA+BT,OAAOU,SAAY,CAAA,EAAA;YACpD,MAAMP,WAAAA,GAAc,KAACH,CAAiEI,YAAY;AAClG2C,YAAAA,IAAAA,GAAO9C,EAAGkC,CAAAA,GAAG,CAACY,IAAAA,EAAM9C,EAAGO,CAAAA,GAAG,CAAC,IAAA,EAAM,IAAMP,EAAAA,EAAAA,CAAGK,KAAK,CAACH,aAAa,CAAG,EAAA,CAAA,CAAA,CAAA,CAAA;AAClE;QACA,OAAO4C,IAAAA;AACT;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadow_impl.js","sources":["../../src/shadow/shadow_impl.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp, TextureFormat } from '@zephyr3d/device';\r\nimport type { ShadowMapParams, ShadowMapType, ShadowMode } from './shadowmapper';\r\nimport { Vector4, type Nullable } from '@zephyr3d/base';\r\n\r\n/** @internal */\r\nexport abstract class ShadowImpl {\r\n protected _resourceDirty: boolean;\r\n constructor() {\r\n this._resourceDirty = true;\r\n }\r\n invalidateResource() {\r\n this._resourceDirty = true;\r\n }\r\n updateResources(shadowMapParams: ShadowMapParams) {\r\n this.doUpdateResources(shadowMapParams);\r\n }\r\n abstract getType(): ShadowMode;\r\n abstract getShadowMapBorder(shadowMapParams: ShadowMapParams): number;\r\n getShadowMapClearColor(shadowMapParams: ShadowMapParams) {\r\n const colorAttachment = shadowMapParams.shadowMapFramebuffer?.getColorAttachments()[0];\r\n return colorAttachment\r\n ? colorAttachment.isFloatFormat()\r\n ? new Vector4(1, 1, 1, 1)\r\n : new Vector4(0, 0, 0, 1)\r\n : null;\r\n }\r\n abstract getShadowMap(shadowMapParams: ShadowMapParams): ShadowMapType;\r\n abstract postRenderShadowMap(shadowMapParams: ShadowMapParams): void;\r\n abstract getDepthScale(): number;\r\n abstract setDepthScale(val: number): void;\r\n abstract resourceDirty(): boolean;\r\n abstract doUpdateResources(shadowMapParams: ShadowMapParams): void;\r\n abstract getShaderHash(): string;\r\n abstract computeShadowMapDepth(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp\r\n ): PBShaderExp;\r\n abstract computeShadow(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp\r\n ): PBShaderExp;\r\n abstract computeShadowCSM(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n split: PBShaderExp\r\n ): PBShaderExp;\r\n abstract getShadowMapColorFormat(shadowMapParams: ShadowMapParams): Nullable<TextureFormat>;\r\n abstract getShadowMapDepthFormat(shadowMapParams: ShadowMapParams): TextureFormat;\r\n abstract useNativeShadowMap(shadowMapParams: ShadowMapParams): boolean;\r\n}\r\n"],"names":["ShadowImpl","_resourceDirty","invalidateResource","updateResources","shadowMapParams","doUpdateResources","getShadowMapClearColor","colorAttachment","shadowMapFramebuffer","getColorAttachments","isFloatFormat","Vector4"],"mappings":";;AAIA,iBACO,MAAeA,UAAAA,CAAAA;IACVC,cAAwB;IAClC,WAAc,EAAA;QACZ,IAAI,CAACA,cAAc,GAAG,IAAA;AACxB;IACAC,kBAAqB,GAAA;QACnB,IAAI,CAACD,cAAc,GAAG,IAAA;AACxB;AACAE,IAAAA,eAAAA,CAAgBC,eAAgC,EAAE;QAChD,IAAI,CAACC,iBAAiB,CAACD,eAAAA,CAAAA;AACzB;AAGAE,IAAAA,sBAAAA,CAAuBF,eAAgC,EAAE;AACvD,QAAA,MAAMG,kBAAkBH,eAAgBI,CAAAA,oBAAoB,EAAEC,mBAAAA,EAAqB,CAAC,CAAE,CAAA;AACtF,QAAA,OAAOF,eACHA,GAAAA,eAAAA,CAAgBG,aAAa,EAAA,GAC3B,IAAIC,OAAQ,CAAA,CAAA,EAAG,CAAG,EAAA,CAAA,EAAG,KACrB,IAAIA,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,GAAG,CACvB,CAAA,GAAA,IAAA;AACN;
|
|
1
|
+
{"version":3,"file":"shadow_impl.js","sources":["../../src/shadow/shadow_impl.ts"],"sourcesContent":["import type { PBInsideFunctionScope, PBShaderExp, TextureFormat } from '@zephyr3d/device';\r\nimport type { ShadowMapParams, ShadowMapType, ShadowMode } from './shadowmapper';\r\nimport { Vector4, type Nullable } from '@zephyr3d/base';\r\n\r\n/** @internal */\r\nexport abstract class ShadowImpl {\r\n protected _resourceDirty: boolean;\r\n constructor() {\r\n this._resourceDirty = true;\r\n }\r\n invalidateResource() {\r\n this._resourceDirty = true;\r\n }\r\n updateResources(shadowMapParams: ShadowMapParams) {\r\n this.doUpdateResources(shadowMapParams);\r\n }\r\n abstract getType(): ShadowMode;\r\n abstract getShadowMapBorder(shadowMapParams: ShadowMapParams): number;\r\n getShadowMapClearColor(shadowMapParams: ShadowMapParams) {\r\n const colorAttachment = shadowMapParams.shadowMapFramebuffer?.getColorAttachments()[0];\r\n return colorAttachment\r\n ? colorAttachment.isFloatFormat()\r\n ? new Vector4(1, 1, 1, 1)\r\n : new Vector4(0, 0, 0, 1)\r\n : null;\r\n }\r\n abstract getParams(out: Vector4): void;\r\n abstract getShadowMap(shadowMapParams: ShadowMapParams): ShadowMapType;\r\n abstract postRenderShadowMap(shadowMapParams: ShadowMapParams): void;\r\n abstract getDepthScale(): number;\r\n abstract setDepthScale(val: number): void;\r\n abstract resourceDirty(): boolean;\r\n abstract doUpdateResources(shadowMapParams: ShadowMapParams): void;\r\n abstract getShaderHash(): string;\r\n abstract computeShadowMapDepth(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp\r\n ): PBShaderExp;\r\n abstract computeShadow(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp\r\n ): PBShaderExp;\r\n abstract computeShadowCSM(\r\n shadowMapParams: ShadowMapParams,\r\n scope: PBInsideFunctionScope,\r\n shadowVertex: PBShaderExp,\r\n NdotL: PBShaderExp,\r\n split: PBShaderExp\r\n ): PBShaderExp;\r\n abstract getShadowMapColorFormat(shadowMapParams: ShadowMapParams): Nullable<TextureFormat>;\r\n abstract getShadowMapDepthFormat(shadowMapParams: ShadowMapParams): TextureFormat;\r\n abstract useNativeShadowMap(shadowMapParams: ShadowMapParams): boolean;\r\n}\r\n"],"names":["ShadowImpl","_resourceDirty","invalidateResource","updateResources","shadowMapParams","doUpdateResources","getShadowMapClearColor","colorAttachment","shadowMapFramebuffer","getColorAttachments","isFloatFormat","Vector4"],"mappings":";;AAIA,iBACO,MAAeA,UAAAA,CAAAA;IACVC,cAAwB;IAClC,WAAc,EAAA;QACZ,IAAI,CAACA,cAAc,GAAG,IAAA;AACxB;IACAC,kBAAqB,GAAA;QACnB,IAAI,CAACD,cAAc,GAAG,IAAA;AACxB;AACAE,IAAAA,eAAAA,CAAgBC,eAAgC,EAAE;QAChD,IAAI,CAACC,iBAAiB,CAACD,eAAAA,CAAAA;AACzB;AAGAE,IAAAA,sBAAAA,CAAuBF,eAAgC,EAAE;AACvD,QAAA,MAAMG,kBAAkBH,eAAgBI,CAAAA,oBAAoB,EAAEC,mBAAAA,EAAqB,CAAC,CAAE,CAAA;AACtF,QAAA,OAAOF,eACHA,GAAAA,eAAAA,CAAgBG,aAAa,EAAA,GAC3B,IAAIC,OAAQ,CAAA,CAAA,EAAG,CAAG,EAAA,CAAA,EAAG,KACrB,IAAIA,OAAAA,CAAQ,CAAG,EAAA,CAAA,EAAG,GAAG,CACvB,CAAA,GAAA,IAAA;AACN;AA8BF;;;;"}
|
|
@@ -3,8 +3,8 @@ import { Camera } from '../camera/camera.js';
|
|
|
3
3
|
import { SSM } from './ssm.js';
|
|
4
4
|
import { ESM } from './esm.js';
|
|
5
5
|
import { VSM } from './vsm.js';
|
|
6
|
-
import { PCFPD } from './pcf_pd.js';
|
|
7
6
|
import { PCFOPT } from './pcf_opt.js';
|
|
7
|
+
import { PCSS } from './pcss.js';
|
|
8
8
|
import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT } from '../values.js';
|
|
9
9
|
import { ShaderHelper } from '../material/shader/helper.js';
|
|
10
10
|
import { getDevice } from '../app/api.js';
|
|
@@ -34,6 +34,11 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
34
34
|
/** @internal */ _pdSampleCount;
|
|
35
35
|
/** @internal */ _pdSampleRadius;
|
|
36
36
|
/** @internal */ _pcfKernelSize;
|
|
37
|
+
/** @internal */ _pcssLightRadius;
|
|
38
|
+
/** @internal */ _pcssBlockerSampleCount;
|
|
39
|
+
/** @internal */ _pcssFilterSampleCount;
|
|
40
|
+
/** @internal */ _pcssMaxFilterRadius;
|
|
41
|
+
/** @internal */ _pcssTemporalJitter;
|
|
37
42
|
/** @internal */ _vsmBlurKernelSize;
|
|
38
43
|
/** @internal */ _vsmBlurRadius;
|
|
39
44
|
/** @internal */ _vsmDarkness;
|
|
@@ -59,12 +64,17 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
59
64
|
nearClip: 1
|
|
60
65
|
};
|
|
61
66
|
this._resourceDirty = true;
|
|
62
|
-
this._shadowMode = 'pcf
|
|
67
|
+
this._shadowMode = 'pcf';
|
|
63
68
|
this._shadowDistance = 2000;
|
|
64
69
|
this._impl = null;
|
|
65
70
|
this._pdSampleCount = 24;
|
|
66
71
|
this._pdSampleRadius = 3;
|
|
67
72
|
this._pcfKernelSize = 7;
|
|
73
|
+
this._pcssLightRadius = 8;
|
|
74
|
+
this._pcssBlockerSampleCount = 24;
|
|
75
|
+
this._pcssFilterSampleCount = 32;
|
|
76
|
+
this._pcssMaxFilterRadius = 32;
|
|
77
|
+
this._pcssTemporalJitter = true;
|
|
68
78
|
this._vsmBlurKernelSize = 5;
|
|
69
79
|
this._vsmBlurRadius = 4;
|
|
70
80
|
this._vsmDarkness = 0.3;
|
|
@@ -201,7 +211,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
201
211
|
* `outdoor-large`: longer distance coverage for open scenes.
|
|
202
212
|
*/ applyQualityPreset(preset) {
|
|
203
213
|
if (preset === 'character-small') {
|
|
204
|
-
this.mode = 'pcf
|
|
214
|
+
this.mode = 'pcf';
|
|
205
215
|
this.shadowMapSize = 2048;
|
|
206
216
|
this.shadowDistance = 120;
|
|
207
217
|
this.splitLambda = 0.75;
|
|
@@ -212,7 +222,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
212
222
|
this.numShadowCascades = this._light.isDirectionLight() ? 3 : 1;
|
|
213
223
|
return;
|
|
214
224
|
}
|
|
215
|
-
this.mode = 'pcf
|
|
225
|
+
this.mode = 'pcf';
|
|
216
226
|
this.shadowMapSize = 2048;
|
|
217
227
|
this.shadowDistance = 800;
|
|
218
228
|
this.splitLambda = 0.6;
|
|
@@ -261,6 +271,71 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
261
271
|
}
|
|
262
272
|
}
|
|
263
273
|
}
|
|
274
|
+
/** Light radius for PCSS shadow, measured in shadow-map texels */ get pcssLightRadius() {
|
|
275
|
+
return this._pcssLightRadius;
|
|
276
|
+
}
|
|
277
|
+
set pcssLightRadius(val) {
|
|
278
|
+
val = Math.max(0, Number(val) || 0);
|
|
279
|
+
if (val !== this._pcssLightRadius) {
|
|
280
|
+
this._pcssLightRadius = val;
|
|
281
|
+
const pcss = this.asPCSS();
|
|
282
|
+
if (pcss) {
|
|
283
|
+
pcss.lightRadius = this._pcssLightRadius;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** Blocker search sample count for PCSS shadow */ get pcssBlockerSampleCount() {
|
|
288
|
+
return this._pcssBlockerSampleCount;
|
|
289
|
+
}
|
|
290
|
+
set pcssBlockerSampleCount(val) {
|
|
291
|
+
val = Math.min(Math.max(1, Number(val) >> 0), 64);
|
|
292
|
+
if (val !== this._pcssBlockerSampleCount) {
|
|
293
|
+
this._pcssBlockerSampleCount = val;
|
|
294
|
+
const pcss = this.asPCSS();
|
|
295
|
+
if (pcss) {
|
|
296
|
+
pcss.blockerSampleCount = this._pcssBlockerSampleCount;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** Filter sample count for PCSS shadow */ get pcssFilterSampleCount() {
|
|
301
|
+
return this._pcssFilterSampleCount;
|
|
302
|
+
}
|
|
303
|
+
set pcssFilterSampleCount(val) {
|
|
304
|
+
val = Math.min(Math.max(1, Number(val) >> 0), 64);
|
|
305
|
+
if (val !== this._pcssFilterSampleCount) {
|
|
306
|
+
this._pcssFilterSampleCount = val;
|
|
307
|
+
const pcss = this.asPCSS();
|
|
308
|
+
if (pcss) {
|
|
309
|
+
pcss.filterSampleCount = this._pcssFilterSampleCount;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/** Maximum PCSS filter radius, measured in shadow-map texels */ get pcssMaxFilterRadius() {
|
|
314
|
+
return this._pcssMaxFilterRadius;
|
|
315
|
+
}
|
|
316
|
+
set pcssMaxFilterRadius(val) {
|
|
317
|
+
val = Math.max(1, Number(val) || 1);
|
|
318
|
+
if (val !== this._pcssMaxFilterRadius) {
|
|
319
|
+
this._pcssMaxFilterRadius = val;
|
|
320
|
+
const pcss = this.asPCSS();
|
|
321
|
+
if (pcss) {
|
|
322
|
+
pcss.maxFilterRadius = this._pcssMaxFilterRadius;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/** If true, rotates PCSS sampling pattern over frames for TAA accumulation */ get pcssTemporalJitter() {
|
|
327
|
+
return this._pcssTemporalJitter;
|
|
328
|
+
}
|
|
329
|
+
set pcssTemporalJitter(val) {
|
|
330
|
+
val = !!val;
|
|
331
|
+
if (val !== this._pcssTemporalJitter) {
|
|
332
|
+
this._pcssTemporalJitter = val;
|
|
333
|
+
const pcss = this.asPCSS();
|
|
334
|
+
if (pcss) {
|
|
335
|
+
pcss.temporalJitter = this._pcssTemporalJitter;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
264
339
|
/** Kernel size of VSM */ get vsmBlurKernelSize() {
|
|
265
340
|
return this._vsmBlurKernelSize;
|
|
266
341
|
}
|
|
@@ -816,7 +891,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
816
891
|
this.postRenderShadowMap(shadowMapParams);
|
|
817
892
|
}
|
|
818
893
|
/** @internal */ applyMode(mode) {
|
|
819
|
-
if (mode !== 'hard' && mode !== 'vsm' && mode !== 'esm' && mode !== 'pcf-pd' && mode !== 'pcf-opt') {
|
|
894
|
+
if (mode !== 'hard' && mode !== 'vsm' && mode !== 'esm' && mode !== 'pcf' && mode !== 'pcf-pd' && mode !== 'pcf-opt' && mode !== 'pcss') {
|
|
820
895
|
console.error(`ShadowMapper.setShadowMode() failed: invalid mode: ${mode}`);
|
|
821
896
|
return;
|
|
822
897
|
}
|
|
@@ -830,10 +905,10 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
830
905
|
const esm = this._impl;
|
|
831
906
|
esm.blur = this._esmBlur;
|
|
832
907
|
esm.logSpace = this._esmLogSpace;
|
|
833
|
-
} else if (mode === 'pcf-pd') {
|
|
834
|
-
this._impl = new PCFPD(this._pdSampleCount, this._pdSampleRadius);
|
|
835
|
-
} else if (mode === 'pcf-opt') {
|
|
908
|
+
} else if (mode === 'pcf' || mode === 'pcf-opt' || mode === 'pcf-pd') {
|
|
836
909
|
this._impl = new PCFOPT(this._pcfKernelSize);
|
|
910
|
+
} else if (mode === 'pcss') {
|
|
911
|
+
this._impl = new PCSS(this._pcssLightRadius, this._pcssBlockerSampleCount, this._pcssFilterSampleCount, this._pcssMaxFilterRadius, this._pcssTemporalJitter);
|
|
837
912
|
}
|
|
838
913
|
}
|
|
839
914
|
/** @internal */ asVSM() {
|
|
@@ -848,6 +923,9 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
|
|
|
848
923
|
/** @internal */ asPCFOPT() {
|
|
849
924
|
return this._impl?.getType() === 'pcf-opt' ? this._impl : null;
|
|
850
925
|
}
|
|
926
|
+
/** @internal */ asPCSS() {
|
|
927
|
+
return this._impl?.getType() === 'pcss' ? this._impl : null;
|
|
928
|
+
}
|
|
851
929
|
}
|
|
852
930
|
|
|
853
931
|
export { ShadowMapper };
|