@woosh/meep-engine 3.77.0 → 3.78.0
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/package.json +3 -2
- package/src/engine/EngineHarness.d.ts +4 -6
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +11 -19
- package/src/engine/sound/sopra/runtime/EventInstance.d.ts +0 -1
- package/src/engine/sound/sopra/runtime/EventInstance.d.ts.map +1 -1
- package/src/engine/sound/sopra/runtime/EventInstance.js +0 -1
- package/src/shade/renderer/extension/ShadowAtlas.d.ts +4 -2
- package/src/shade/renderer/extension/ShadowAtlas.d.ts.map +1 -1
- package/src/shade/renderer/extension/ShadowAtlas.js +4 -2
- package/src/shade/renderer/hair/hair_shadow_draw.d.ts +2 -2
- package/src/shade/renderer/hair/hair_shadow_draw.js +2 -2
- package/src/shade/renderer/rasterize/draw/chunk_meshlet_draw_vertex.d.ts +7 -4
- package/src/shade/renderer/rasterize/draw/chunk_meshlet_draw_vertex.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/draw/chunk_meshlet_draw_vertex.js +66 -14
- package/src/shade/renderer/rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.d.ts +20 -0
- package/src/shade/renderer/rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.d.ts.map +1 -0
- package/src/shade/renderer/rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.js +149 -0
- package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.d.ts +8 -0
- package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.js +100 -33
- package/src/shade/renderer/rasterize/native/rasterization_shader_resources.d.ts +11 -0
- package/src/shade/renderer/rasterize/native/rasterization_shader_resources.d.ts.map +1 -1
- package/src/shade/renderer/rasterize/native/rasterization_shader_resources.js +24 -11
- package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.d.ts +13 -0
- package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.d.ts.map +1 -0
- package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.js +42 -0
- package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.d.ts.map +1 -1
- package/src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js +14 -5
- package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.d.ts +34 -0
- package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.d.ts.map +1 -0
- package/src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.js +106 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_cascade_caster_position.d.ts +16 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_cascade_caster_position.d.ts.map +1 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_cascade_caster_position.js +50 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.d.ts +25 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.d.ts.map +1 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.js +42 -0
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_directional_cascades.d.ts +1 -1
- package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_directional_cascades.js +5 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RenderPipelineDescriptor } from "../../../../descriptor/pipeline/render/RenderPipelineDescriptor.js";
|
|
2
|
+
/** @typedef {import("../../../../descriptor/pipeline/render/DepthStencilState.js").DepthStencilState} DepthStencilState */
|
|
2
3
|
import { DEPTH_BACKGROUND_VALUE } from "../../../depth/DEPTH_BACKGROUND_VALUE.js";
|
|
3
4
|
import {
|
|
4
5
|
chunk_material_opacity_contract,
|
|
@@ -22,6 +23,14 @@ import {
|
|
|
22
23
|
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
23
24
|
import { ShaderDescriptor } from "../../../shader/ShaderDescriptor.js";
|
|
24
25
|
import { DEPTH_STENCIL_STATE_SHADOW } from "../../DEPTH_STENCIL_STATE_SHADOW.js";
|
|
26
|
+
import {
|
|
27
|
+
chunk_shadow_cascade_caster_position
|
|
28
|
+
} from "../../../shadow/map/shader/chunk_shadow_cascade_caster_position.js";
|
|
29
|
+
import {
|
|
30
|
+
chunk_read_meshlet_vertex_normal
|
|
31
|
+
} from "../../../shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.js";
|
|
32
|
+
import { MESHLET_METADATA_STRUCT } from "../../../geometry/meshlet/encoding/MESHLET_METADATA_STRUCT.js";
|
|
33
|
+
import { DEPTH_STENCIL_STATE_SHADOW_CASCADE } from "./shadow_cascade_rasterization_pass_descriptor.js";
|
|
25
34
|
import {
|
|
26
35
|
alpha_tested_fragment_resources,
|
|
27
36
|
alpha_tested_pipeline_layout,
|
|
@@ -76,7 +85,35 @@ fn main(
|
|
|
76
85
|
]
|
|
77
86
|
);
|
|
78
87
|
|
|
79
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Where a caster vertex lands in the map, for a shadow map whose rasterizer biases it:
|
|
90
|
+
* `fn alpha_tested_caster_position(node_global: mat4x4f, header: MeshletMetadata, vertex_id: u32, position_os: vec3f) -> vec4f`.
|
|
91
|
+
*/
|
|
92
|
+
const chunk_caster_position_plain = CodeChunk.from(
|
|
93
|
+
//language=WGSL
|
|
94
|
+
`
|
|
95
|
+
fn alpha_tested_caster_position(node_global: mat4x4f, header: ${MESHLET_METADATA_STRUCT.wgsl_ref}, vertex_id: u32, position_os: vec3f) -> vec4f {
|
|
96
|
+
return camera.view_projection_matrix * node_global * vec4(position_os, 1.0);
|
|
97
|
+
}
|
|
98
|
+
`, [MESHLET_METADATA_STRUCT.declaration_chunk]);
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The same for a cascade: pushed by Unreal's caster bias, {@link chunk_shadow_cascade_caster_position}.
|
|
102
|
+
*/
|
|
103
|
+
const chunk_caster_position_cascade = CodeChunk.from(
|
|
104
|
+
//language=WGSL
|
|
105
|
+
`
|
|
106
|
+
fn alpha_tested_caster_position(node_global: mat4x4f, header: ${MESHLET_METADATA_STRUCT.wgsl_ref}, vertex_id: u32, position_os: vec3f) -> vec4f {
|
|
107
|
+
return shadow_cascade_caster_position(node_global, position_os, read_meshlet_vertex_normal(header, vertex_id));
|
|
108
|
+
}
|
|
109
|
+
`, [MESHLET_METADATA_STRUCT.declaration_chunk, chunk_shadow_cascade_caster_position, chunk_read_meshlet_vertex_normal]);
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {CodeChunk} caster_position defines `alpha_tested_caster_position`
|
|
113
|
+
* @returns {string} the vertex stage
|
|
114
|
+
*/
|
|
115
|
+
function vertex_code_with(caster_position) {
|
|
116
|
+
return ShaderDescriptor.from({
|
|
80
117
|
resources: alpha_tested_vertex_resources,
|
|
81
118
|
body: CodeChunk.from(
|
|
82
119
|
//language=WGSL
|
|
@@ -128,7 +165,7 @@ fn main(
|
|
|
128
165
|
let position_world = node.global * vec4(meshlet_vertex.position, 1.0);
|
|
129
166
|
|
|
130
167
|
output.position_world = position_world.xyz / position_world.w;
|
|
131
|
-
output.position =
|
|
168
|
+
output.position = alpha_tested_caster_position(node.global, meshlet_header, resolved_vertex_id, meshlet_vertex.position);
|
|
132
169
|
|
|
133
170
|
output.uv = meshlet_vertex.uv;
|
|
134
171
|
|
|
@@ -140,11 +177,56 @@ fn main(
|
|
|
140
177
|
chunk_scene_database_access,
|
|
141
178
|
chunk_triangle_winding_is_reversed,
|
|
142
179
|
chunk_triangle_list_reverse_winding,
|
|
180
|
+
caster_position,
|
|
143
181
|
]
|
|
144
182
|
)
|
|
145
|
-
});
|
|
183
|
+
}).source;
|
|
184
|
+
}
|
|
146
185
|
|
|
147
|
-
|
|
186
|
+
/**
|
|
187
|
+
* An alpha-tested shadow pass, one pipeline per template.
|
|
188
|
+
*
|
|
189
|
+
* @param {string} label
|
|
190
|
+
* @param {string} vertex_code
|
|
191
|
+
* @param {DepthStencilState} depth_stencil
|
|
192
|
+
* @returns {TemplatePassDescriptor}
|
|
193
|
+
*/
|
|
194
|
+
function alpha_tested_shadow_pass(label, vertex_code, depth_stencil) {
|
|
195
|
+
const pass = new TemplatePassDescriptor(label, template => {
|
|
196
|
+
const shader_fragment = ShaderDescriptor.from({
|
|
197
|
+
label: `${label} / ${template.name}`,
|
|
198
|
+
resources: alpha_tested_fragment_resources(template),
|
|
199
|
+
body: CodeChunk.from('', [
|
|
200
|
+
template.opacity ?? chunk_material_opacity_opaque,
|
|
201
|
+
fragment_body,
|
|
202
|
+
])
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return RenderPipelineDescriptor.from({
|
|
206
|
+
label: `${label} / ${template.name}`,
|
|
207
|
+
layout: alpha_tested_pipeline_layout(template),
|
|
208
|
+
vertex: {
|
|
209
|
+
module: {
|
|
210
|
+
code: vertex_code
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
fragment: {
|
|
214
|
+
module: {
|
|
215
|
+
code: shader_fragment.source
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
depthStencil: depth_stencil,
|
|
219
|
+
primitive: rasterization_primitive_state
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Clear depth to 0 for reverse Z technique
|
|
225
|
+
*/
|
|
226
|
+
pass.depthStencilAttachment.depthClearValue = DEPTH_BACKGROUND_VALUE;
|
|
227
|
+
|
|
228
|
+
return pass;
|
|
229
|
+
}
|
|
148
230
|
|
|
149
231
|
/**
|
|
150
232
|
* The shadow pass for alpha-tested casters, one pipeline per template: what is cut out on screen is
|
|
@@ -152,35 +234,20 @@ const vertex_code = shader_vertex.source;
|
|
|
152
234
|
*
|
|
153
235
|
* @type {TemplatePassDescriptor}
|
|
154
236
|
*/
|
|
155
|
-
export const shadow_rasterization_alpha_tested_pass_descriptor =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
template.opacity ?? chunk_material_opacity_opaque,
|
|
161
|
-
fragment_body,
|
|
162
|
-
])
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return RenderPipelineDescriptor.from({
|
|
166
|
-
label: `Rasterize to Depth Buffer / alpha-tested / ${template.name}`,
|
|
167
|
-
layout: alpha_tested_pipeline_layout(template),
|
|
168
|
-
vertex: {
|
|
169
|
-
module: {
|
|
170
|
-
code: vertex_code
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
fragment: {
|
|
174
|
-
module: {
|
|
175
|
-
code: shader_fragment.source
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
depthStencil: DEPTH_STENCIL_STATE_SHADOW,
|
|
179
|
-
primitive: rasterization_primitive_state
|
|
180
|
-
});
|
|
181
|
-
});
|
|
237
|
+
export const shadow_rasterization_alpha_tested_pass_descriptor = alpha_tested_shadow_pass(
|
|
238
|
+
"Rasterize to Depth Buffer / alpha-tested",
|
|
239
|
+
vertex_code_with(chunk_caster_position_plain),
|
|
240
|
+
DEPTH_STENCIL_STATE_SHADOW
|
|
241
|
+
);
|
|
182
242
|
|
|
183
243
|
/**
|
|
184
|
-
*
|
|
244
|
+
* The same for a directional light's cascades, its casters biased as `shadow_cascade_rasterization_pass_descriptor`
|
|
245
|
+
* biases the opaque ones.
|
|
246
|
+
*
|
|
247
|
+
* @type {TemplatePassDescriptor}
|
|
185
248
|
*/
|
|
186
|
-
|
|
249
|
+
export const shadow_cascade_alpha_tested_pass_descriptor = alpha_tested_shadow_pass(
|
|
250
|
+
"Rasterize to Depth Buffer / alpha-tested / cascade",
|
|
251
|
+
vertex_code_with(chunk_caster_position_cascade),
|
|
252
|
+
DEPTH_STENCIL_STATE_SHADOW_CASCADE
|
|
253
|
+
);
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("../../shader/resource/ShaderResourceGroupDescriptor.js").ShaderResourceGroupDescriptor} ShaderResourceGroupDescriptor
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The bindings a meshlet draw's vertex stage reads, as `chunk_meshlet_draw_vertex` names them, added to a group.
|
|
6
|
+
*
|
|
7
|
+
* @param {ShaderResourceGroupDescriptor} group
|
|
8
|
+
* @returns {ShaderResourceGroupDescriptor} the group
|
|
9
|
+
*/
|
|
10
|
+
export function add_rasterization_bindings(group: ShaderResourceGroupDescriptor): ShaderResourceGroupDescriptor;
|
|
1
11
|
export const rasterization_shader_resources: ShaderResourceSetDescriptor;
|
|
12
|
+
export type ShaderResourceGroupDescriptor = import("../../shader/resource/ShaderResourceGroupDescriptor.js").ShaderResourceGroupDescriptor;
|
|
2
13
|
import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
|
|
3
14
|
//# sourceMappingURL=rasterization_shader_resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rasterization_shader_resources.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/rasterize/native/rasterization_shader_resources.js"],"names":[],"mappings":"AAWA,yEAAgF;
|
|
1
|
+
{"version":3,"file":"rasterization_shader_resources.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/rasterize/native/rasterization_shader_resources.js"],"names":[],"mappings":"AAWA;;GAEG;AAEH;;;;;GAKG;AACH,kDAHW,6BAA6B,GAC3B,6BAA6B,CAazC;AAED,yEAAgF;4CAtBnE,OAAO,wDAAwD,EAAE,6BAA6B;4CAN/D,sDAAsD"}
|
|
@@ -9,16 +9,29 @@ import { GEOMETRY_ATTRIBUTE_DATA_TYPE } from "../../geometry/GEOMETRY_ATTRIBUTE_
|
|
|
9
9
|
import { GEOMETRY_METADATA_STRUCT } from "../../geometry/GEOMETRY_METADATA_STRUCT.js";
|
|
10
10
|
import { MESHLET_METADATA_STRUCT } from "../../geometry/meshlet/encoding/MESHLET_METADATA_STRUCT.js";
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import("../../shader/resource/ShaderResourceGroupDescriptor.js").ShaderResourceGroupDescriptor} ShaderResourceGroupDescriptor
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The bindings a meshlet draw's vertex stage reads, as `chunk_meshlet_draw_vertex` names them, added to a group.
|
|
18
|
+
*
|
|
19
|
+
* @param {ShaderResourceGroupDescriptor} group
|
|
20
|
+
* @returns {ShaderResourceGroupDescriptor} the group
|
|
21
|
+
*/
|
|
22
|
+
export function add_rasterization_bindings(group) {
|
|
23
|
+
return group
|
|
24
|
+
.addUniform("camera", CAMERA_UNIFORM_STRUCT)
|
|
25
|
+
.addStorageBuffer("scene_database", WebGPUBufferType.unsized)
|
|
26
|
+
.addStorageBuffer("geometries", WebGPUArray.from(GEOMETRY_METADATA_STRUCT))
|
|
27
|
+
.addStorageBuffer("meshlets", MESHLET_COLLECTION_STRUCT)
|
|
28
|
+
.addStorageBuffer("meshlet_metadata", WebGPUArray.from(MESHLET_METADATA_STRUCT))
|
|
29
|
+
.addStorageBuffer("meshlet_data", GEOMETRY_ATTRIBUTE_DATA_TYPE)
|
|
30
|
+
// one draw covers every material in the bucket, so the side a material draws is per-instance
|
|
31
|
+
// here rather than per-pass, the way the alpha-tested and forward passes can have it
|
|
32
|
+
.addStorageBuffer("materials", WebGPUArray.from(MATERIAL_METADATA_STRUCT));
|
|
33
|
+
}
|
|
34
|
+
|
|
12
35
|
export const rasterization_shader_resources = new ShaderResourceSetDescriptor();
|
|
13
36
|
|
|
14
|
-
rasterization_shader_resources.createGroup()
|
|
15
|
-
.addUniform("camera", CAMERA_UNIFORM_STRUCT)
|
|
16
|
-
.addStorageBuffer("scene_database", WebGPUBufferType.unsized)
|
|
17
|
-
.addStorageBuffer("geometries", WebGPUArray.from(GEOMETRY_METADATA_STRUCT))
|
|
18
|
-
.addStorageBuffer("meshlets", MESHLET_COLLECTION_STRUCT)
|
|
19
|
-
.addStorageBuffer("meshlet_metadata", WebGPUArray.from(MESHLET_METADATA_STRUCT))
|
|
20
|
-
.addStorageBuffer("meshlet_data", GEOMETRY_ATTRIBUTE_DATA_TYPE)
|
|
21
|
-
// one draw covers every material in the bucket, so the side a material draws is per-instance
|
|
22
|
-
// here rather than per-pass, the way the alpha-tested and forward passes can have it
|
|
23
|
-
.addStorageBuffer("materials", WebGPUArray.from(MATERIAL_METADATA_STRUCT))
|
|
24
|
-
;
|
|
37
|
+
add_rasterization_bindings(rasterization_shader_resources.createGroup());
|
package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A meshlet vertex's normal alone, in the geometry's own space: the shading frame section that follows
|
|
3
|
+
* the positions, as {@link chunk_read_meshlet_vertex} reads it, without the tangent or the sections after.
|
|
4
|
+
*
|
|
5
|
+
* ```wgsl
|
|
6
|
+
* fn read_meshlet_vertex_normal(header: MeshletMetadata, vertex_id: u32) -> vec3f
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* @type {CodeChunk}
|
|
10
|
+
*/
|
|
11
|
+
export const chunk_read_meshlet_vertex_normal: CodeChunk;
|
|
12
|
+
import { CodeChunk } from "../../../compiler/CodeChunk.js";
|
|
13
|
+
//# sourceMappingURL=chunk_read_meshlet_vertex_normal.d.ts.map
|
package/src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk_read_meshlet_vertex_normal.d.ts","sourceRoot":"","sources":["../../../../../../../../src/shade/renderer/shader/chunk/geometry/meshlet/chunk_read_meshlet_vertex_normal.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,+CAFU,SAAS,CAyBjB;0BAvCwB,gCAAgC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MESHLET_METADATA_FLAGS } from "../../../../geometry/meshlet/encoding/MESHLET_METADATA_FLAGS.js";
|
|
2
|
+
import { MESHLET_METADATA_STRUCT } from "../../../../geometry/meshlet/encoding/MESHLET_METADATA_STRUCT.js";
|
|
3
|
+
import { CodeChunk } from "../../../compiler/CodeChunk.js";
|
|
4
|
+
import { chunk_meshlet_compute_attribute_section_offset } from "./chunk_meshlet_compute_attribute_section_offset.js";
|
|
5
|
+
import { chunk_meshlet_frame_decode } from "./chunk_meshlet_frame_decode.js";
|
|
6
|
+
import { chunk_meshlet_section_sizes } from "./chunk_meshlet_section_sizes.js";
|
|
7
|
+
import { chunk_read_meshlet_attribute_u32 } from "./chunk_read_meshlet_attribute_u32.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A meshlet vertex's normal alone, in the geometry's own space: the shading frame section that follows
|
|
11
|
+
* the positions, as {@link chunk_read_meshlet_vertex} reads it, without the tangent or the sections after.
|
|
12
|
+
*
|
|
13
|
+
* ```wgsl
|
|
14
|
+
* fn read_meshlet_vertex_normal(header: MeshletMetadata, vertex_id: u32) -> vec3f
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @type {CodeChunk}
|
|
18
|
+
*/
|
|
19
|
+
export const chunk_read_meshlet_vertex_normal = CodeChunk.from(
|
|
20
|
+
//language=WGSL
|
|
21
|
+
`
|
|
22
|
+
fn read_meshlet_vertex_normal(
|
|
23
|
+
header: ${MESHLET_METADATA_STRUCT.wgsl_ref},
|
|
24
|
+
vertex_id: u32,
|
|
25
|
+
) -> vec3f {
|
|
26
|
+
let clamped_vertex_id = min(vertex_id, header.vertex_count - 1u);
|
|
27
|
+
|
|
28
|
+
// the shading frame section follows the positions
|
|
29
|
+
let frame_offset = meshlet_compute_attribute_section_offset(header) + header.vertex_count * meshlet_position_words(header.flags);
|
|
30
|
+
|
|
31
|
+
let compressed = (header.flags & ${MESHLET_METADATA_FLAGS.ATTRIBUTE_COMPRESSED_NORMAL}) != 0u;
|
|
32
|
+
|
|
33
|
+
return meshlet_frame_decode_normal(read_meshlet_attribute_u32(frame_offset + select(clamped_vertex_id, 0u, compressed)));
|
|
34
|
+
}
|
|
35
|
+
`, [
|
|
36
|
+
MESHLET_METADATA_STRUCT.declaration_chunk,
|
|
37
|
+
chunk_meshlet_compute_attribute_section_offset,
|
|
38
|
+
chunk_meshlet_section_sizes,
|
|
39
|
+
chunk_read_meshlet_attribute_u32,
|
|
40
|
+
chunk_meshlet_frame_decode,
|
|
41
|
+
]
|
|
42
|
+
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GPUSceneShadowmapContext.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GPUSceneShadowmapContext.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/shadow/map/GPUSceneShadowmapContext.js"],"names":[],"mappings":"AAsKA;;GAEG;AACH;IACI;;;;;;OAMG;IACH,iCAFW,OAAO,6CAA6C,EAAE,eAAe,QAQ/E;IA+aD;;;;;;;;OAQG;IACH,sBAPW,eAAe,aACf,eAAe,SAGf,kBAAkB,EAiE5B;IApfD,2BAAwG;IAExG;;;OAGG;IACH,SAFU,iBAAiB,CAEnB;IAQR;;;;;;;;OAQG;IACH,qBAFU,WAAW,CAED;IAsCpB;;;;;;;;OAQG;IACH,SAFU,OAAO,CAEF;IAEf;;;;;;;;;;OAUG;IACH,+BAFU,OAAO,CAEqB;IAEtC;;;;;;OAMG;IACH,yBAFU,OAAO,CAEe;IAehC;;;;;OAKG;IACH,mCAIC;IAjBD;;OAEG;IACH,kCAEC;IAcD;;;;;OAKG;IACH,kBAFU,MAAM,CAEK;IAiBrB;;;;OAIG;IACH,uCAMC;IAlBD;;OAEG;IACH,sCAEC;IA6BD;;;;OAIG;IACH,uCAMC;IAlBD;;OAEG;IACH,sCAEC;IA6BD;;;;OAIG;IACH,4CAKC;IAjBD;;OAEG;IACH,2CAEC;IA2BD;;;;;OAKG;IACH,wCAKC;IAlBD;;OAEG;IACH,uCAEC;IA4BD;;;;;;;;OAQG;IACH,6BAIC;IApBD;;OAEG;IACH,4BAEC;IA0CD;;;;OAIG;IACH,6BAIC;IAhBD;;OAEG;IACH,4BAEC;IA2FD;;OAEG;IACH,iCAEC;IAED;;;;;;OAMG;IACH,oCAEC;IAED;;;;;OAKG;IACH,oCAEC;IAoGD;;;;;OAKG;IACH,4BAMC;IA2MD;;;;;;;;;;;;OAYG;IACH;QAN+B,KAAK,EAAzB,UAAU;QACqD,IAAI,EAAnE,OAAO,8BAA8B,EAAE,cAAc;QACrC,KAAK,EAArB,MAAM;QACU,MAAM,EAAtB,MAAM;aA+BhB;IAiMD;;;;;;;OAOG;IACH,eAFa,OAAO,gCAAgC,EAAE,eAAe,EAAE,CA6CtE;IAED;;;;OAIG;IACH,+BAEC;IASD;;;;OAIG;IACH,eAHW,KAAK,GACH,SAAS,GAAC,SAAS,CAI/B;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,6BAPW,MAAM,SAEN,eAAe,eACf,MAAM,mBACN,UAAU,MAAM,CAAC,QA0G3B;IA2GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,kBAFW,sBAAsB,QA0FhC;IA0bD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,kBALa,OAAO,CAsTnB;IAED;;;;;;;;;;OAUG;IACH,iBALW,MAAM,SACN,MAAM,GACJ,KAAK,CAejB;IA2DD,gBAiBC;;CACJ;qCAx0EY,OAAO,2CAA2C,EAAE,sBAAsB;8BAC1E,OAAO,0BAA0B,EAAE,eAAe;qBAClD,OAAO,wBAAwB,EAAE,MAAM;iCACvC,OAAO,mCAAmC,EAAE,kBAAkB;oBAC9D,OAAO,4BAA4B,EAAE,KAAK;8BAC1C,OAAO,gCAAgC,EAAE,eAAe;wBACxD,OAAO,gBAAgB,EAAE,SAAS;8BAClC,OAAO,oDAAoD,EAAE,eAAe;oCAtFrD,+DAA+D;kCAuBjE,oCAAoC;4BAI1C,2BAA2B;2BA1B5B,8DAA8D;kBAFvE,wCAAwC"}
|
|
@@ -12,11 +12,15 @@ import { CullPolicy } from "../../rasterize/bucket/construct_primitive_state.js"
|
|
|
12
12
|
import { graph_mesh_sphere_cull } from "../../rasterize/compute/graph_mesh_sphere_cull.js";
|
|
13
13
|
import { execute_rasterization_jobs } from "../../rasterize/execute_rasterization_jobs.js";
|
|
14
14
|
import {
|
|
15
|
+
shadow_cascade_alpha_tested_pass_descriptor,
|
|
15
16
|
shadow_rasterization_alpha_tested_pass_descriptor
|
|
16
17
|
} from "../../rasterize/native/depth/shadow_rasterization_alpha_tested_pass_descriptor.js";
|
|
17
18
|
import {
|
|
18
19
|
shadow_rasterization_pass_descriptor
|
|
19
20
|
} from "../../rasterize/native/depth/shadow_rasterization_pass_descriptor.js";
|
|
21
|
+
import {
|
|
22
|
+
shadow_cascade_rasterization_pass_descriptor
|
|
23
|
+
} from "../../rasterize/native/depth/shadow_cascade_rasterization_pass_descriptor.js";
|
|
20
24
|
import { RasterizationJob, RasterizationPipelineType } from "../../rasterize/RasterizationJob.js";
|
|
21
25
|
import { enquire_rasterize_scene_pipelines } from "../../rasterize/standard/graph_rasterize_scene.js";
|
|
22
26
|
import { graph_rasterize_scene_fast_raw } from "../../rasterize/fast/graph_rasterize_scene_fast.js";
|
|
@@ -118,9 +122,10 @@ const DEFAULT_SHADOWMAP_LOCAL_RESOLUTION = 128;
|
|
|
118
122
|
|
|
119
123
|
/**
|
|
120
124
|
* How every shadow caster is culled: as the main view culls it, so a caster's front faces are what
|
|
121
|
-
* reach the shadow map and acne is the
|
|
122
|
-
* ({@link DEPTH_STENCIL_STATE_SHADOW})
|
|
123
|
-
*
|
|
125
|
+
* reach the shadow map and acne is the caster bias's to prevent — the rasterizer's slope bias
|
|
126
|
+
* ({@link DEPTH_STENCIL_STATE_SHADOW}), or for a directional light's cascades the vertex-stage push of
|
|
127
|
+
* `shadow_cascade_rasterization_pass_descriptor`. Casting back faces on top of the rasterizer's bias
|
|
128
|
+
* pushed a caster's steep far face past the ground at its base, a gap of 1–1.5 shadow texels at every contact.
|
|
124
129
|
* @type {Readonly<Record<number, GPUCullMode>>}
|
|
125
130
|
*/
|
|
126
131
|
const SHADOW_CULL_POLICY = CullPolicy.Standard;
|
|
@@ -172,6 +177,7 @@ export class GPUSceneShadowmapContext {
|
|
|
172
177
|
*/
|
|
173
178
|
static enquirePipelines(enquiry) {
|
|
174
179
|
enquire_rasterize_scene_pipelines(enquiry, shadow_rasterization_pass_descriptor, SHADOW_CULL_POLICY);
|
|
180
|
+
enquire_rasterize_scene_pipelines(enquiry, shadow_cascade_rasterization_pass_descriptor, SHADOW_CULL_POLICY);
|
|
175
181
|
enquiry.compute.push(shader_csm_caster_range_accumulate.pipeline);
|
|
176
182
|
enquiry.compute.push(shader_csm_caster_range_publish.pipeline);
|
|
177
183
|
enquire_texture_fill_rectangle_depth_pipeline(enquiry);
|
|
@@ -1613,8 +1619,11 @@ export class GPUSceneShadowmapContext {
|
|
|
1613
1619
|
view_ctx.update();
|
|
1614
1620
|
|
|
1615
1621
|
const job = new RasterizationJob();
|
|
1616
|
-
|
|
1617
|
-
|
|
1622
|
+
// a directional light's cascades are biased the way Unreal biases them, in the vertex stage of an
|
|
1623
|
+
// orthographic view; a spot light keeps the rasterizer's bias
|
|
1624
|
+
const cascade = map.light.isDirectionalLight === true;
|
|
1625
|
+
job.opaque_pass = cascade ? shadow_cascade_rasterization_pass_descriptor : shadow_rasterization_pass_descriptor;
|
|
1626
|
+
job.alpha_tested_pass = cascade ? shadow_cascade_alpha_tested_pass_descriptor : shadow_rasterization_alpha_tested_pass_descriptor;
|
|
1618
1627
|
job.cull_policy = SHADOW_CULL_POLICY;
|
|
1619
1628
|
job.render_target = this.#render_target;
|
|
1620
1629
|
job.view_ctx = view_ctx;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visibility of a point in one of a directional light's cascades: Unreal's receiver for cascaded shadow
|
|
3
|
+
* maps (UE 5.4 `ShadowProjectionPixelShader.usf`, `ShadowFilteringCommon.ush` `Manual5x5PCF`) at its
|
|
4
|
+
* defaults, the receiver half of the scheme whose caster half is {@link chunk_shadow_caster_depth_bias}.
|
|
5
|
+
*
|
|
6
|
+
* ```wgsl
|
|
7
|
+
* fn sample_shadowmap_cascade(
|
|
8
|
+
* projection_matrix: mat4x4f, // the cascade's view-projection, orthographic, reverse-Z
|
|
9
|
+
* position_ws: vec3f,
|
|
10
|
+
* surface_normal: vec3f,
|
|
11
|
+
* light: IncidentLight,
|
|
12
|
+
* atlas_aabb: vec4f, // the cascade's tile: x0, y0, width, height in texels
|
|
13
|
+
* ) -> f32
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The point is projected as it is, with no offset. Each of the 6×6 texels around it is compared softly,
|
|
17
|
+
* `saturate((receiver − texel) / transition + 1)` in reverse-Z depth: a texel nearer the light by the
|
|
18
|
+
* transition or more shadows the point fully, one level with it not at all. The transition is 2.5 texels
|
|
19
|
+
* along the light (the caster bias's constant, `ComputeTransitionSize`), widened by
|
|
20
|
+
* `1 / lerp(1 − r.Shadow.CSMReceiverBias, 1, N·L)` with `CSMReceiverBias` 0.9: tenfold where the surface
|
|
21
|
+
* meets the light edge-on. The 36 results are weighted as a 5×5 box filter at the point's sub-texel
|
|
22
|
+
* position, the edge rows and columns by the fraction that falls inside it, and the filtered value is
|
|
23
|
+
* squared, Unreal's `ApplyPCFOverBlurCorrection`.
|
|
24
|
+
*
|
|
25
|
+
* A receiver past the far plane, depth at or below 0, is shadowed only by what was drawn in front of it:
|
|
26
|
+
* against a texel nothing was drawn into, depth 0, it is level and lit.
|
|
27
|
+
*
|
|
28
|
+
* Texels are read with `textureLoad`, clamped to the tile, so the shader needs the atlas and no sampler.
|
|
29
|
+
*
|
|
30
|
+
* @type {CodeChunk}
|
|
31
|
+
*/
|
|
32
|
+
export const chunk_sample_shadowmap_cascade: CodeChunk;
|
|
33
|
+
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
34
|
+
//# sourceMappingURL=chunk_sample_shadowmap_cascade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk_sample_shadowmap_cascade.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shadow/map/shader/chunk_sample_shadowmap_cascade.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,6CAFU,SAAS,CAqEjB;0BArGwB,uCAAuC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { INCIDENT_LIGHT_STRUCT } from "../../../shader/chunk/light/INCIDENT_LIGHT_STRUCT.js";
|
|
2
|
+
import { chunk_ndc_to_uv } from "../../../shader/chunk/texture/chunk_ndc_to_uv.js";
|
|
3
|
+
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
4
|
+
import { SHADOWMAP_ATLAS_RESOURCE } from "../SHADOWMAP_RESOURCES.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Visibility of a point in one of a directional light's cascades: Unreal's receiver for cascaded shadow
|
|
8
|
+
* maps (UE 5.4 `ShadowProjectionPixelShader.usf`, `ShadowFilteringCommon.ush` `Manual5x5PCF`) at its
|
|
9
|
+
* defaults, the receiver half of the scheme whose caster half is {@link chunk_shadow_caster_depth_bias}.
|
|
10
|
+
*
|
|
11
|
+
* ```wgsl
|
|
12
|
+
* fn sample_shadowmap_cascade(
|
|
13
|
+
* projection_matrix: mat4x4f, // the cascade's view-projection, orthographic, reverse-Z
|
|
14
|
+
* position_ws: vec3f,
|
|
15
|
+
* surface_normal: vec3f,
|
|
16
|
+
* light: IncidentLight,
|
|
17
|
+
* atlas_aabb: vec4f, // the cascade's tile: x0, y0, width, height in texels
|
|
18
|
+
* ) -> f32
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* The point is projected as it is, with no offset. Each of the 6×6 texels around it is compared softly,
|
|
22
|
+
* `saturate((receiver − texel) / transition + 1)` in reverse-Z depth: a texel nearer the light by the
|
|
23
|
+
* transition or more shadows the point fully, one level with it not at all. The transition is 2.5 texels
|
|
24
|
+
* along the light (the caster bias's constant, `ComputeTransitionSize`), widened by
|
|
25
|
+
* `1 / lerp(1 − r.Shadow.CSMReceiverBias, 1, N·L)` with `CSMReceiverBias` 0.9: tenfold where the surface
|
|
26
|
+
* meets the light edge-on. The 36 results are weighted as a 5×5 box filter at the point's sub-texel
|
|
27
|
+
* position, the edge rows and columns by the fraction that falls inside it, and the filtered value is
|
|
28
|
+
* squared, Unreal's `ApplyPCFOverBlurCorrection`.
|
|
29
|
+
*
|
|
30
|
+
* A receiver past the far plane, depth at or below 0, is shadowed only by what was drawn in front of it:
|
|
31
|
+
* against a texel nothing was drawn into, depth 0, it is level and lit.
|
|
32
|
+
*
|
|
33
|
+
* Texels are read with `textureLoad`, clamped to the tile, so the shader needs the atlas and no sampler.
|
|
34
|
+
*
|
|
35
|
+
* @type {CodeChunk}
|
|
36
|
+
*/
|
|
37
|
+
export const chunk_sample_shadowmap_cascade = CodeChunk.from(
|
|
38
|
+
//language=WGSL
|
|
39
|
+
`
|
|
40
|
+
fn sample_shadowmap_cascade(
|
|
41
|
+
projection_matrix: mat4x4f,
|
|
42
|
+
position_ws: vec3f,
|
|
43
|
+
surface_normal: vec3f,
|
|
44
|
+
light: ${INCIDENT_LIGHT_STRUCT.wgsl_ref},
|
|
45
|
+
atlas_aabb: vec4f,
|
|
46
|
+
) -> f32 {
|
|
47
|
+
const TRANSITION_TEXELS = 2.5;
|
|
48
|
+
const RECEIVER_BIAS = 0.9;
|
|
49
|
+
|
|
50
|
+
let row_x = vec3f(projection_matrix[0].x, projection_matrix[1].x, projection_matrix[2].x);
|
|
51
|
+
let row_y = vec3f(projection_matrix[0].y, projection_matrix[1].y, projection_matrix[2].y);
|
|
52
|
+
let row_z = vec3f(projection_matrix[0].z, projection_matrix[1].z, projection_matrix[2].z);
|
|
53
|
+
|
|
54
|
+
// NDC spans 2 across the tile
|
|
55
|
+
let texel_world_size = max(2.0 / (length(row_x) * atlas_aabb.z), 2.0 / (length(row_y) * atlas_aabb.w));
|
|
56
|
+
|
|
57
|
+
// the transition in depth units: an orthographic depth changes by |row_z| a world unit along the light
|
|
58
|
+
// never zero, as Unreal's ComputeTransitionSize keeps it, so a degenerate projection cannot make inf × 0
|
|
59
|
+
let transition = max(TRANSITION_TEXELS * texel_world_size * length(row_z), 1e-5);
|
|
60
|
+
|
|
61
|
+
let n_dot_l = saturate(dot(surface_normal, light.direction));
|
|
62
|
+
let transition_scale = mix(1.0 - RECEIVER_BIAS, 1.0, n_dot_l) / transition;
|
|
63
|
+
|
|
64
|
+
let clip = projection_matrix * vec4(position_ws, 1.0);
|
|
65
|
+
let ndc = clip.xyz / clip.w;
|
|
66
|
+
|
|
67
|
+
// past the far plane, held level with a texel nothing was drawn into
|
|
68
|
+
let depth = max(ndc.z, 0.0);
|
|
69
|
+
|
|
70
|
+
// texel centres at whole numbers
|
|
71
|
+
let texel_position = ndc_to_uv(ndc.xy) * atlas_aabb.zw - 0.5;
|
|
72
|
+
let base = floor(texel_position);
|
|
73
|
+
let fraction = texel_position - base;
|
|
74
|
+
|
|
75
|
+
let first = vec2i(base) - vec2i(2);
|
|
76
|
+
let tile_min = vec2i(atlas_aabb.xy);
|
|
77
|
+
let tile_last = vec2i(atlas_aabb.zw) - vec2i(1);
|
|
78
|
+
|
|
79
|
+
var sum = 0.0;
|
|
80
|
+
|
|
81
|
+
for (var j = 0; j < 6; j++) {
|
|
82
|
+
let weight_y = select(select(1.0, fraction.y, j == 5), 1.0 - fraction.y, j == 0);
|
|
83
|
+
|
|
84
|
+
for (var i = 0; i < 6; i++) {
|
|
85
|
+
let weight_x = select(select(1.0, fraction.x, i == 5), 1.0 - fraction.x, i == 0);
|
|
86
|
+
|
|
87
|
+
let texel = clamp(first + vec2i(i, j), vec2i(0), tile_last) + tile_min;
|
|
88
|
+
let texel_depth = textureLoad(shadowmapAtlas, texel, 0);
|
|
89
|
+
|
|
90
|
+
// reverse-Z: a texel nearer the light than the receiver has the larger depth
|
|
91
|
+
sum += weight_x * weight_y * saturate((depth - texel_depth) * transition_scale + 1.0);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let filtered = sum * (1.0 / 25.0);
|
|
96
|
+
|
|
97
|
+
// Unreal's ApplyPCFOverBlurCorrection
|
|
98
|
+
return filtered * filtered;
|
|
99
|
+
}
|
|
100
|
+
`, [
|
|
101
|
+
INCIDENT_LIGHT_STRUCT.declaration_chunk,
|
|
102
|
+
chunk_ndc_to_uv,
|
|
103
|
+
]
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
chunk_sample_shadowmap_cascade.requireResource(SHADOWMAP_ATLAS_RESOURCE);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A cascade caster's vertex in clip space, pushed away from the light by {@link chunk_shadow_caster_depth_bias}.
|
|
3
|
+
*
|
|
4
|
+
* ```wgsl
|
|
5
|
+
* fn shadow_cascade_caster_position(node_global: mat4x4f, position_os: vec3f, normal_os: vec3f) -> vec4f
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Reads `camera.view_projection_matrix` and the `view`'s `width` and `height`, the cascade's tile. The view is
|
|
9
|
+
* orthographic and reverse-Z, so the light's direction is the matrix's third row and a texel's world size is
|
|
10
|
+
* the tile's NDC span, 2, over its width in texels.
|
|
11
|
+
*
|
|
12
|
+
* @type {CodeChunk}
|
|
13
|
+
*/
|
|
14
|
+
export const chunk_shadow_cascade_caster_position: CodeChunk;
|
|
15
|
+
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
16
|
+
//# sourceMappingURL=chunk_shadow_cascade_caster_position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk_shadow_cascade_caster_position.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shadow/map/shader/chunk_shadow_cascade_caster_position.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AACH,mDAFU,SAAS,CAgCjB;0BA9CwB,uCAAuC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chunk_compute_normal_matrix_from_m4
|
|
3
|
+
} from "../../../shader/chunk/geometry/mat4/chunk_compute_normal_matrix_from_m4.js";
|
|
4
|
+
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
5
|
+
import { chunk_shadow_caster_depth_bias } from "./chunk_shadow_caster_depth_bias.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A cascade caster's vertex in clip space, pushed away from the light by {@link chunk_shadow_caster_depth_bias}.
|
|
9
|
+
*
|
|
10
|
+
* ```wgsl
|
|
11
|
+
* fn shadow_cascade_caster_position(node_global: mat4x4f, position_os: vec3f, normal_os: vec3f) -> vec4f
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Reads `camera.view_projection_matrix` and the `view`'s `width` and `height`, the cascade's tile. The view is
|
|
15
|
+
* orthographic and reverse-Z, so the light's direction is the matrix's third row and a texel's world size is
|
|
16
|
+
* the tile's NDC span, 2, over its width in texels.
|
|
17
|
+
*
|
|
18
|
+
* @type {CodeChunk}
|
|
19
|
+
*/
|
|
20
|
+
export const chunk_shadow_cascade_caster_position = CodeChunk.from(
|
|
21
|
+
//language=WGSL
|
|
22
|
+
`
|
|
23
|
+
fn shadow_cascade_caster_position(node_global: mat4x4f, position_os: vec3f, normal_os: vec3f) -> vec4f {
|
|
24
|
+
let vp = camera.view_projection_matrix;
|
|
25
|
+
|
|
26
|
+
let row_x = vec3f(vp[0].x, vp[1].x, vp[2].x);
|
|
27
|
+
let row_y = vec3f(vp[0].y, vp[1].y, vp[2].y);
|
|
28
|
+
let light_direction = normalize(vec3f(vp[0].z, vp[1].z, vp[2].z));
|
|
29
|
+
|
|
30
|
+
let texel_world_size = max(
|
|
31
|
+
2.0 / (length(row_x) * f32(view.width)),
|
|
32
|
+
2.0 / (length(row_y) * f32(view.height))
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// a node scaled to nothing on an axis has no normal matrix: push it by the constant alone, as a normal along the
|
|
36
|
+
// light would be, rather than lose the vertex to a NaN
|
|
37
|
+
let transformed = compute_normal_matrix_from_m4(node_global) * normal_os;
|
|
38
|
+
let normal_ws = select(light_direction, normalize(transformed), dot(transformed, transformed) > 0.0);
|
|
39
|
+
let position_ws = (node_global * vec4(position_os, 1.0)).xyz;
|
|
40
|
+
|
|
41
|
+
// straight away from the light, which in an orthographic view moves only the depth
|
|
42
|
+
let pushed = position_ws - light_direction * shadow_caster_depth_bias(normal_ws, light_direction, texel_world_size);
|
|
43
|
+
|
|
44
|
+
return vp * vec4(pushed, 1.0);
|
|
45
|
+
}
|
|
46
|
+
`, [
|
|
47
|
+
chunk_shadow_caster_depth_bias,
|
|
48
|
+
chunk_compute_normal_matrix_from_m4,
|
|
49
|
+
]
|
|
50
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How far a cascade's caster vertex is pushed away from the light, in world units: Unreal's cascaded
|
|
3
|
+
* shadow map caster bias (UE 5.4 `ShadowDepthVertexShader.usf`, `FProjectedShadowInfo::UpdateShaderDepthBias`)
|
|
4
|
+
* at its defaults, in texels of the cascade.
|
|
5
|
+
*
|
|
6
|
+
* ```wgsl
|
|
7
|
+
* fn shadow_caster_depth_bias(normal_ws: vec3f, light_direction_ws: vec3f, texel_world_size: f32) -> f32
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* `2.5 texels × (1 + 1.5 × min(tan θ, 1))`, θ the angle between the vertex normal and the light, either
|
|
11
|
+
* facing. The constant is `r.Shadow.CSMDepthBias` (10) times the light's `ShadowBias` (0.5) times the
|
|
12
|
+
* cascade's `WorldSpaceTexelScale`, half a texel, at `ShadowCascadeBiasDistribution` 1. The slope term is
|
|
13
|
+
* that times `r.Shadow.CSMSlopeScaleDepthBias` (3) times the light's `ShadowSlopeBias` (0.5), with the
|
|
14
|
+
* slope clamped at `r.Shadow.ShadowMaxSlopeScaleDepthBias` (1, 45°).
|
|
15
|
+
*
|
|
16
|
+
* It is the caster half of one scheme: the rasterizer adds no bias of its own, and the receiver
|
|
17
|
+
* ({@link chunk_sample_shadowmap_cascade}) takes no offset and compares softly instead.
|
|
18
|
+
*
|
|
19
|
+
* `light_direction_ws` is unit length.
|
|
20
|
+
*
|
|
21
|
+
* @type {CodeChunk}
|
|
22
|
+
*/
|
|
23
|
+
export const chunk_shadow_caster_depth_bias: CodeChunk;
|
|
24
|
+
import { CodeChunk } from "../../../shader/compiler/CodeChunk.js";
|
|
25
|
+
//# sourceMappingURL=chunk_shadow_caster_depth_bias.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk_shadow_caster_depth_bias.d.ts","sourceRoot":"","sources":["../../../../../../../src/shade/renderer/shadow/map/shader/chunk_shadow_caster_depth_bias.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,6CAFU,SAAS,CAmBhB;0BAzCuB,uCAAuC"}
|