@footgun/cobalt 0.11.1 → 0.12.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/bundle.js +2 -2
  3. package/examples/01-primitives/index.html +11 -0
  4. package/examples/01-primitives/main.js +4 -3
  5. package/examples/01-primitives/system-renderer.js +1 -1
  6. package/examples/02-sprites/component-transform.js +1 -1
  7. package/examples/02-sprites/entity-sprite.js +2 -1
  8. package/examples/02-sprites/hdr.html +15 -4
  9. package/examples/02-sprites/index.html +15 -3
  10. package/examples/02-sprites/system-renderer.js +1 -1
  11. package/examples/03-tiles/component-transform.js +1 -1
  12. package/examples/03-tiles/entity-sprite.js +2 -1
  13. package/examples/03-tiles/index.html +15 -3
  14. package/examples/03-tiles/system-renderer.js +1 -1
  15. package/examples/04-overlay/index.html +13 -2
  16. package/examples/05-bloom/component-transform.js +1 -1
  17. package/examples/05-bloom/entity-sprite.js +2 -1
  18. package/examples/05-bloom/index.html +15 -4
  19. package/examples/05-bloom/system-renderer.js +1 -1
  20. package/examples/06-displacement/component-transform.js +1 -1
  21. package/examples/06-displacement/entity-sprite.js +2 -1
  22. package/examples/06-displacement/index.html +15 -3
  23. package/examples/06-displacement/system-renderer.js +1 -1
  24. package/examples/08-light/index.html +14 -3
  25. package/package.json +2 -2
  26. package/src/bloom/bloom.js +13 -20
  27. package/src/bloom/bloom.wgsl +13 -17
  28. package/examples/01-primitives/deps.js +0 -2
  29. package/examples/02-sprites/deps.js +0 -2
  30. package/examples/03-tiles/deps.js +0 -2
  31. package/examples/05-bloom/deps.js +0 -2
  32. package/examples/06-displacement/deps.js +0 -2
  33. package/examples/08-light/deps.js +0 -2
@@ -59,6 +59,17 @@
59
59
  <canvas id="viewport" width="480" height="270"></canvas>
60
60
  </div>
61
61
 
62
+ <script type="importmap">
63
+ {
64
+ "imports": {
65
+ "ecs": "https://esm.sh/ecs@0.21.0",
66
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
67
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
68
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
69
+ }
70
+ }
71
+ </script>
72
+
62
73
  <script type="module" src="./main.js"></script>
63
74
 
64
75
  </body>
@@ -1,10 +1,11 @@
1
1
  import Global from './Global.js'
2
2
  import * as Cobalt from '../../bundle.js'
3
3
  import constants from './constants.js'
4
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
5
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
4
+ import dat from 'dat.gui'
5
+ import debounce from 'lodash.debounce'
6
6
  import rendererSystem from './system-renderer.js'
7
- import { ECS, vec2 } from './deps.js'
7
+ import ECS from 'ecs'
8
+ import { vec2 } from 'wgpu-matrix'
8
9
 
9
10
 
