@footgun/cobalt 0.9.1 → 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.
@@ -103,89 +103,11 @@ async function main () {
103
103
  }
104
104
  })
105
105
 
106
- /*
107
- const hdrTex = await Cobalt.initNode(Global.renderer, {
108
- type: 'cobalt:fbTexture',
109
- refs: { },
110
- options: {
111
- label: 'hdr color texture',
112
- format: 'rgba16float',
113
- mip_count: 1,
114
- viewportScale: 1.0,
115
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
116
- }
117
- })
118
-
119
- const emissiveTex = await Cobalt.initNode(Global.renderer, {
120
- type: 'cobalt:fbTexture',
121
- refs: { },
122
- options: {
123
- label: 'hdr emissive texture',
124
- format: 'rgba16float',
125
- mip_count: 1,
126
- viewportScale: 1.0,
127
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
128
- }
129
- })
130
-
131
- const bloomTex = await Cobalt.initNode(Global.renderer, {
132
- type: 'cobalt:fbTexture',
133
- refs: { },
134
- options: {
135
- label: 'hdr bloom texture',
136
- format: 'rgba16float',
137
- mip_count: 7,
138
- viewportScale: 0.5,
139
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
140
- }
141
- })
142
-
143
- const bloomNode = await Cobalt.initNode(Global.renderer, {
144
- type: 'cobalt:bloom',
145
- refs: {
146
- // key is the var name defined in this node
147
- // value is the var name in the cobalt resources dictionary
148
- emissive: emissiveTex,
149
- hdr: hdrTex,
150
- bloom: bloomTex
151
- },
152
- options: {
153
- // any extra options you want to pass to this node
154
- bloom_intensity: 45.0,
155
- bloom_combine_constant: 0.3,
156
- bloom_knee: 0.2,
157
- bloom_threshold: 0.1, // 1.0
158
-
159
- // sprite instance 1
160
- sprite_instances: [
161
- {
162
- emissive_intensity: 1.0,
163
- },
164
- {
165
- emissive_intensity: 0.5,
166
- },
167
- ],
168
- }
169
- })
170
-
171
- const tmpTex = await Cobalt.initNode(Global.renderer, {
172
- type: 'cobalt:fbTexture',
173
- refs: { },
174
- options: {
175
- label: 'bloom + hdr compositing',
176
- format: 'PREFERRED_TEXTURE_FORMAT',
177
- mip_count: 1,
178
- viewportScale: 1.0,
179
- usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
180
- }
181
- })
182
- */
183
-
184
106
  const tileNodeBG = await Cobalt.initNode(Global.renderer, {
185
- type: 'cobalt:tileHDR',
107
+ type: 'cobalt:tile',
186
108
  refs: {
187
109
  tileAtlas: tileAtlasNode,
188
- hdr: 'FRAME_TEXTURE_VIEW',
110
+ out: 'FRAME_TEXTURE_VIEW',
189
111
  },
190
112
  options: {
191
113
  textureUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVR42mP4DwQACfsD/Wj6HMwAAAAASUVORK5CYII=',
@@ -196,10 +118,10 @@ async function main () {
196
118
 
197
119
  // instantiate all runnable nodes
198
120
  const tileNodeBg = await Cobalt.initNode(Global.renderer, {
199
- type: 'cobalt:tileHDR',
121
+ type: 'cobalt:tile',
200
122
  refs: {
201
123
  tileAtlas: tileAtlasNode,
202
- hdr: 'FRAME_TEXTURE_VIEW',
124
+ out: 'FRAME_TEXTURE_VIEW',
203
125
  },
204
126
  options: {
205
127
  textureUrl: 'assets/spelunky1.png',
@@ -208,10 +130,10 @@ async function main () {
208
130
  })
209
131
 
210
132
  const tileNodeFg = await Cobalt.initNode(Global.renderer, {
211
- type: 'cobalt:tileHDR',
133
+ type: 'cobalt:tile',
212
134
  refs: {
213
135
  tileAtlas: tileAtlasNode,
214
- hdr: 'FRAME_TEXTURE_VIEW',
136
+ out: 'FRAME_TEXTURE_VIEW',
215
137
  },
216
138
  options: {
217
139
  textureUrl: 'assets/spelunky0.png',
@@ -220,29 +142,6 @@ async function main () {
220
142
  })
221
143
 
222
144
 
223
- /*
224
- const compositeNode = await Cobalt.initNode(Global.renderer, {
225
- type: 'cobalt:composite',
226
- refs: {
227
- hdr: hdrTex,
228
- bloom: bloomTex,
229
- combined: tmpTex,
230
- },
231
- options: { }
232
- })
233
-
234
-
235
- const b = await Cobalt.initNode(Global.renderer, {
236
- type: 'cobalt:fbBlit',
237
- refs: {
238
- in: tmpTex,
239
- out: 'FRAME_TEXTURE_VIEW',
240
- },
241
- options: { }
242
- })
243
- */
244
-
245
-
246
145
  // use resizeViewport to init values on load:
247
146
  resizeViewport(Global.renderer, window.innerWidth, window.innerHeight)
248
147
 
@@ -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,12 +110,12 @@ 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
117
117
  tileAtlas: tileAtlasNode,
118
- hdr: hdrTex,
118
+ out: hdrTex,
119
119
  },
120
120
  options: {
121
121
  textureUrl: 'assets/spelunky1.png',
@@ -124,12 +124,12 @@ 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
131
131
  tileAtlas: tileAtlasNode,
132
- hdr: hdrTex,
132
+ out: hdrTex,
133
133
  },
134
134
  options: {
135
135
  textureUrl: 'assets/spelunky0.png',
@@ -122,12 +122,12 @@ async function main () {
122
122
 
123
123
  // instantiate all runnable nodes
124
124
  const tileNode = await Cobalt.initNode(Global.renderer, {
125
- type: 'cobalt:tileHDR',
125
+ type: 'cobalt:tile',
126
126
  refs: {
127
127
  // key is the var name defined in this node
128
128
  // value is the var name in the cobalt resources dictionary
129
129
  tileAtlas: tileAtlasNode,
130
- hdr: hdrTex,
130
+ out: hdrTex,
131
131
  },
132
132
  options: {
133
133
  textureUrl: 'assets/spelunky1.png',
@@ -136,12 +136,12 @@ async function main () {
136
136
  })
137
137
 
138
138
  const tileNode2 = await Cobalt.initNode(Global.renderer, {
139
- type: 'cobalt:tileHDR',
139
+ type: 'cobalt:tile',
140
140
  refs: {
141
141
  // key is the var name defined in this node
142
142
  // value is the var name in the cobalt resources dictionary
143
143
  tileAtlas: tileAtlasNode,
144
- hdr: hdrTex,
144
+ out: hdrTex,
145
145
  },
146
146
  options: {
147
147
  textureUrl: 'assets/spelunky0.png',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.9.1",
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
 
@@ -185,7 +185,7 @@ async function init(cobalt, nodeData) {
185
185
  targets: [
186
186
  // color
187
187
  {
188
- format: getPreferredFormat(cobalt),
188
+ format: nodeData.refs.color.data?.texture?.format || getPreferredFormat(cobalt),
189
189
  blend: {
190
190
  color: {
191
191
  srcFactor: 'src-alpha',
@@ -339,7 +339,7 @@ function draw(cobalt, node, commandEncoder) {
339
339
  colorAttachments: [
340
340
  // color
341
341
  {
342
- view: node.refs.color,
342
+ view: node.refs.color.data?.view || node.refs.color,
343
343
  clearValue: cobalt.clearValue,
344
344
  loadOp: loadOp,
345
345
  storeOp: 'store',
@@ -45,13 +45,14 @@ async function init(cobalt, node) {
45
45
  node.options.colorTextureUrl,
46
46
  format,
47
47
  )
48
- emissiveTexture = await createTextureFromUrl(
49
- cobalt,
50
- 'emissive sprite',
51
- node.options.emissiveTextureUrl,
52
- format,
53
- )
54
-
48
+ if (node.options.emissiveTextureUrl) {
49
+ emissiveTexture = await createTextureFromUrl(
50
+ cobalt,
51
+ 'emissive sprite',
52
+ node.options.emissiveTextureUrl,
53
+ format,
54
+ )
55
+ }
55
56
  // for some reason this needs to be done _after_ creating the material, or the rendering will be blurry
56
57
  canvas.style.imageRendering = 'pixelated'
57
58
  } else {
@@ -64,12 +65,14 @@ async function init(cobalt, node) {
64
65
  node.options.colorTexture,
65
66
  format,
66
67
  )
67
- emissiveTexture = await createTextureFromBuffer(
68
- cobalt,
69
- 'emissive sprite',
70
- node.options.emissiveTexture,
71
- format,
72
- )
68
+ if (node.options.emissiveTexture) {
69
+ emissiveTexture = await createTextureFromBuffer(
70
+ cobalt,
71
+ 'emissive sprite',
72
+ node.options.emissiveTexture,
73
+ format,
74
+ )
75
+ }
73
76
  }
74
77
 
75
78
  // Map sprite name → ID
@@ -85,5 +88,5 @@ async function init(cobalt, node) {
85
88
 
86
89
  function destroy(node) {
87
90
  node.data.colorTexture.texture.destroy()
88
- node.data.emissiveTexture.texture.destroy()
91
+ if (node.data.emissiveTexture) node.data.emissiveTexture.texture.destroy()
89
92
  }
@@ -18,10 +18,10 @@ Inspired by/ported from https://blog.tojicode.com/2012/07/sprite-tile-maps-on-gp
18
18
  /**
19
19
  * Refs:
20
20
  * tileAtlas (textureView, rgba8unorm, read) - tile atlas texture
21
- * hdr (textureView, rgba16float, write) - HDR render target
21
+ * out (textureView, rgba16float, write) - render target
22
22
  */
23
23
  export default {
24
- type: 'cobalt:tileHDR',
24
+ type: 'cobalt:tile',
25
25
 
26
26
  // @params Object cobalt renderer world object
27
27
  // @params Object options optional data passed when initing this node
@@ -175,8 +175,8 @@ function draw(cobalt, nodeData, commandEncoder) {
175
175
  label: 'tile',
176
176
  colorAttachments: [
177
177
  {
178
- // hdr is passsed as a node || FRAME_TEXTURE_VIEW
179
- view: nodeData.refs.hdr.data?.view || nodeData.refs.hdr,
178
+ // out is passsed as a node || FRAME_TEXTURE_VIEW
179
+ view: nodeData.refs.out.data?.view || nodeData.refs.out,
180
180
  clearValue: cobalt.clearValue,
181
181
  loadOp,
182
182
  storeOp: 'store',
File without changes
File without changes