@woosh/meep-engine 3.60.8 → 3.60.9
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 +1 -1
- package/src/engine/graphics3/AnimationGraphSystem.d.ts +4 -1
- package/src/engine/graphics3/AnimationGraphSystem.d.ts.map +1 -1
- package/src/engine/graphics3/AnimationGraphSystem.js +35 -5
- package/src/engine/graphics3/AnimationSystem.d.ts +1 -1
- package/src/engine/graphics3/AnimationSystem.d.ts.map +1 -1
- package/src/engine/graphics3/AnimationSystem.js +34 -5
- package/src/engine/graphics3/FoliageWindSystem.d.ts +2 -1
- package/src/engine/graphics3/FoliageWindSystem.d.ts.map +1 -1
- package/src/engine/graphics3/FoliageWindSystem.js +50 -3
- package/src/engine/graphics3/GPUFluidSystem.d.ts.map +1 -1
- package/src/engine/graphics3/GPUFluidSystem.js +16 -14
- package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts +2 -2
- package/src/engine/graphics3/GPUParticleEmitterSystem.d.ts.map +1 -1
- package/src/engine/graphics3/GPUParticleEmitterSystem.js +84 -32
- package/src/engine/graphics3/LightSystem.d.ts +4 -0
- package/src/engine/graphics3/LightSystem.d.ts.map +1 -1
- package/src/engine/graphics3/LightSystem.js +23 -6
- package/src/engine/graphics3/MeshSkinSystem.d.ts +1 -1
- package/src/engine/graphics3/MeshSkinSystem.d.ts.map +1 -1
- package/src/engine/graphics3/MeshSkinSystem.js +50 -5
- package/src/engine/graphics3/MeshSystem.d.ts +1 -0
- package/src/engine/graphics3/MeshSystem.d.ts.map +1 -1
- package/src/engine/graphics3/MeshSystem.js +22 -8
- package/src/engine/graphics3/ShadedGeometrySystem.d.ts +5 -1
- package/src/engine/graphics3/ShadedGeometrySystem.d.ts.map +1 -1
- package/src/engine/graphics3/ShadedGeometrySystem.js +56 -7
- package/src/engine/graphics3/WaterSystem.d.ts +3 -0
- package/src/engine/graphics3/WaterSystem.d.ts.map +1 -1
- package/src/engine/graphics3/WaterSystem.js +10 -2
- package/src/engine/graphics3/animation/AnimationClipsSink.d.ts +15 -7
- package/src/engine/graphics3/animation/AnimationClipsSink.d.ts.map +1 -1
- package/src/engine/graphics3/animation/AnimationClipsSink.js +42 -8
- package/src/engine/network/state/ReplicationSlotTable.d.ts +9 -5
- package/src/engine/network/state/ReplicationSlotTable.d.ts.map +1 -1
- package/src/engine/network/state/ReplicationSlotTable.js +36 -8
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/shade/renderer/GraphicsContext.d.ts +8 -0
- package/src/shade/renderer/GraphicsContext.d.ts.map +1 -1
- package/src/shade/renderer/GraphicsContext.js +29 -0
- package/src/shade/renderer/Renderer.d.ts +10 -0
- package/src/shade/renderer/Renderer.d.ts.map +1 -1
- package/src/shade/renderer/Renderer.js +22 -2
- package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
- package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
- package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +6 -6
- package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
- package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
- package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
- package/src/shade/renderer/light/GPULightCollection.d.ts +3 -1
- package/src/shade/renderer/light/GPULightCollection.d.ts.map +1 -1
- package/src/shade/renderer/light/GPULightCollection.js +34 -9
- package/src/shade/renderer/light/LightCollection.d.ts +13 -3
- package/src/shade/renderer/light/LightCollection.d.ts.map +1 -1
- package/src/shade/renderer/light/LightCollection.js +19 -3
- package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
- package/src/shade/renderer/material/GPUMaterialManager.d.ts +22 -0
- package/src/shade/renderer/material/GPUMaterialManager.d.ts.map +1 -1
- package/src/shade/renderer/material/GPUMaterialManager.js +30 -0
- package/src/shade/renderer/material/dispatch/GPUMaterialComputeDispatch.d.ts +75 -0
- package/src/shade/renderer/material/dispatch/GPUMaterialComputeDispatch.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/GPUMaterialComputeDispatch.js +338 -0
- package/src/shade/renderer/material/dispatch/MATERIAL_DISPATCH_CONSTANTS.d.ts +50 -0
- package/src/shade/renderer/material/dispatch/MATERIAL_DISPATCH_CONSTANTS.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/MATERIAL_DISPATCH_CONSTANTS.js +54 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatch.d.ts +37 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatch.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatch.js +31 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatchRecords.d.ts +42 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatchRecords.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/MaterialDispatchRecords.js +132 -0
- package/src/shade/renderer/material/dispatch/chunk_material_mesh_key.d.ts +21 -0
- package/src/shade/renderer/material/dispatch/chunk_material_mesh_key.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/chunk_material_mesh_key.js +46 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_keys.d.ts +20 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_keys.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_keys.js +111 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_pack.d.ts +18 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_pack.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/chunk_material_quad_pack.js +33 -0
- package/src/shade/renderer/material/dispatch/gbuffer_compute.d.ts +116 -0
- package/src/shade/renderer/material/dispatch/gbuffer_compute.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/gbuffer_compute.js +249 -0
- package/src/shade/renderer/material/dispatch/graph_material_dispatch_compute.d.ts +56 -0
- package/src/shade/renderer/material/dispatch/graph_material_dispatch_compute.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/graph_material_dispatch_compute.js +315 -0
- package/src/shade/renderer/material/dispatch/shader_material_dispatch_commands.d.ts +16 -0
- package/src/shade/renderer/material/dispatch/shader_material_dispatch_commands.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/shader_material_dispatch_commands.js +83 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_count.d.ts +22 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_count.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_count.js +133 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_scatter.d.ts +14 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_scatter.d.ts.map +1 -0
- package/src/shade/renderer/material/dispatch/shader_material_pixel_scatter.js +98 -0
- package/src/shade/renderer/material/standard/VT_MATERIAL_TEMPLATE.d.ts +1 -0
- package/src/shade/renderer/material/standard/VT_MATERIAL_TEMPLATE.d.ts.map +1 -1
- package/src/shade/renderer/material/standard/VT_MATERIAL_TEMPLATE.js +11 -0
- package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts +41 -6
- package/src/shade/renderer/material/standard/fragment_gbuffer.d.ts.map +1 -1
- package/src/shade/renderer/material/standard/fragment_gbuffer.js +88 -29
- package/src/shade/renderer/material/template/ShadeMaterialTemplate.d.ts +13 -1
- package/src/shade/renderer/material/template/ShadeMaterialTemplate.d.ts.map +1 -1
- package/src/shade/renderer/material/template/ShadeMaterialTemplate.js +18 -1
- package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
- package/src/shade/renderer/scene/GPUSceneContext.d.ts +6 -0
- package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
- package/src/shade/renderer/scene/GPUSceneContext.js +17 -7
- package/src/shade/renderer/scene/Scene.d.ts +4 -3
- package/src/shade/renderer/scene/Scene.d.ts.map +1 -1
- package/src/shade/renderer/scene/Scene.js +54 -53
- package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts +16 -0
- package/src/shade/renderer/scene/rows/GPUSceneRows.d.ts.map +1 -1
- package/src/shade/renderer/scene/rows/GPUSceneRows.js +34 -0
- package/src/shade/renderer/shader/chunk/geometry/normal/chunk_anti_alias_roughness_kaplanyan.d.ts +19 -0
- package/src/shade/renderer/shader/chunk/geometry/normal/chunk_anti_alias_roughness_kaplanyan.d.ts.map +1 -1
- package/src/shade/renderer/shader/chunk/geometry/normal/chunk_anti_alias_roughness_kaplanyan.js +55 -20
- package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_keyed_append.d.ts +31 -0
- package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_keyed_append.d.ts.map +1 -0
- package/src/shade/renderer/shader/chunk/subgroup/chunk_subgroup_keyed_append.js +77 -0
- package/src/shade/renderer/texture/virtual/VirtualTextureManager.d.ts +6 -0
- package/src/shade/renderer/texture/virtual/VirtualTextureManager.d.ts.map +1 -1
- package/src/shade/renderer/texture/virtual/VirtualTextureManager.js +15 -1
- package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { COLLECTION_U32_STRUCT_READ } from "../../gpu_primitive/COLLECTION_U32_STRUCT_READ.js";
|
|
2
|
+
import { chunk_folded_dispatch } from "../../gpu_primitive/indirect/chunk_folded_dispatch.js";
|
|
3
|
+
import { chunk_divide_round_up_u32 } from "../../shader/chunk/math/chunk_divide_round_up_u32.js";
|
|
4
|
+
import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
|
|
5
|
+
import { ComputeShader } from "../../shader/ComputeShader.js";
|
|
6
|
+
import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
|
|
7
|
+
import { u32 } from "../../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
8
|
+
import { WebGPUArray } from "../../shader/type/WebGPUArray.js";
|
|
9
|
+
import { WebGPUStruct } from "../../shader/type/WebGPUStruct.js";
|
|
10
|
+
import { MATERIAL_DISPATCH_QUADS_PER_GROUP, MATERIAL_DISPATCH_RECORD_STRIDE } from "./MATERIAL_DISPATCH_CONSTANTS.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {WebGPUStruct}
|
|
14
|
+
*/
|
|
15
|
+
export const MATERIAL_DISPATCH_COMMANDS_SETTINGS_STRUCT = WebGPUStruct.from({
|
|
16
|
+
tile_count: u32,
|
|
17
|
+
slot_count: u32,
|
|
18
|
+
}, "MaterialDispatchCommandsSettings");
|
|
19
|
+
|
|
20
|
+
const resources = new ShaderResourceSetDescriptor();
|
|
21
|
+
|
|
22
|
+
resources.createGroup()
|
|
23
|
+
.addStorageBuffer("offsets", COLLECTION_U32_STRUCT_READ)
|
|
24
|
+
.addStorageBuffer("records", WebGPUArray.u32, true)
|
|
25
|
+
.addUniform("settings", MATERIAL_DISPATCH_COMMANDS_SETTINGS_STRUCT)
|
|
26
|
+
;
|
|
27
|
+
|
|
28
|
+
const RECORD_WORDS = MATERIAL_DISPATCH_RECORD_STRIDE / 4;
|
|
29
|
+
|
|
30
|
+
const body = CodeChunk.from(
|
|
31
|
+
//language=WGSL
|
|
32
|
+
`
|
|
33
|
+
@compute @workgroup_size(64)
|
|
34
|
+
fn main(
|
|
35
|
+
@builtin(global_invocation_id) global_id : vec3<u32>,
|
|
36
|
+
) {
|
|
37
|
+
let slot = global_id.x;
|
|
38
|
+
|
|
39
|
+
if (slot >= settings.slot_count) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// a material's lists are its tiles', one after another
|
|
44
|
+
let first = slot * settings.tile_count;
|
|
45
|
+
let last = first + settings.tile_count - 1u;
|
|
46
|
+
|
|
47
|
+
var start = 0u;
|
|
48
|
+
|
|
49
|
+
if (first > 0u) {
|
|
50
|
+
start = offsets.elements[first - 1u];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let count = offsets.elements[last] - start;
|
|
54
|
+
|
|
55
|
+
let groups = folded_dispatch(divide_round_up_u32(count, ${MATERIAL_DISPATCH_QUADS_PER_GROUP}u));
|
|
56
|
+
|
|
57
|
+
let at = slot * ${RECORD_WORDS}u;
|
|
58
|
+
|
|
59
|
+
records[at] = groups.x;
|
|
60
|
+
records[at + 1u] = groups.y;
|
|
61
|
+
records[at + 2u] = groups.z;
|
|
62
|
+
records[at + 3u] = start;
|
|
63
|
+
records[at + 4u] = count;
|
|
64
|
+
}
|
|
65
|
+
`, [
|
|
66
|
+
chunk_folded_dispatch,
|
|
67
|
+
chunk_divide_round_up_u32,
|
|
68
|
+
]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Write each material's {@link MATERIAL_DISPATCH_RECORD_STRUCT}: its run of the pixel list, from
|
|
73
|
+
* the inclusive sums of the (material, tile) counts, and the folded workgroup counts its dispatch is
|
|
74
|
+
* issued with — `(0, 1, 1)` for a material with no pixel on screen. One invocation per material,
|
|
75
|
+
* dispatched directly over the G-buffer pass's list.
|
|
76
|
+
*
|
|
77
|
+
* @type {ComputeShader}
|
|
78
|
+
*/
|
|
79
|
+
export const shader_material_dispatch_commands = ComputeShader.from({
|
|
80
|
+
label: "Material dispatch / commands",
|
|
81
|
+
body,
|
|
82
|
+
resources,
|
|
83
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What both classification passes are told of the view and the material list.
|
|
3
|
+
*
|
|
4
|
+
* @type {WebGPUStruct}
|
|
5
|
+
*/
|
|
6
|
+
export const MATERIAL_CLASSIFY_SETTINGS_STRUCT: WebGPUStruct;
|
|
7
|
+
/**
|
|
8
|
+
* Count every 2×2 quad of the visibility buffer into the (material, tile) list of each material it
|
|
9
|
+
* holds a pixel of — see {@link chunk_material_quad_keys} — and write the cleared G-buffer value
|
|
10
|
+
* to every pixel no material will shade. One invocation per quad, a
|
|
11
|
+
* {@link MATERIAL_CLASSIFY_GROUP_SIDE}² block of quads per workgroup, dispatched over the view's
|
|
12
|
+
* resolution.
|
|
13
|
+
*
|
|
14
|
+
* `counts` must start at zero; its count header is set to the number of lists, as
|
|
15
|
+
* {@link graph_prefix_scan_csdldf} reads it.
|
|
16
|
+
*
|
|
17
|
+
* @type {ComputeShader}
|
|
18
|
+
*/
|
|
19
|
+
export const shader_material_pixel_count: ComputeShader;
|
|
20
|
+
import { WebGPUStruct } from "../../shader/type/WebGPUStruct.js";
|
|
21
|
+
import { ComputeShader } from "../../shader/ComputeShader.js";
|
|
22
|
+
//# sourceMappingURL=shader_material_pixel_count.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_material_pixel_count.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/dispatch/shader_material_pixel_count.js"],"names":[],"mappings":"AAiBA;;;;GAIG;AACH,gDAFU,YAAY,CAgBS;AAgF/B;;;;;;;;;;;GAWG;AACH,0CAFU,aAAa,CAMpB;6BA1H0B,mCAAmC;8BAJlC,+BAA+B"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { G_BUFFER_COLOR_TARGETS } from "../../gbuffer/G_BUFFER_COLOR_TARGETS.js";
|
|
2
|
+
import {
|
|
3
|
+
chunk_subgroup_keyed_append,
|
|
4
|
+
SUBGROUP_KEYED_APPEND_NONE
|
|
5
|
+
} from "../../shader/chunk/subgroup/chunk_subgroup_keyed_append.js";
|
|
6
|
+
import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
|
|
7
|
+
import { ComputeShader } from "../../shader/ComputeShader.js";
|
|
8
|
+
import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
|
|
9
|
+
import { atomic_u32, u32, vec2u } from "../../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
10
|
+
import { WebGPUArray } from "../../shader/type/WebGPUArray.js";
|
|
11
|
+
import { WebGPUStruct } from "../../shader/type/WebGPUStruct.js";
|
|
12
|
+
import { WGSLAttribute } from "../../shader/type/WGSLAttribute.js";
|
|
13
|
+
import { WGSLAttributes } from "../../shader/type/WGSLAttributes.js";
|
|
14
|
+
import { WGSLStructField } from "../../shader/type/WGSLStructField.js";
|
|
15
|
+
import { chunk_material_quad_keys } from "./chunk_material_quad_keys.js";
|
|
16
|
+
import { MATERIAL_CLASSIFY_GROUP_SIDE } from "./MATERIAL_DISPATCH_CONSTANTS.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What both classification passes are told of the view and the material list.
|
|
20
|
+
*
|
|
21
|
+
* @type {WebGPUStruct}
|
|
22
|
+
*/
|
|
23
|
+
export const MATERIAL_CLASSIFY_SETTINGS_STRUCT = WebGPUStruct.from({
|
|
24
|
+
resolution: vec2u,
|
|
25
|
+
/**
|
|
26
|
+
* Tile columns across the view.
|
|
27
|
+
*/
|
|
28
|
+
tiles_x: u32,
|
|
29
|
+
/**
|
|
30
|
+
* Tiles across the whole view.
|
|
31
|
+
*/
|
|
32
|
+
tile_count: u32,
|
|
33
|
+
/**
|
|
34
|
+
* Materials in the G-buffer pass's list, which is how many lists there are per tile.
|
|
35
|
+
*/
|
|
36
|
+
slot_count: u32,
|
|
37
|
+
}, "MaterialClassifySettings");
|
|
38
|
+
|
|
39
|
+
const resources = new ShaderResourceSetDescriptor();
|
|
40
|
+
|
|
41
|
+
resources.createGroup()
|
|
42
|
+
.addTexture("viz_buffer_mesh", "uint")
|
|
43
|
+
.addStorageBuffer("material_slots", WebGPUArray.u32)
|
|
44
|
+
// laid out as graph_prefix_scan_csdldf takes its input, so the counts are scanned where they lie
|
|
45
|
+
.addStorageBuffer("counts", WebGPUStruct.fromFields(
|
|
46
|
+
WGSLStructField.from("count", u32),
|
|
47
|
+
WGSLStructField.from("elements", WebGPUArray.from(atomic_u32), WGSLAttribute.from(WGSLAttributes.Align, 16)),
|
|
48
|
+
), true)
|
|
49
|
+
.addUniform("settings", MATERIAL_CLASSIFY_SETTINGS_STRUCT)
|
|
50
|
+
.addStorageTexture("g_buffer_pbr", G_BUFFER_COLOR_TARGETS[0].format, "2d", "write-only")
|
|
51
|
+
.addStorageTexture("g_buffer_normal", G_BUFFER_COLOR_TARGETS[1].format, "2d", "write-only")
|
|
52
|
+
.addStorageTexture("g_buffer_albedo", G_BUFFER_COLOR_TARGETS[2].format, "2d", "write-only")
|
|
53
|
+
.addStorageTexture("g_buffer_emissive", G_BUFFER_COLOR_TARGETS[3].format, "2d", "write-only")
|
|
54
|
+
;
|
|
55
|
+
|
|
56
|
+
resources.createGroup()
|
|
57
|
+
.addStorageBuffer("scene_database", WebGPUArray.u32);
|
|
58
|
+
|
|
59
|
+
const NONE = `${SUBGROUP_KEYED_APPEND_NONE}u`;
|
|
60
|
+
|
|
61
|
+
const body = CodeChunk.from(
|
|
62
|
+
//language=WGSL
|
|
63
|
+
`
|
|
64
|
+
// the later rounds run only where some lane of the subgroup holds a second, third or fourth
|
|
65
|
+
// material, a uniform condition the analysis cannot see
|
|
66
|
+
@diagnostic(off, subgroup_uniformity)
|
|
67
|
+
@compute @workgroup_size(${MATERIAL_CLASSIFY_GROUP_SIDE}, ${MATERIAL_CLASSIFY_GROUP_SIDE})
|
|
68
|
+
fn main(
|
|
69
|
+
@builtin(global_invocation_id) global_id : vec3<u32>,
|
|
70
|
+
@builtin(workgroup_id) workgroup_id : vec3<u32>,
|
|
71
|
+
@builtin(local_invocation_index) local_index : u32,
|
|
72
|
+
) {
|
|
73
|
+
let quad = global_id.xy;
|
|
74
|
+
let resolution = settings.resolution;
|
|
75
|
+
|
|
76
|
+
let q = material_quad_keys(quad, resolution, settings.tiles_x, settings.tile_count);
|
|
77
|
+
|
|
78
|
+
let covered = q.masks.x | q.masks.y | q.masks.z | q.masks.w;
|
|
79
|
+
|
|
80
|
+
for (var corner = 0u; corner < 4u; corner++) {
|
|
81
|
+
let pixel = quad * 2u + vec2<u32>(corner & 1u, corner >> 1u);
|
|
82
|
+
|
|
83
|
+
if (all(pixel < resolution) && (covered & (1u << corner)) == 0u) {
|
|
84
|
+
// no material will shade it; the fragment dispatch's targets are cleared to this
|
|
85
|
+
textureStore(g_buffer_pbr, pixel, vec4<f32>(0.0));
|
|
86
|
+
textureStore(g_buffer_normal, pixel, vec4<u32>(0u));
|
|
87
|
+
textureStore(g_buffer_albedo, pixel, vec4<f32>(0.0));
|
|
88
|
+
textureStore(g_buffer_emissive, pixel, vec4<u32>(0u));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (local_index == 0u && all(workgroup_id == vec3<u32>(0u))) {
|
|
93
|
+
counts.count = settings.slot_count * settings.tile_count;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// a quad counts once into the list of each material it holds a pixel of
|
|
97
|
+
subgroup_keyed_append(&counts.elements, q.keys.x);
|
|
98
|
+
|
|
99
|
+
if (subgroupAny(q.keys.y != ${NONE})) {
|
|
100
|
+
subgroup_keyed_append(&counts.elements, q.keys.y);
|
|
101
|
+
|
|
102
|
+
if (subgroupAny(q.keys.z != ${NONE})) {
|
|
103
|
+
subgroup_keyed_append(&counts.elements, q.keys.z);
|
|
104
|
+
|
|
105
|
+
if (subgroupAny(q.keys.w != ${NONE})) {
|
|
106
|
+
subgroup_keyed_append(&counts.elements, q.keys.w);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
`, [
|
|
112
|
+
chunk_material_quad_keys,
|
|
113
|
+
chunk_subgroup_keyed_append,
|
|
114
|
+
]
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Count every 2×2 quad of the visibility buffer into the (material, tile) list of each material it
|
|
119
|
+
* holds a pixel of — see {@link chunk_material_quad_keys} — and write the cleared G-buffer value
|
|
120
|
+
* to every pixel no material will shade. One invocation per quad, a
|
|
121
|
+
* {@link MATERIAL_CLASSIFY_GROUP_SIDE}² block of quads per workgroup, dispatched over the view's
|
|
122
|
+
* resolution.
|
|
123
|
+
*
|
|
124
|
+
* `counts` must start at zero; its count header is set to the number of lists, as
|
|
125
|
+
* {@link graph_prefix_scan_csdldf} reads it.
|
|
126
|
+
*
|
|
127
|
+
* @type {ComputeShader}
|
|
128
|
+
*/
|
|
129
|
+
export const shader_material_pixel_count = ComputeShader.from({
|
|
130
|
+
label: "Material dispatch / count quads",
|
|
131
|
+
body,
|
|
132
|
+
resources,
|
|
133
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write every 2×2 quad of the visibility buffer into the (material, tile) list of each material it
|
|
3
|
+
* holds a pixel of, with the mask of its pixels that are that material's, at the place the count
|
|
4
|
+
* pass made for it — `offsets` holds the inclusive sums of {@link shader_material_pixel_count}'s
|
|
5
|
+
* counts. Dispatched exactly as the count pass is, so it meets the same quads with the same keys and
|
|
6
|
+
* fills exactly the room that pass counted.
|
|
7
|
+
*
|
|
8
|
+
* `cursors` must start at zero, one word per list.
|
|
9
|
+
*
|
|
10
|
+
* @type {ComputeShader}
|
|
11
|
+
*/
|
|
12
|
+
export const shader_material_pixel_scatter: ComputeShader;
|
|
13
|
+
import { ComputeShader } from "../../shader/ComputeShader.js";
|
|
14
|
+
//# sourceMappingURL=shader_material_pixel_scatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shader_material_pixel_scatter.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/dispatch/shader_material_pixel_scatter.js"],"names":[],"mappings":"AAkFA;;;;;;;;;;GAUG;AACH,4CAFU,aAAa,CAMpB;8BA3F2B,+BAA+B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { COLLECTION_U32_STRUCT_READ } from "../../gpu_primitive/COLLECTION_U32_STRUCT_READ.js";
|
|
2
|
+
import {
|
|
3
|
+
chunk_subgroup_keyed_append,
|
|
4
|
+
SUBGROUP_KEYED_APPEND_NONE
|
|
5
|
+
} from "../../shader/chunk/subgroup/chunk_subgroup_keyed_append.js";
|
|
6
|
+
import { CodeChunk } from "../../shader/compiler/CodeChunk.js";
|
|
7
|
+
import { ComputeShader } from "../../shader/ComputeShader.js";
|
|
8
|
+
import { ShaderResourceSetDescriptor } from "../../shader/resource/ShaderResourceSetDescriptor.js";
|
|
9
|
+
import { atomic_u32 } from "../../shader/type/WEBGPU_WGSL_PRIMITIVE_TYPES.js";
|
|
10
|
+
import { WebGPUArray } from "../../shader/type/WebGPUArray.js";
|
|
11
|
+
import { chunk_material_quad_keys } from "./chunk_material_quad_keys.js";
|
|
12
|
+
import { chunk_material_quad_pack } from "./chunk_material_quad_pack.js";
|
|
13
|
+
import { MATERIAL_CLASSIFY_GROUP_SIDE } from "./MATERIAL_DISPATCH_CONSTANTS.js";
|
|
14
|
+
import { MATERIAL_CLASSIFY_SETTINGS_STRUCT } from "./shader_material_pixel_count.js";
|
|
15
|
+
|
|
16
|
+
const resources = new ShaderResourceSetDescriptor();
|
|
17
|
+
|
|
18
|
+
resources.createGroup()
|
|
19
|
+
.addTexture("viz_buffer_mesh", "uint")
|
|
20
|
+
.addStorageBuffer("material_slots", WebGPUArray.u32)
|
|
21
|
+
.addUniform("settings", MATERIAL_CLASSIFY_SETTINGS_STRUCT)
|
|
22
|
+
// inclusive sums of the counts, so a list starts where the one before it ends
|
|
23
|
+
.addStorageBuffer("offsets", COLLECTION_U32_STRUCT_READ)
|
|
24
|
+
.addStorageBuffer("cursors", WebGPUArray.from(atomic_u32), true)
|
|
25
|
+
.addStorageBuffer("material_quads", WebGPUArray.u32, true)
|
|
26
|
+
;
|
|
27
|
+
|
|
28
|
+
resources.createGroup()
|
|
29
|
+
.addStorageBuffer("scene_database", WebGPUArray.u32);
|
|
30
|
+
|
|
31
|
+
const NONE = `${SUBGROUP_KEYED_APPEND_NONE}u`;
|
|
32
|
+
|
|
33
|
+
const body = CodeChunk.from(
|
|
34
|
+
//language=WGSL
|
|
35
|
+
`
|
|
36
|
+
// every lane of the subgroup calls it, with a key or with none
|
|
37
|
+
fn material_quad_scatter(quad: vec2<u32>, key: u32, mask: u32) {
|
|
38
|
+
let at = subgroup_keyed_append(&cursors, key);
|
|
39
|
+
|
|
40
|
+
if (key != ${NONE}) {
|
|
41
|
+
var start = 0u;
|
|
42
|
+
|
|
43
|
+
if (key > 0u) {
|
|
44
|
+
start = offsets.elements[key - 1u];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
material_quads[start + at] = material_quad_pack(quad, mask);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// the later rounds run only where some lane of the subgroup holds a second, third or fourth
|
|
52
|
+
// material, a uniform condition the analysis cannot see
|
|
53
|
+
@diagnostic(off, subgroup_uniformity)
|
|
54
|
+
@compute @workgroup_size(${MATERIAL_CLASSIFY_GROUP_SIDE}, ${MATERIAL_CLASSIFY_GROUP_SIDE})
|
|
55
|
+
fn main(
|
|
56
|
+
@builtin(global_invocation_id) global_id : vec3<u32>,
|
|
57
|
+
) {
|
|
58
|
+
let quad = global_id.xy;
|
|
59
|
+
|
|
60
|
+
let q = material_quad_keys(quad, settings.resolution, settings.tiles_x, settings.tile_count);
|
|
61
|
+
|
|
62
|
+
material_quad_scatter(quad, q.keys.x, q.masks.x);
|
|
63
|
+
|
|
64
|
+
if (subgroupAny(q.keys.y != ${NONE})) {
|
|
65
|
+
material_quad_scatter(quad, q.keys.y, q.masks.y);
|
|
66
|
+
|
|
67
|
+
if (subgroupAny(q.keys.z != ${NONE})) {
|
|
68
|
+
material_quad_scatter(quad, q.keys.z, q.masks.z);
|
|
69
|
+
|
|
70
|
+
if (subgroupAny(q.keys.w != ${NONE})) {
|
|
71
|
+
material_quad_scatter(quad, q.keys.w, q.masks.w);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
`, [
|
|
77
|
+
chunk_material_quad_keys,
|
|
78
|
+
chunk_material_quad_pack,
|
|
79
|
+
chunk_subgroup_keyed_append,
|
|
80
|
+
]
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Write every 2×2 quad of the visibility buffer into the (material, tile) list of each material it
|
|
85
|
+
* holds a pixel of, with the mask of its pixels that are that material's, at the place the count
|
|
86
|
+
* pass made for it — `offsets` holds the inclusive sums of {@link shader_material_pixel_count}'s
|
|
87
|
+
* counts. Dispatched exactly as the count pass is, so it meets the same quads with the same keys and
|
|
88
|
+
* fills exactly the room that pass counted.
|
|
89
|
+
*
|
|
90
|
+
* `cursors` must start at zero, one word per list.
|
|
91
|
+
*
|
|
92
|
+
* @type {ComputeShader}
|
|
93
|
+
*/
|
|
94
|
+
export const shader_material_pixel_scatter = ComputeShader.from({
|
|
95
|
+
label: "Material dispatch / scatter quads",
|
|
96
|
+
body,
|
|
97
|
+
resources,
|
|
98
|
+
});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const VT_MATERIAL_TEMPLATE: ShadeMaterialTemplate;
|
|
5
5
|
export type RenderPipelineDescriptor = import("../../../descriptor/pipeline/render/RenderPipelineDescriptor.js").RenderPipelineDescriptor;
|
|
6
|
+
export type CodeChunk = import("../../shader/compiler/CodeChunk.js").CodeChunk;
|
|
6
7
|
export type GPUMaterialContext = import("../GPUMaterialContext.js").GPUMaterialContext;
|
|
7
8
|
export type StandardShadeMaterial = import("../StandardShadeMaterial.js").StandardShadeMaterial;
|
|
8
9
|
export type GPUMaterialServices = import("../template/GPUMaterialServices.js").GPUMaterialServices;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VT_MATERIAL_TEMPLATE.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/standard/VT_MATERIAL_TEMPLATE.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VT_MATERIAL_TEMPLATE.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/standard/VT_MATERIAL_TEMPLATE.js"],"names":[],"mappings":"AA+IA;;GAEG;AACH,mCAFU,qBAAqB,CAO5B;uCA9IU,OAAO,iEAAiE,EAAE,wBAAwB;wBAClG,OAAO,oCAAoC,EAAE,SAAS;iCACtD,OAAO,0BAA0B,EAAE,kBAAkB;oCACrD,OAAO,6BAA6B,EAAE,qBAAqB;kCAC3D,OAAO,oCAAoC,EAAE,mBAAmB;sCATvC,sCAAsC"}
|
|
@@ -8,6 +8,7 @@ import { SHADING_MATERIAL_VT_RESOURCE_GROUP } from "./fragment_gbuffer_vt.js";
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {import("../../../descriptor/pipeline/render/RenderPipelineDescriptor.js").RenderPipelineDescriptor} RenderPipelineDescriptor
|
|
11
|
+
* @typedef {import("../../shader/compiler/CodeChunk.js").CodeChunk} CodeChunk
|
|
11
12
|
* @typedef {import("../GPUMaterialContext.js").GPUMaterialContext} GPUMaterialContext
|
|
12
13
|
* @typedef {import("../StandardShadeMaterial.js").StandardShadeMaterial} StandardShadeMaterial
|
|
13
14
|
* @typedef {import("../template/GPUMaterialServices.js").GPUMaterialServices} GPUMaterialServices
|
|
@@ -33,6 +34,16 @@ class VirtualTextureMaterialTemplate extends ShadeMaterialTemplate {
|
|
|
33
34
|
return services.virtual_textures.material_pipeline_descriptor;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @param {GPUMaterialServices} services
|
|
39
|
+
* @returns {CodeChunk}
|
|
40
|
+
*/
|
|
41
|
+
gbuffer_surface(services) {
|
|
42
|
+
assert.defined(services.virtual_textures, 'material uses a vt_stack but no VirtualTextureManager is wired');
|
|
43
|
+
|
|
44
|
+
return services.virtual_textures.material_surface;
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
/**
|
|
37
48
|
* @param {GPUMaterialContext} ctx
|
|
38
49
|
* @param {GPUMaterialServices} services
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare in `group` what {@link build_gbuffer_laydown} reads of the visibility buffer and the
|
|
3
|
+
* view that drew it: the first four bindings of group 1, under the names the body reads them by.
|
|
4
|
+
*
|
|
5
|
+
* @param {ShaderResourceGroupDescriptor} group
|
|
6
|
+
* @returns {ShaderResourceGroupDescriptor} `group`
|
|
7
|
+
*/
|
|
8
|
+
export function add_g_buffer_viz_resources(group: ShaderResourceGroupDescriptor): ShaderResourceGroupDescriptor;
|
|
1
9
|
/**
|
|
2
10
|
* The resource set of a G-buffer pipeline whose group 0 is `material_group`.
|
|
3
11
|
*
|
|
@@ -9,13 +17,33 @@
|
|
|
9
17
|
*/
|
|
10
18
|
export function build_gbuffer_shader_resources(material_group: ShaderResourceGroupDescriptor): ShaderResourceSetDescriptor;
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* only evolve in one place.
|
|
20
|
+
* The viz-buffer → G-buffer laydown of one pixel, around a template's surface function. Everything
|
|
21
|
+
* else — vertex pulling, perspective-correct barycentric derivatives, normal frame construction,
|
|
22
|
+
* roughness AA, G-buffer encoding — is shared verbatim between templates and between every entry
|
|
23
|
+
* point that runs it, so it can only evolve in one place.
|
|
24
|
+
*
|
|
25
|
+
* Reconstructs the {@link chunk_material_surface_contract} input from the visibility buffer and
|
|
26
|
+
* calls `material_surface` once; what comes back is anti-aliased, dithered and encoded here.
|
|
27
|
+
*
|
|
28
|
+
* ```wgsl
|
|
29
|
+
* fn gbuffer_laydown(coord: vec2<f32>) -> GBufferOutput
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* `coord` is the pixel's centre in framebuffer coordinates — what a fragment's `position` holds.
|
|
33
|
+
*
|
|
34
|
+
* Every derivative it takes is analytic, from the barycentrics, except one: the specular
|
|
35
|
+
* anti-aliasing footprint, `fwidth` of the normal-mapped normal. That one the entry point supplies,
|
|
36
|
+
* by `derivatives`.
|
|
16
37
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
38
|
+
* @param {CodeChunk} surface defines `fn material_surface(s: MaterialSurfaceInput) -> MaterialSurfaceOutput`
|
|
39
|
+
* @param {CodeChunk} derivatives defines `fn gbuffer_fwidth(v: vec2<f32>) -> vec2<f32>`, `fwidth` as
|
|
40
|
+
* the stage can take it — {@link chunk_gbuffer_fwidth_fragment} in a fragment shader
|
|
41
|
+
* @returns {CodeChunk}
|
|
42
|
+
*/
|
|
43
|
+
export function build_gbuffer_laydown(surface: CodeChunk, derivatives: CodeChunk): CodeChunk;
|
|
44
|
+
/**
|
|
45
|
+
* The fragment entry of a template's G-buffer pipeline: {@link build_gbuffer_laydown} at the
|
|
46
|
+
* fragment's own pixel, which the material-depth mask has already narrowed to the material's.
|
|
19
47
|
*
|
|
20
48
|
* @param {CodeChunk} surface defines `fn material_surface(s: MaterialSurfaceInput) -> MaterialSurfaceOutput`
|
|
21
49
|
* @returns {CodeChunk}
|
|
@@ -72,6 +100,13 @@ export const g_buffer_scene_resources: ShaderResourceGroupDescriptor;
|
|
|
72
100
|
* @type {ShaderResourceSetDescriptor}
|
|
73
101
|
*/
|
|
74
102
|
export const g_buffer_shader_resources: ShaderResourceSetDescriptor;
|
|
103
|
+
/**
|
|
104
|
+
* `fn gbuffer_fwidth(v: vec2<f32>) -> vec2<f32>` for {@link build_gbuffer_laydown} in a fragment
|
|
105
|
+
* shader: the fragment's own `fwidth`, across its quad.
|
|
106
|
+
*
|
|
107
|
+
* @type {CodeChunk}
|
|
108
|
+
*/
|
|
109
|
+
export const chunk_gbuffer_fwidth_fragment: CodeChunk;
|
|
75
110
|
/**
|
|
76
111
|
* The standard material's G-buffer fragment shader.
|
|
77
112
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragment_gbuffer.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/standard/fragment_gbuffer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fragment_gbuffer.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/material/standard/fragment_gbuffer.js"],"names":[],"mappings":"AA2EA;;;;;;GAMG;AACH,kDAHW,6BAA6B,GAC3B,6BAA6B,CASzC;AAoBD;;;;;;;;GAQG;AACH,+DAHW,6BAA6B,GAC3B,2BAA2B,CAUvC;AASD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,+CALW,SAAS,eACT,SAAS,GAEP,SAAS,CA+OrB;AAgBD;;;;;;GAMG;AACH,qDAHW,SAAS,GACP,SAAS,CAerB;AAED;;;;;;;;;GASG;AACH;IAL2B,KAAK,EAArB,MAAM;IACiC,cAAc,EAArD,6BAA6B;IACV,OAAO,EAA1B,SAAS;IACP,wBAAwB,CAUpC;AAED;;;;;;;GAOG;AACH,8DAJW,MAAM,UACN,gBAAgB,GACd,wBAAwB,CA4BpC;AArbD;;;GAGG;AAGH;;;;;;;;;GASG;AACH,qCAFU,6BAA6B,CAEmC;AAwB1E;;;;GAIG;AACH,uCAFU,6BAA6B,CAEqC;AAgC5E;;;;GAIG;AACH,wCAFU,2BAA2B,CAEoE;AAyQzG;;;;;GAKG;AACH,4CAFU,SAAS,CAQhB;AAgFH;;;;GAIG;AACH,6BAFU,gBAAgB,CAMvB;8CAzc2C,wDAAwD;4CAC1D,sDAAsD;0BAFxE,oCAAoC;yCAxCrB,iEAAiE;iCA2CzE,kCAAkC"}
|