10
11
  async function main () {
@@ -1,6 +1,6 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import Global from './Global.js'
3
- import { ECS } from './deps.js'
3
+ import ECS from 'ecs'
4
4
 
5
5
 
6
6
  // @param Object renderer Cobalt render state
@@ -1,4 +1,4 @@
1
- import { vec3 } from './deps.js'
1
+ import { vec3 } from 'wgpu-matrix'
2
2
 
3
3
 
4
4
  export default function componentTransform (obj) {
@@ -1,7 +1,8 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import animationComponent from './component-animation.js'
3
3
  import transformComponent from './component-transform.js'
4
- import { ECS, vec2, vec3, vec4 } from './deps.js'
4
+ import ECS from 'ecs'
5
+ import { vec2, vec3, vec4 } from 'wgpu-matrix'
5
6
 
6
7
 
7
8
  export default function spriteEntity (world, opts) {
@@ -59,16 +59,27 @@
59
59
  <canvas id="viewport" width="480" height="270"></canvas>
60
60
  </div>
61
61
 
62
+ <script type="importmap">
63
+ {
64
+ "imports": {
65
+ "ecs": "https://esm.sh/ecs@0.21.0",
66
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
67
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
68
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
69
+ }
70
+ }
71
+ </script>
72
+
62
73
  <script type="module">
63
74
  import Global from './Global.js'
64
75
  import * as Cobalt from '../../bundle.js'
65
76
  import constants from './constants.js'
66
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
67
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
68
- //import animationSystem from './system-animation.js'
77
+ import dat from 'dat.gui'
78
+ import debounce from 'lodash.debounce'
69
79
  import rendererSystem from './system-renderer.js'
70
80
  import spriteEntity from './entity-sprite.js'
71
- import { ECS, vec2 } from './deps.js'
81
+ import ECS from 'ecs'
82
+ import { vec2 } from 'wgpu-matrix'
72
83
 
73
84
 
74
85
  async function main () {
@@ -59,15 +59,27 @@
59
59
  <canvas id="viewport" width="480" height="270"></canvas>
60
60
  </div>
61
61
 
62
+ <script type="importmap">
63
+ {
64
+ "imports": {
65
+ "ecs": "https://esm.sh/ecs@0.21.0",
66
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
67
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
68
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
69
+ }
70
+ }
71
+ </script>
72
+
62
73
  <script type="module">
63
74
  import Global from './Global.js'
64
75
  import * as Cobalt from '../../bundle.js'
65
76
  import constants from './constants.js'
66
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
67
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
77
+ import dat from 'dat.gui'
78
+ import debounce from 'lodash.debounce'
68
79
  import rendererSystem from './system-renderer.js'
69
80
  import spriteEntity from './entity-sprite.js'
70
- import { ECS, vec2 } from './deps.js'
81
+ import ECS from 'ecs'
82
+ import { vec2 } from 'wgpu-matrix'
71
83
 
72
84
 
73
85
  async function main () {
@@ -1,6 +1,6 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import Global from './Global.js'
3
- import { ECS } from './deps.js'
3
+ import ECS from 'ecs'
4
4
 
5
5
 
6
6
  const SPRITE_QUERY = [ 'sprite' ]
@@ -1,4 +1,4 @@
1
- import { vec3 } from './deps.js'
1
+ import { vec3 } from 'wgpu-matrix'
2
2
 
3
3
 
4
4
  export default function componentTransform (obj) {
@@ -1,7 +1,8 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import animationComponent from './component-animation.js'
3
3
  import transformComponent from './component-transform.js'
4
- import { ECS, vec3, vec4 } from './deps.js'
4
+ import ECS from 'ecs'
5
+ import { vec3, vec4 } from 'wgpu-matrix'
5
6
 
6
7
 
7
8
  export default function spriteEntity (world, opts) {
@@ -71,16 +71,28 @@
71
71
  <button type="button" style="left: 180px">disable bg sprite texture</button>
72
72
 
73
73
 
74
+ <script type="importmap">
75
+ {
76
+ "imports": {
77
+ "ecs": "https://esm.sh/ecs@0.21.0",
78
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
79
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
80
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
81
+ }
82
+ }
83
+ </script>
84
+
74
85
  <script type="module">
75
86
  import Global from './Global.js'
76
87
  import * as Cobalt from '../../bundle.js'
77
88
  import constants from './constants.js'
78
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
79
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
89
+ import dat from 'dat.gui'
90
+ import debounce from 'lodash.debounce'
80
91
  //import animationSystem from './system-animation.js'
81
92
  import rendererSystem from './system-renderer.js'
82
93
  import spriteEntity from './entity-sprite.js'
83
- import { ECS, vec2 } from './deps.js'
94
+ import ECS from 'ecs'
95
+ import { vec2 } from 'wgpu-matrix'
84
96
 
85
97
 
86
98
  async function main () {
@@ -1,6 +1,6 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import Global from './Global.js'
3
- import { ECS } from './deps.js'
3
+ import ECS from 'ecs'
4
4
 
5
5
 
6
6
  const SPRITE_QUERY = [ 'sprite' ]
@@ -63,11 +63,22 @@
63
63
  <canvas id="viewport" width="480" height="270"></canvas>
64
64
  </div>
65
65
 
66
+ <script type="importmap">
67
+ {
68
+ "imports": {
69
+ "ecs": "https://esm.sh/ecs@0.21.0",
70
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
71
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
72
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
73
+ }
74
+ }
75
+ </script>
76
+
66
77
  <script type="module">
67
78
  import * as Cobalt from '../../bundle.js'
68
79
  import constants from './constants.js'
69
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
70
- import { vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
80
+ import debounce from 'lodash.debounce'
81
+ import { vec2, vec3, vec4 } from 'wgpu-matrix'
71
82
 
72
83
 
73
84
  async function main () {
@@ -1,4 +1,4 @@
1
- import { vec3 } from './deps.js'
1
+ import { vec3 } from 'wgpu-matrix'
2
2
 
3
3
 
4
4
  export default function componentTransform (obj) {
@@ -1,7 +1,8 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import animationComponent from './component-animation.js'
3
3
  import transformComponent from './component-transform.js'
4
- import { ECS, vec3, vec4 } from './deps.js'
4
+ import ECS from 'ecs'
5
+ import { vec3, vec4 } from 'wgpu-matrix'
5
6
 
6
7
 
7
8
  export default function spriteEntity (world, opts) {
@@ -62,16 +62,27 @@
62
62
  <canvas id="viewport" width="480" height="270"></canvas>
63
63
  </div>
64
64
 
65
+ <script type="importmap">
66
+ {
67
+ "imports": {
68
+ "ecs": "https://esm.sh/ecs@0.21.0",
69
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
70
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
71
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
72
+ }
73
+ }
74
+ </script>
75
+
65
76
  <script type="module">
66
77
  import Global from './Global.js'
67
78
  import * as Cobalt from '../../bundle.js'
68
79
  import constants from './constants.js'
69
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
70
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
71
- //import animationSystem from './system-animation.js'
80
+ import dat from 'dat.gui'
81
+ import debounce from 'lodash.debounce'
72
82
  import rendererSystem from './system-renderer.js'
73
83
  import spriteEntity from './entity-sprite.js'
74
- import { ECS, vec2 } from './deps.js'
84
+ import ECS from 'ecs'
85
+ import { vec2 } from 'wgpu-matrix'
75
86
 
76
87
 
77
88
  async function main () {
@@ -1,6 +1,6 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import Global from './Global.js'
3
- import { ECS } from './deps.js'
3
+ import ECS from 'ecs'
4
4
 
5
5
 
6
6
  const SPRITE_QUERY = [ 'sprite' ]
@@ -1,4 +1,4 @@
1
- import { vec3 } from './deps.js'
1
+ import { vec3 } from 'wgpu-matrix'
2
2
 
3
3
 
4
4
  export default function componentTransform (obj) {
@@ -1,7 +1,8 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import animationComponent from './component-animation.js'
3
3
  import transformComponent from './component-transform.js'
4
- import { ECS, vec3, vec4 } from './deps.js'
4
+ import ECS from 'ecs'
5
+ import { vec3, vec4 } from 'wgpu-matrix'
5
6
 
6
7
 
7
8
  export default function spriteEntity (world, opts) {
@@ -62,15 +62,27 @@
62
62
  <canvas id="viewport" width="480" height="270"></canvas>
63
63
  </div>
64
64
 
65
+ <script type="importmap">
66
+ {
67
+ "imports": {
68
+ "ecs": "https://esm.sh/ecs@0.21.0",
69
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
70
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
71
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
72
+ }
73
+ }
74
+ </script>
75
+
65
76
  <script type="module">
66
77
  import Global from './Global.js'
67
78
  import * as Cobalt from '../../bundle.js'
68
79
  import constants from './constants.js'
69
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
70
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
80
+ import dat from 'dat.gui'
81
+ import debounce from 'lodash.debounce'
71
82
  import rendererSystem from './system-renderer.js'
72
83
  import spriteEntity from './entity-sprite.js'
73
- import { ECS, vec2 } from './deps.js'
84
+ import ECS from 'ecs'
85
+ import { vec2 } from 'wgpu-matrix'
74
86
 
75
87
 
76
88
  async function main () {
@@ -1,6 +1,6 @@
1
1
  import * as Cobalt from '../../bundle.js'
2
2
  import Global from './Global.js'
3
- import { ECS } from './deps.js'
3
+ import ECS from 'ecs'
4
4
 
5
5
 
6
6
  const SPRITE_QUERY = [ 'sprite' ]
@@ -61,13 +61,24 @@
61
61
  <canvas id="viewport" width="480" height="270"></canvas>
62
62
  </div>
63
63
 
64
+ <script type="importmap">
65
+ {
66
+ "imports": {
67
+ "ecs": "https://esm.sh/ecs@0.21.0",
68
+ "wgpu-matrix": "https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js",
69
+ "dat.gui": "https://esm.sh/dat.gui@0.7.9",
70
+ "lodash.debounce": "https://esm.sh/lodash.debounce@4.0.8"
71
+ }
72
+ }
73
+ </script>
74
+
64
75
  <script type="module">
65
76
  import Global from './Global.js'
66
77
  import * as Cobalt from '../../bundle.js'
67
78
  import constants from './constants.js'
68
- import dat from 'https://cdn.skypack.dev/pin/dat.gui@v0.7.9-2wtQAdFH5SRwnJLDWGNz/mode=imports,min/optimized/dat.gui.js'
69
- import debounce from 'https://cdn.skypack.dev/pin/lodash.debounce@v4.0.8-4GXU9B066R3Th6HmjZmO/lodash.debounce.js'
70
- import { ECS } from './deps.js'
79
+ import dat from 'dat.gui'
80
+ import debounce from 'lodash.debounce'
81
+ import ECS from 'ecs'
71
82
 
72
83
  let mouseViewportPosition = [0, 0];
73
84
  const mouseButtonsDown = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@webgpu/types": "^0.1.51",
27
- "esbuild": "^0.27.0",
27
+ "esbuild": "^0.28.1",
28
28
  "esbuild-plugin-glsl": "^1.1.0"
29
29
  },
30
30
  "dependencies": {
@@ -101,14 +101,6 @@ function init(cobalt, nodeData) {
101
101
  //minBindingSize: 24 // sizeOf(BloomParam)
102
102
  },
103
103
  },
104
- {
105
- binding: 5,
106
- visibility: GPUShaderStage.COMPUTE,
107
- buffer: {
108
- type: 'uniform',
109
- //minBindingSize: 4 // sizeOf(lode_mode Param)
110
- },
111
- },
112
104
  ],
113
105
  })
114
106
 
@@ -155,6 +147,7 @@ function init(cobalt, nodeData) {
155
147
 
156
148
  const compute_pipeline_layout = device.createPipelineLayout({
157
149
  bindGroupLayouts: bloom_mat.bind_group_layout,
150
+ immediateSize: 8, // bytes reserved for var<immediate> shaderMode: u32
158
151
  })
159
152
 
160
153
  const compute_pipeline = device.createComputePipeline({
@@ -223,7 +216,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
223
216
  refs.hdr.data.view, // unused here, only for upsample passes
224
217
  refs.hdr.data.sampler,
225
218
  params_buf,
226
- (MODE_PREFILTER << 16) | 0, // mode_lod value
227
219
  ),
228
220
  )
229
221
 
@@ -239,7 +231,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
239
231
  refs.hdr.data.view, // unused here, only for upsample passes
240
232
  refs.hdr.data.sampler,
241
233
  params_buf,
242
- (MODE_DOWNSAMPLE << 16) | (i - 1), // mode_lod value
243
234
  ),
244
235
  )
245
236
 
@@ -253,7 +244,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
253
244
  refs.hdr.data.view, // unused here, only for upsample passes
254
245
  refs.hdr.data.sampler,
255
246
  params_buf,
256
- (MODE_DOWNSAMPLE << 16) | i, // mode_lod value
257
247
  ),
258
248
  )
259
249
  }
@@ -268,7 +258,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
268
258
  refs.hdr.data.view, // unused here, only for upsample passes
269
259
  refs.hdr.data.sampler,
270
260
  params_buf,
271
- (MODE_UPSAMPLE_FIRST << 16) | (BLOOM_MIP_COUNT - 2), // mode_lod value
272
261
  ),
273
262
  )
274
263
 
@@ -286,7 +275,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
286
275
  bloom_mat.bind_groups_textures[2].view,
287
276
  refs.hdr.data.sampler,
288
277
  params_buf,
289
- (MODE_UPSAMPLE << 16) | i, // mode_lod value
290
278
  ),
291
279
  )
292
280
  o = false
@@ -300,7 +288,6 @@ function set_all_bind_group(cobalt, bloom_mat, node) {
300
288
  bloom_mat.bind_groups_textures[1].view,
301
289
  refs.hdr.data.sampler,
302
290
  params_buf,
303
- (MODE_UPSAMPLE << 16) | i, // mode_lod value
304
291
  ),
305
292
  )
306
293
  o = true
@@ -359,12 +346,6 @@ function create_bloom_bind_group(
359
346
  buffer: params_buf,
360
347
  },
361
348
  },
362
- {
363
- binding: 5,
364
- resource: {
365
- buffer: lod_buf,
366
- },
367
- },
368
349
  ],
369
350
  })
