@footgun/cobalt 0.5.1 → 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/CHANGELOG.md +4 -0
- package/bundle.js +14486 -16
- package/esbuild.js +1 -1
- package/examples/02-sprites/index.html +1 -1
- package/examples/03-tiles/index.html +1 -1
- package/examples/05-bloom/index.html +1 -1
- package/examples/06-displacement/index.html +1 -1
- package/examples/08-light/index.html +1 -1
- package/examples/09-sdl-polar-meters/package.json +1 -1
- package/package.json +1 -1
- package/src/cobalt.js +0 -8
- package/src/displacement/displacement.js +2 -1
- package/src/fb-blit/fb-blit.js +5 -4
- package/src/fb-texture/fb-texture.js +5 -2
- package/src/get-preferred-format.js +7 -0
- package/src/overlay/overlay.js +2 -1
- package/src/primitives/primitives.js +3 -2
- package/src/scene-composite/scene-composite.js +3 -3
package/esbuild.js
CHANGED
|
@@ -159,7 +159,7 @@ async function main () {
|
|
|
159
159
|
refs: { },
|
|
160
160
|
options: {
|
|
161
161
|
label: 'bloom + hdr compositing',
|
|
162
|
-
format: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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,
|
package/package.json
CHANGED
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:
|
|
106
|
+
targetFormat: getPreferredFormat(cobalt),
|
|
106
107
|
|
|
107
108
|
colorTextureView: node.refs.color.data.view,
|
|
108
109
|
noiseMapTextureView: node.refs.map.view,
|
package/src/fb-blit/fb-blit.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import blitWGSL
|
|
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: '
|
|
10
|
-
{ name: 'out', type: 'cobaltTexture', format: '
|
|
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:
|
|
91
|
+
format: getPreferredFormat(cobalt),
|
|
91
92
|
blend: {
|
|
92
93
|
color: {
|
|
93
94
|
srcFactor: 'src-alpha',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import createTexture
|
|
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
|
-
|
|
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
|
+
}
|
package/src/overlay/overlay.js
CHANGED
|
@@ -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'
|
|
@@ -159,7 +160,7 @@ async function init (cobalt, nodeData) {
|
|
|
159
160
|
targets: [
|
|
160
161
|
// color
|
|
161
162
|
{
|
|
162
|
-
format:
|
|
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: '
|
|
19
|
+
{ name: 'color', type: 'textView', format: 'PREFERRED_TEXTURE_VIEW', access: 'write' },
|
|
19
20
|
],
|
|
20
21
|
|
|
21
22
|
// cobalt event handling functions
|
|
@@ -137,7 +138,7 @@ async function init (cobalt, node) {
|
|
|
137
138
|
entryPoint: 'fs_main',
|
|
138
139
|
targets: [
|
|
139
140
|
{
|
|
140
|
-
format:
|
|
141
|
+
format: getPreferredFormat(cobalt),
|
|
141
142
|
blend: {
|
|
142
143
|
color: {
|
|
143
144
|
srcFactor: 'src-alpha',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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: '
|
|
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 =
|
|
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
|