@footgun/cobalt 0.10.0 → 0.11.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.
@@ -104,7 +104,7 @@ async function main () {
104
104
  })
105
105
 
106
106
  const tileNodeBG = await Cobalt.initNode(Global.renderer, {
107
- type: 'cobalt:tileHDR',
107
+ type: 'cobalt:tile',
108
108
  refs: {
109
109
  tileAtlas: tileAtlasNode,
110
110
  out: 'FRAME_TEXTURE_VIEW',
@@ -118,7 +118,7 @@ async function main () {
118
118
 
119
119
  // instantiate all runnable nodes
120
120
  const tileNodeBg = await Cobalt.initNode(Global.renderer, {
121
- type: 'cobalt:tileHDR',
121
+ type: 'cobalt:tile',
122
122
  refs: {
123
123
  tileAtlas: tileAtlasNode,
124
124
  out: 'FRAME_TEXTURE_VIEW',
@@ -130,7 +130,7 @@ async function main () {
130
130
  })
131
131
 
132
132
  const tileNodeFg = await Cobalt.initNode(Global.renderer, {
133
- type: 'cobalt:tileHDR',
133
+ type: 'cobalt:tile',
134
134
  refs: {
135
135
  tileAtlas: tileAtlasNode,
136
136
  out: 'FRAME_TEXTURE_VIEW',
@@ -85,92 +85,14 @@ async function main () {
85
85
  options: {
86
86
  spriteSheetJsonUrl: './assets/spritesheet.json',
87
87
  colorTextureUrl: 'assets/spritesheet.png',
88
- emissiveTextureUrl: 'assets/spritesheet_emissive.png'
89
- }
90
- })
91
-
92
- const hdrTex = await Cobalt.initNode(renderer, {
93
- type: 'cobalt:fbTexture',
94
- refs: { },
95
- options: {
96
- label: 'hdr color texture',
97
- format: 'rgba16float',
98
- mip_count: 1,
99
- viewportScale: 1.0,
100
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
101
- }
102
- })
103
-
104
- const emissiveTex = await Cobalt.initNode(renderer, {
105
- type: 'cobalt:fbTexture',
106
- refs: { },
107
- options: {
108
- label: 'hdr emissive texture',
109
- format: 'rgba16float',
110
- mip_count: 1,
111
- viewportScale: 1.0,
112
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
113
- }
114
- })
115
-
116
- const bloomTex = await Cobalt.initNode(renderer, {
117
- type: 'cobalt:fbTexture',
118
- refs: { },
119
- options: {
120
- label: 'hdr bloom texture',
121
- format: 'rgba16float',
122
- mip_count: 7,
123
- viewportScale: 0.5,
124
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
125
- }
126
- })
127
-
128
- const bloomNode = await Cobalt.initNode(renderer, {
129
- type: 'cobalt:bloom',
130
- refs: {
131
- // key is the var name defined in this node
132
- // value is the var name in the cobalt resources dictionary
133
- emissive: emissiveTex,
134
- hdr: hdrTex,
135
- bloom: bloomTex
136
- },
137
- options: {
138
- // any extra options you want to pass to this node
139
- bloom_intensity: 0.0,
140
- bloom_knee: 0.0,
141
- bloom_threshold: 0.1, // 1.0
142
- /*
143
- // sprite instance 1
144
- sprite_instances: [
145
- {
146
- emissive_intensity: 1.0,
147
- },
148
- {
149
- emissive_intensity: 0.5,
150
- },
151
- ],
152
- */
153
- }
154
- })
155
-
156
- const tmpTex = await Cobalt.initNode(renderer, {
157
- type: 'cobalt:fbTexture',
158
- refs: { },
159
- options: {
160
- label: 'bloom + hdr compositing',
161
- format: 'PREFERRED_TEXTURE_FORMAT',
162
- mip_count: 1,
163
- viewportScale: 1.0,
164
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
165
88
  }
166
89
  })
167
90
 
168
91
  const overlayNode = await Cobalt.initNode(renderer, {
169
- type: 'cobalt:spriteHDR',
92
+ type: 'cobalt:sprite',
170
93
  refs: {
171
94
  spritesheet: spritesheet,
172
- emissive: emissiveTex,
173
- color: hdrTex,
95
+ color: 'FRAME_TEXTURE_VIEW',
174
96
  },
175
97
  options: {
176
98
  loadOp: 'clear',
@@ -178,28 +100,6 @@ async function main () {
178
100
  }
179
101
  })
180
102
 
181
- const compositeNode = await Cobalt.initNode(renderer, {
182
- type: 'cobalt:composite',
183
- refs: {
184
- hdr: hdrTex,
185
- bloom: bloomTex,
186
- combined: tmpTex,
187
- },
188
- options: {
189
- bloom_combine_constant: 0.0,
190
- },
191
- })
192
-
193
-
194
- const b = await Cobalt.initNode(renderer, {
195
- type: 'cobalt:fbBlit',
196
- refs: {
197
- in: tmpTex,
198
- out: 'FRAME_TEXTURE_VIEW',
199
- },
200
- options: { }
201
- })
202
-
203
103
 
204
104
  // test sprites
205
105
  overlayNode.addSprite('health-0.png', // name
@@ -110,7 +110,7 @@ async function main () {
110
110
 
111
111
  // instantiate all runnable nodes
112
112
  const tileNode = await Cobalt.initNode(Global.renderer, {
113
- type: 'cobalt:tileHDR',
113
+ type: 'cobalt:tile',
114
114
  refs: {
115
115
  // key is the var name defined in this node
116
116
  // value is the var name in the cobalt resources dictionary
@@ -124,7 +124,7 @@ async function main () {
124
124
  })
125
125
 
126
126
  const tileNode2 = await Cobalt.initNode(Global.renderer, {
127
- type: 'cobalt:tileHDR',
127
+ type: 'cobalt:tile',
128
128
  refs: {
129
129
  // key is the var name defined in this node
130
130
  // value is the var name in the cobalt resources dictionary
@@ -51,13 +51,6 @@
51
51
  display: none;
52
52
  }
53
53
 
54
- /* pin dat.gui to top-left so it doesn't fight the canvas */
55
- .dg.ac {
56
- top: 8px !important;
57
- left: 8px !important;
58
- right: auto !important;
59
- }
60
-
61
54
  </style>
62
55
  </head>
63
56
  <body>
@@ -129,7 +122,7 @@ async function main () {
129
122
 
130
123
  // instantiate all runnable nodes
131
124
  const tileNode = await Cobalt.initNode(Global.renderer, {
132
- type: 'cobalt:tileHDR',
125
+ type: 'cobalt:tile',
133
126
  refs: {
134
127
  // key is the var name defined in this node
135
128
  // value is the var name in the cobalt resources dictionary
@@ -143,7 +136,7 @@ async function main () {
143
136
  })
144
137
 
145
138
  const tileNode2 = await Cobalt.initNode(Global.renderer, {
146
- type: 'cobalt:tileHDR',
139
+ type: 'cobalt:tile',
147
140
  refs: {
148
141
  // key is the var name defined in this node
149
142
  // value is the var name in the cobalt resources dictionary
@@ -301,55 +294,6 @@ async function main () {
301
294
  light.setLights(lights)
302
295
 
303
296
 
304
- // ---- dat.gui tweakable panel ----
305
-
306
- const gui = new dat.GUI({ name: 'Lighting' })
307
-
308
- // ambient light (dat.gui color expects a hex string)
309
- const ambientParams = { color: '#4d4d4d' }
310
- const hexToRgb01 = hex => {
311
- const n = parseInt(hex.slice(1), 16)
312
- return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255]
313
- }
314
- const rgb01ToHex = ([r, g, b]) =>
315
- '#' + [r, g, b].map(v => Math.round(v * 255).toString(16).padStart(2, '0')).join('')
316
-
317
- ambientParams.color = rgb01ToHex([0.3, 0.3, 0.3])
318
- const ambientFolder = gui.addFolder('Ambient')
319
- ambientFolder.addColor(ambientParams, 'color').name('color').onChange(v => {
320
- light.setAmbientLight(hexToRgb01(v))
321
- })
322
- ambientFolder.open()
323
-
324
- // helper: add a folder for a single light object
325
- const addLightFolder = (folder, lightObj, colorHex) => {
326
- const params = { color: colorHex }
327
- folder.addColor(params, 'color').name('color').onChange(v => {
328
- lightObj.color = hexToRgb01(v)
329
- })
330
- folder.add(lightObj, 'intensity', 0, 50).name('intensity')
331
- folder.add(lightObj, 'radius', 1, 512).name('radius')
332
- folder.add(lightObj, 'attenuationLinear', 0, 1).name('attn linear')
333
- folder.add(lightObj, 'attenuationExp', 0, 200).name('attn exp')
334
- }
335
-
336
- const mouseLightFolder = gui.addFolder('Mouse light')
337
- addLightFolder(mouseLightFolder, mouseLight, rgb01ToHex(mouseLight.color))
338
- mouseLightFolder.open()
339
-
340
- const redLightFolder = gui.addFolder('Red light')
341
- addLightFolder(redLightFolder, movingRedLight, rgb01ToHex(movingRedLight.color))
342
- const redAnim = { animated: true }
343
- redLightFolder.add(redAnim, 'animated').name('animated')
344
-
345
- const greenLightFolder = gui.addFolder('Green light')
346
- addLightFolder(greenLightFolder, movingGreenLight, rgb01ToHex(movingGreenLight.color))
347
- const greenAnim = { animated: true }
348
- greenLightFolder.add(greenAnim, 'animated').name('animated')
349
-
350
- // ---- end gui ----
351
-
352
-
353
297
  // use resizeViewport to init values on load:
354
298
  resizeViewport(Global.renderer, window.innerWidth, window.innerHeight)
355
299
 
@@ -369,19 +313,15 @@ async function main () {
369
313
 
370
314
  mouseLight.position = convertToWorldPosition(mouseViewportPosition);
371
315
 
372
- if (greenAnim.animated) {
373
- movingGreenLight.position = [
374
- 80 * Math.cos(performance.now() / 500),
375
- 80 * Math.sin(performance.now() / 500),
376
- ];
377
- }
316
+ movingGreenLight.position = [
317
+ 80 * Math.cos(performance.now() / 500),
318
+ 80 * Math.sin(performance.now() / 500),
319
+ ];
378
320
 
379
- if (redAnim.animated) {
380
- movingRedLight.position = [
381
- 40 * Math.cos(performance.now() / 500),
382
- 60,
383
- ];
384
- }
321
+ movingRedLight.position = [
322
+ 40 * Math.cos(performance.now() / 500),
323
+ 60,
324
+ ];
385
325
  light.setLights(lights)
386
326
 
387
327
  Cobalt.draw(Global.renderer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
package/src/cobalt.js CHANGED
@@ -15,8 +15,8 @@ import spriteNode from './sprite/sprite.js'
15
15
  import spriteHDRNode from './sprite-hdr/sprite.js'
16
16
  import spritesheetNode from './spritesheet/spritesheet.js'
17
17
  // built-in resource nodes
18
- import tileAtlasNode from './tile-hdr/atlas.js'
19
- import tileHDRNode from './tile-hdr/tile.js'
18
+ import tileAtlasNode from './tile/atlas.js'
19
+ import tileNode from './tile/tile.js'
20
20
 
21
21
  // create and initialize a WebGPU renderer for a given canvas
22
22
  // returns the data structure containing all WebGPU related stuff
@@ -70,7 +70,7 @@ export async function init(ctx, viewportWidth, viewportHeight) {
70
70
  'cobalt:bloom': bloomNode,
71
71
  'cobalt:composite': compositeNode,
72
72
  'cobalt:spriteHDR': spriteHDRNode,
73
- 'cobalt:tileHDR': tileHDRNode,
73
+ 'cobalt:tile': tileNode,
74
74
  'cobalt:displacement': displacementNode,
75
75
  'cobalt:fbBlit': fbBlitNode,
76
76
  'cobalt:primitives': primitivesNode,
@@ -1,4 +1,13 @@
1
- export default function createTexture(device, label, width, height, mip_count, format, usage) {
1
+ export default function createTexture(
2
+ device,
3
+ label,
4
+ width,
5
+ height,
6
+ mip_count,
7
+ format,
8
+ usage,
9
+ filter = 'linear',
10
+ ) {
2
11
  const texture = device.createTexture({
3
12
  label,
4
13
  size: { width, height },
@@ -32,9 +41,9 @@ export default function createTexture(device, label, width, height, mip_count, f
32
41
  addressModeU: 'clamp-to-edge',
33
42
  addressModeV: 'clamp-to-edge',
34
43
  addressModeW: 'clamp-to-edge',
35
- magFilter: 'linear',
36
- minFilter: 'linear',
37
- mipmapFilter: 'linear',
44
+ magFilter: filter,
45
+ minFilter: filter,
46
+ mipmapFilter: filter,
38
47
  })
39
48
 
40
49
  return {
@@ -47,6 +47,7 @@ async function init(cobalt, node) {
47
47
  mip_count,
48
48
  format,
49
49
  usage,
50
+ node.options.filter,
50
51
  )
51
52
  }
52
53