370
351
  }
@@ -390,6 +371,7 @@ function draw(cobalt, node, commandEncoder) {
390
371
 
391
372
  let mip_size = get_mip_size(0, bloom_mat.bind_groups_textures[0])
392
373
 
374
+ compute_pass.setImmediates(0, new Uint32Array([MODE_PREFILTER, 0]))
393
375
  compute_pass.dispatchWorkgroups(mip_size.width / 8 + 1, mip_size.height / 4 + 1, 1)
394
376
 
395
377
  // Downsample
@@ -399,11 +381,17 @@ function draw(cobalt, node, commandEncoder) {
399
381
  // Ping
400
382
  compute_pass.setBindGroup(0, bloom_mat.bind_group[bind_group_index])
401
383
  bind_group_index += 1
384
+
385
+ compute_pass.setImmediates(0, new Uint32Array([MODE_DOWNSAMPLE, i - 1]))
386
+
402
387
  compute_pass.dispatchWorkgroups(mip_size.width / 8 + 1, mip_size.height / 4 + 1, 1)
403
388
 
404
389
  // Pong
405
390
  compute_pass.setBindGroup(0, bloom_mat.bind_group[bind_group_index])
406
391
  bind_group_index += 1
392
+
393
+ compute_pass.setImmediates(0, new Uint32Array([MODE_DOWNSAMPLE, i]))
394
+
407
395
  compute_pass.dispatchWorkgroups(mip_size.width / 8 + 1, mip_size.height / 4 + 1, 1)
408
396
  }
409
397
 
@@ -411,6 +399,8 @@ function draw(cobalt, node, commandEncoder) {
411
399
  compute_pass.setBindGroup(0, bloom_mat.bind_group[bind_group_index])
412
400
  bind_group_index += 1
413
401
  mip_size = get_mip_size(BLOOM_MIP_COUNT - 1, bloom_mat.bind_groups_textures[2])
402
+ compute_pass.setImmediates(0, new Uint32Array([MODE_UPSAMPLE_FIRST, BLOOM_MIP_COUNT - 2]))
403
+
414
404
  compute_pass.dispatchWorkgroups(mip_size.width / 8 + 1, mip_size.height / 4 + 1, 1)
415
405
 
416
406
  // Upsample
@@ -419,6 +409,9 @@ function draw(cobalt, node, commandEncoder) {
419
409
 
420
410
  compute_pass.setBindGroup(0, bloom_mat.bind_group[bind_group_index])
421
411
  bind_group_index += 1
412
+
413
+ compute_pass.setImmediates(0, new Uint32Array([MODE_UPSAMPLE, i]))
414
+
422
415
  compute_pass.dispatchWorkgroups(mip_size.width / 8 + 1, mip_size.height / 4 + 1, 1)
423
416
  }
424
417
 
@@ -1,5 +1,13 @@
1
+ requires immediate_address_space;
1
2
  // Compute Shader
2
3
 
4
+ struct myImmediate {
5
+ mode: u32,
6
+ lod: u32,
7
+ };
8
+
9
+ var<immediate> shaderMode: myImmediate;
10
+
3
11
  const BLOOM_MIP_COUNT: i32 = 7;
4
12
 
5
13
  const MODE_PREFILTER: u32 = 0u;
@@ -16,22 +24,11 @@ struct bloom_param {
16
24
  ferp: u32,
17
25
  }
18
26
 
19
- struct mode_lod_param {
20
- mode_lod: u32,
21
- }
22
-
23
-
24
27
  @group(0) @binding(0) var output_texture: texture_storage_2d<rgba16float, write>;
25
28
  @group(0) @binding(1) var input_texture: texture_2d<f32>;
26
29
  @group(0) @binding(2) var bloom_texture: texture_2d<f32>;
27
30
  @group(0) @binding(3) var samp: sampler;
28
31
  @group(0) @binding(4) var<uniform> param: bloom_param;
29
- @group(0) @binding(5) var<uniform> pc: mode_lod_param;
30
-
31
-
32
- // PushConstants don't work in webgpu in chrome because they've been removed from the spec for v1 :(
33
- // might be added after v1 though https://github.com/gpuweb/gpuweb/issues/75
34
- //var<push_constant> pc: PushConstants;
35
32
 
36
33
 
37
34
  // Quadratic color thresholding
@@ -129,8 +126,7 @@ fn combine(ex_color: vec3<f32>, color_to_add: vec3<f32>, combine_constant: f32)
129
126
  @compute @workgroup_size(8, 4, 1)
130
127
  fn cs_main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>)
131
128
  {
132
- let mode = pc.mode_lod >> 16u;
133
- let lod = pc.mode_lod & 65535u;
129
+ let lod = shaderMode.lod;
134
130
 
135
131
  let imgSize = textureDimensions(output_texture);
136
132
 
@@ -142,16 +138,16 @@ fn cs_main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>)
142
138
  let texSize = vec2<f32>(textureDimensions(input_texture, i32(lod)));
143
139
  var color: vec4<f32> = vec4<f32>(1.0);
144
140
 
145
- if (mode == MODE_PREFILTER)
141
+ if (shaderMode.mode == MODE_PREFILTER)
146
142
  {
147
143
  color = vec4<f32>(DownsampleBox13(input_texture, f32(lod), texCoords, 1.0 / texSize), 1.0);
148
144
  color = Prefilter(color, texCoords);
149
145
  }
150
- else if (mode == MODE_DOWNSAMPLE)
146
+ else if (shaderMode.mode == MODE_DOWNSAMPLE)
151
147
  {
152
148
  color = vec4<f32>(DownsampleBox13(input_texture, f32(lod), texCoords, 1.0 / texSize), 1.0);
153
149
  }
154
- else if (mode == MODE_UPSAMPLE_FIRST)
150
+ else if (shaderMode.mode == MODE_UPSAMPLE_FIRST)
155
151
  {
156
152
  let bloomTexSize = textureDimensions(input_texture, i32(lod) + 1);
157
153
  let sampleScale = 1.0;
@@ -160,7 +156,7 @@ fn cs_main(@builtin(global_invocation_id) global_invocation_id: vec3<u32>)
160
156
  let existing = textureSampleLevel(input_texture, samp, texCoords, f32(lod)).rgb;
161
157
  color = vec4<f32>(combine(existing, upsampledTexture, param.combine_constant), 1.0);
162
158
  }
163
- else if (mode == MODE_UPSAMPLE)
159
+ else if (shaderMode.mode == MODE_UPSAMPLE)
164
160
  {
165
161
  let bloomTexSize = textureDimensions(bloom_texture, i32(lod) + 1);
166
162
  let sampleScale = 1.0;
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat3, mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'
@@ -1,2 +0,0 @@
1
- export { default as ECS } from 'https://cdn.skypack.dev/pin/ecs@v0.21.0-P934LlnmSF5QgmGODbyN/mode=imports/optimized/ecs.js'
2
- export { mat4, vec2, vec3, vec4 } from 'https://wgpu-matrix.org/dist/3.x/wgpu-matrix.module.js'