@footgun/cobalt 0.5.0 → 0.6.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/esbuild.js CHANGED
@@ -12,5 +12,5 @@ esbuild.build({
12
12
  glsl({ minify: true })
13
13
  ],
14
14
  outfile: 'bundle.js',
15
- minify: true,
15
+ minify: false,
16
16
  })
@@ -159,7 +159,7 @@ async function main () {
159
159
  refs: { },
160
160
  options: {
161
161
  label: 'bloom + hdr compositing',
162
- format: 'bgra8unorm',
162
+ format: 'PREFERRED_TEXTURE_FORMAT',
163
163
  mip_count: 1,
164
164
  viewportScale: 1.0,
165
165
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
@@ -160,7 +160,7 @@ async function main () {
160
160
  refs: { },
161
161
  options: {
162
162
  label: 'bloom + hdr compositing',
163
- format: 'bgra8unorm',
163
+ format: 'PREFERRED_TEXTURE_FORMAT',
164
164
  mip_count: 1,
165
165
  viewportScale: 1.0,
166
166
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
@@ -178,7 +178,7 @@ async function main () {
178
178
  refs: { },
179
179
  options: {
180
180
  label: 'bloom + hdr compositing',
181
- format: 'bgra8unorm',
181
+ format: 'PREFERRED_TEXTURE_FORMAT',
182
182
  mip_count: 1,
183
183
  viewportScale: 1.0,
184
184
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
@@ -162,7 +162,7 @@ async function main () {
162
162
  refs: { },
163
163
  options: {
164
164
  label: 'bloom + hdr compositing',
165
- format: 'bgra8unorm',
165
+ format: 'PREFERRED_TEXTURE_FORMAT',
166
166
  mip_count: 1,
167
167
  viewportScale: 1.0,
168
168
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
@@ -174,7 +174,7 @@ async function main () {
174
174
  refs: { },
175
175
  options: {
176
176
  label: 'bloom + hdr compositing',
177
- format: 'bgra8unorm',
177
+ format: 'PREFERRED_TEXTURE_FORMAT',
178
178
  mip_count: 1,
179
179
  viewportScale: 1.0,
180
180
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.TEXTURE_BINDING,
@@ -11,7 +11,7 @@
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "@kmamal/gpu": "^0.2.0",
14
+ "@kmamal/gpu": "0.2.0",
15
15
  "@kmamal/sdl": "^0.11.7",
16
16
  "pngjs": "^7.0.0",
17
17
  "wgpu-matrix": "^3.4.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
@@ -0,0 +1,11 @@
1
+ > Why do I have a folder named ".vercel" in my project?
2
+ The ".vercel" folder is created when you link a directory to a Vercel project.
3
+
4
+ > What does the "project.json" file contain?
5
+ The "project.json" file contains:
6
+ - The ID of the Vercel project that you linked ("projectId")
7
+ - The ID of the user or team your Vercel project is owned by ("orgId")
8
+
9
+ > Should I commit the ".vercel" folder?
10
+ No, you should not share the ".vercel" folder with anyone.
11
+ Upon creation, it will be automatically added to your ".gitignore" file.
@@ -0,0 +1 @@
1
+ {"projectId":"prj_jJXTHkZlQjFtTW7K7D94nIPjxcOX","orgId":"team_b8j5PhQ0qhPb9qIqUQzkxmra"}
package/src/cobalt.js CHANGED
@@ -213,14 +213,6 @@ export function setViewportPosition (c, pos) {
213
213
  }
214
214
 
215
215
 
216
- export function getPreferredFormat (cobalt) {
217
- if (cobalt.canvas)
218
- return navigator.gpu.getPreferredCanvasFormat()
219
- else
220
- return cobalt.context.getPreferredFormat()
221
- }
222
-
223
-
224
216
  export function getCurrentTextureView (cobalt) {
225
217
  if (cobalt.canvas)
226
218
  return cobalt.context.getCurrentTexture().createView()
@@ -1,3 +1,4 @@
1
+ import getPreferredFormat from '../get-preferred-format.js'
1
2
  import { TrianglesBuffer } from './triangles-buffer.js'
2
3
  import { DisplacementParametersBuffer } from './displacement-parameters-buffer.js'
3
4
  import { DisplacementComposition } from './displacement-composition.js'
@@ -102,7 +103,7 @@ async function init (cobalt, node) {
102
103
 
103
104
  const displacementComposition = new DisplacementComposition({
104
105
  device,
105
- targetFormat: "bgra8unorm",
106
+ targetFormat: getPreferredFormat(cobalt),
106
107
 
107
108
  colorTextureView: node.refs.color.data.view,
108
109
  noiseMapTextureView: node.refs.map.view,
@@ -1,4 +1,5 @@
1
- import blitWGSL from './fb-blit.wgsl'
1
+ import blitWGSL from './fb-blit.wgsl'
2
+ import getPreferredFormat from '../get-preferred-format.js'
2
3
 
3
4
 
4
5
  // blit a source texture into a destination texture
@@ -6,8 +7,8 @@ import blitWGSL from './fb-blit.wgsl'
6
7
  export default {
7
8
  type: 'cobalt:fbBlit',
8
9
  refs: [
9
- { name: 'in', type: 'cobaltTexture', format: 'bgra8unorm', access: 'read' },
10
- { name: 'out', type: 'cobaltTexture', format: 'bgra8unorm', access: 'write' },
10
+ { name: 'in', type: 'cobaltTexture', format: 'PREFERRED_TEXTURE_FORMAT', access: 'read' },
11
+ { name: 'out', type: 'cobaltTexture', format: 'PREFERRED_TEXTURE_FORMAT', access: 'write' },
11
12
  ],
12
13
 
13
14
  // @params Object cobalt renderer world object
@@ -87,7 +88,7 @@ async function init (cobalt, node) {
87
88
  entryPoint: 'fs_main',
88
89
  targets: [
89
90
  {
90
- format: 'bgra8unorm',
91
+ format: getPreferredFormat(cobalt),
91
92
  blend: {
92
93
  color: {
93
94
  srcFactor: 'src-alpha',
@@ -1,4 +1,5 @@
1
- import createTexture from '../create-texture.js'
1
+ import createTexture from '../create-texture.js'
2
+ import getPreferredFormat from '../get-preferred-format.js'
2
3
 
3
4
 
4
5
  // Frame buffer textures automatically resize to match the cobalt viewport.
@@ -34,7 +35,9 @@ export default {
34
35
  async function init (cobalt, node) {
35
36
  const { device } = cobalt
36
37
 
37
- const { label, mip_count, format, usage, viewportScale } = node.options
38
+ node.options.format = node.options.format === 'PREFERRED_TEXTURE_FORMAT' ? getPreferredFormat(cobalt) : node.options.format
39
+
40
+ const { format, label, mip_count, usage, viewportScale } = node.options
38
41
 
39
42
  return createTexture(device, label, cobalt.viewport.width * viewportScale, cobalt.viewport.height * viewportScale, mip_count, format, usage)
40
43
  }
@@ -0,0 +1,7 @@
1
+ // so far this seems to be 'bgra8unorm' on macos/windows, 'bgra8unorm-srgb' on linux
2
+ export default function getPreferredFormat (cobalt) {
3
+ if (cobalt.canvas)
4
+ return navigator.gpu?.getPreferredCanvasFormat()
5
+ else
6
+ return cobalt.context.getPreferredFormat()
7
+ }
@@ -1,5 +1,6 @@
1
1
  import * as publicAPI from '../sprite/public-api.js'
2
2
  import createSpriteQuads from '../sprite/create-sprite-quads.js'
3
+ import getPreferredFormat from '../get-preferred-format.js'
3
4
  import overlayWGSL from './overlay.wgsl'
4
5
  import sortedBinaryInsert from '../sprite/sorted-binary-insert.js'
5
6
  import uuid from '../uuid.js'
@@ -142,7 +143,7 @@ async function init (cobalt, nodeData) {
142
143
  })
143
144
 
144
145
  const pipeline = device.createRenderPipeline({
145
- label: 'overlay',
146
+ label: 'overlaysprite',
146
147
  vertex: {
147
148
  module: device.createShaderModule({
148
149
  code: overlayWGSL
@@ -159,7 +160,7 @@ async function init (cobalt, nodeData) {
159
160
  targets: [
160
161
  // color
161
162
  {
162
- format: 'bgra8unorm',
163
+ format: getPreferredFormat(cobalt),
163
164
  blend: {
164
165
  color: {
165
166
  srcFactor: 'src-alpha',
@@ -1,3 +1,4 @@
1
+ import getPreferredFormat from '../get-preferred-format.js'
1
2
  import primitivesWGSL from './primitives.wgsl'
2
3
  import publicAPI from './public-api.js'
3
4
  import { FLOAT32S_PER_SPRITE } from './constants.js'
@@ -15,7 +16,7 @@ const _tmpVec3 = vec3.create(0, 0, 0)
15
16
  export default {
16
17
  type: 'cobalt:primitives',
17
18
  refs: [
18
- { name: 'color', type: 'textView', format: 'rgba8unorm', access: 'write' },
19
+ { name: 'color', type: 'textView', format: 'PREFERRED_TEXTURE_VIEW', access: 'write' },
19
20
  ],
20
21
 
21
22
  // cobalt event handling functions
@@ -108,6 +109,7 @@ async function init (cobalt, node) {
108
109
 
109
110
  // Create render pipeline
110
111
  const pipeline = device.createRenderPipeline({
112
+ label: "primitives",
111
113
  layout: pipelineLayout,
112
114
  vertex: {
113
115
  module: shaderModule,
@@ -136,7 +138,7 @@ async function init (cobalt, node) {
136
138
  entryPoint: 'fs_main',
137
139
  targets: [
138
140
  {
139
- format: 'bgra8unorm',
141
+ format: getPreferredFormat(cobalt),
140
142
  blend: {
141
143
  color: {
142
144
  srcFactor: 'src-alpha',
@@ -1,4 +1,4 @@
1
- import * as Cobalt from '../cobalt.js'
1
+ import getPreferredFormat from '../get-preferred-format.js'
2
2
  import sceneCompositeWGSL from './scene-composite.wgsl'
3
3
 
4
4
 
@@ -7,7 +7,7 @@ export default {
7
7
  refs: [
8
8
  { name: 'hdr', type: 'textureView', format: 'rgba16', access: 'read' },
9
9
  { name: 'bloom', type: 'textureView', format: 'rgba16', access: 'read' },
10
- { name: 'combined', type: 'textureView', format: 'rgba8unorm', access: 'write' },
10
+ { name: 'combined', type: 'textureView', format: 'PREFERRED_TEXTURE_FORMAT', access: 'write' },
11
11
  ],
12
12
  // @params Object cobalt renderer world object
13
13
  // @params Object options optional data passed when initing this node
@@ -38,7 +38,7 @@ function init (cobalt, node) {
38
38
  const { options, refs } = node
39
39
 
40
40
  const { device } = cobalt
41
- const format = Cobalt.getPreferredFormat(cobalt) // bgra8unorm
41
+ const format = getPreferredFormat(cobalt) // bgra8unorm or bgra8unorm-srgb usually
42
42
 
43
43
  const bloom_intensity = options.bloom_intensity ?? 40.0
44
44
  const bloom_combine_constant = options.bloom_combine_constant ?? 0.68
@@ -55,6 +55,7 @@ function init (cobalt, node) {
55
55
  params_buf.unmap()
56
56
 
57
57
  const pipeline = device.createRenderPipeline({
58
+ label: 'scenecomposite',
58
59
  layout: 'auto',
59
60
  vertex: {
60
61
  module: device.createShaderModule({
@@ -113,7 +113,7 @@ async function init (cobalt, node) {
113
113
  })
114
114
 
115
115
  const pipeline = device.createRenderPipeline({
116
- label: 'sprite',
116
+ label: 'spritesheet',
117
117
  vertex: {
118
118
  module: device.createShaderModule({
119
119
  code: spriteWGSL
package/src/tile/atlas.js CHANGED
@@ -111,7 +111,7 @@ async function init (cobalt, nodeData) {
111
111
  })
112
112
 
113
113
  const pipeline = device.createRenderPipeline({
114
- label: 'tile',
114
+ label: 'tileatlas',
115
115
  vertex: {
116
116
  module: device.createShaderModule({
117
117
  code: tileWGSL