@margoengine/dof 0.1.0 → 1.0.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/dist/shaders.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  export declare const groupMax = "var<workgroup> lanes:array<f32,64>;\nvar<workgroup> rows:array<f32,8>;\nfn groupMax(v:f32,local:u32)->f32 {\n lanes[local]=v;workgroupBarrier();\n if(local<8u){var m=lanes[local*8u];for(var i=1u;i<8u;i++){m=max(m,lanes[local*8u+i]);}rows[local]=m;}\n workgroupBarrier();\n var m=rows[0];for(var i=1u;i<8u;i++){m=max(m,rows[i]);}return m;\n}";
2
2
  export declare const cocShader = "struct Params {lens:vec4f,frame:vec4f,ortho:vec4f}\n@group(0) @binding(0) var<uniform> p:Params;\n@group(0) @binding(1) var depth:texture_depth_2d;\n@group(0) @binding(2) var coc:texture_storage_2d<rg32float,write>;\n@group(0) @binding(3) var tiles:texture_storage_2d<r32float,write>;\nvar<workgroup> lanes:array<f32,64>;\nvar<workgroup> rows:array<f32,8>;\nfn groupMax(v:f32,local:u32)->f32 {\n lanes[local]=v;workgroupBarrier();\n if(local<8u){var m=lanes[local*8u];for(var i=1u;i<8u;i++){m=max(m,lanes[local*8u+i]);}rows[local]=m;}\n workgroupBarrier();\n var m=rows[0];for(var i=1u;i<8u;i++){m=max(m,rows[i]);}return m;\n}\n@compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) id:vec3u,@builtin(workgroup_id) tile:vec3u,@builtin(local_invocation_index) local:u32) {\n var near=0.0;\n if(all(id.xy<textureDimensions(coc))){\n let d=textureLoad(depth,vec2i(id.xy),0);\n let ortho=p.ortho.x>0.5;\n let z=select(p.frame.x*p.frame.y/(p.frame.x+d*(p.frame.y-p.frame.x)),mix(p.frame.y,p.frame.x,d),ortho);\n let radius=clamp(p.frame.z*select(1.0-p.lens.x/z,(z-p.lens.x)/p.lens.x,ortho),-p.lens.w,p.lens.w)*p.frame.w;\n textureStore(coc,vec2i(id.xy),vec4f(radius,z,0,0));near=-radius;\n }\n let m=groupMax(near,local);\n if(local==0u){textureStore(tiles,vec2i(tile.xy),vec4f(m,0,0,0));}\n}";
3
3
  export declare const coarseShader: string;
4
- export declare const NEAR_LEVELS = 4;
4
+ export declare const NEAR_LEVELS = 6;
5
+ /** The largest disk radius in pixels the near chain's levels serve: a scaled cap stops here. */
6
+ export declare const DOF_MAX_DISK = 128;
7
+ /** The view height in pixels at which `DOFOptions.maxRadius` holds unless `referenceHeight` says otherwise. */
8
+ export declare const DOF_REFERENCE_HEIGHT = 1080;
9
+ /**
10
+ * The disk cap in pixels for a view `height` pixels tall: `maxRadius` at `reference`, scaled by the height so it is one
11
+ * share of the frame at any canvas size, and at most DOF_MAX_DISK.
12
+ */
13
+ export declare function capRadius(maxRadius: number, height: number, reference: number): number;
14
+ /**
15
+ * How many near-chain levels above level 0 a gather capped at `cap` pixels reads: the bokeh kernel's ceil(nearLod) for
16
+ * a round disk (the widest tap spacing; a polygon's is narrower), never under the three it always had, at most five.
17
+ */
18
+ export declare function nearLevelsFor(cap: number): number;
5
19
  export declare const nearShader = "struct Params {lens:vec4f,frame:vec4f,ortho:vec4f}\n@group(0) @binding(0) var<uniform> p:Params;\n@group(0) @binding(1) var scene:texture_2d<f32>;\n@group(0) @binding(2) var coc:texture_2d<f32>;\n@group(0) @binding(3) var nearTaps:texture_storage_2d<rgba16float,write>;\n@group(0) @binding(4) var nearShapes:texture_storage_2d<rgba16float,write>;\n@group(0) @binding(5) var nearScene:texture_storage_2d<rgba16float,write>;\n@compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) id:vec3u) {\n if(any(id.xy>=textureDimensions(nearTaps))||p.frame.w==0.0){return;}\n let at=vec2i(id.xy);let s=textureLoad(coc,at,0).xy;let color=textureLoad(scene,at,0).rgb;\n let g=select(0.0,1.0/max(s.x*s.x,1.0),s.x< -0.5);\n textureStore(nearTaps,at,vec4f(color*g,g));\n textureStore(nearShapes,at,vec4f(-s.x*g,s.y*g,0,0));\n textureStore(nearScene,at,vec4f(color,1));\n}";
6
20
  export declare const nearDownShader = "@group(0) @binding(0) var tapsBelow:texture_2d<f32>;\n@group(0) @binding(1) var shapesBelow:texture_2d<f32>;\n@group(0) @binding(2) var sceneBelow:texture_2d<f32>;\n@group(0) @binding(3) var nearTaps:texture_storage_2d<rgba16float,write>;\n@group(0) @binding(4) var nearShapes:texture_storage_2d<rgba16float,write>;\n@group(0) @binding(5) var nearScene:texture_storage_2d<rgba16float,write>;\n@compute @workgroup_size(8,8) fn main(@builtin(global_invocation_id) id:vec3u) {\n if(any(id.xy>=textureDimensions(nearTaps))){return;}\n let last=vec2i(textureDimensions(tapsBelow))-1;var taps=vec4f(0);var shapes=vec4f(0);var plain=vec4f(0);\n for(var k=0;k<4;k++){\n let at=min(vec2i(id.xy)*2+vec2i(k%2,k/2),last);\n taps+=textureLoad(tapsBelow,at,0);shapes+=textureLoad(shapesBelow,at,0);plain+=textureLoad(sceneBelow,at,0);\n }\n textureStore(nearTaps,vec2i(id.xy),taps*0.25);\n textureStore(nearShapes,vec2i(id.xy),shapes*0.25);\n textureStore(nearScene,vec2i(id.xy),plain*0.25);\n}";
7
21
  export declare const bokehShader: string;
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@margoengine/dof",
3
- "version": "0.1.0",
4
- "description": "Optional two-pass WebGPU depth of field with circular bokeh.",
5
- "keywords": [
6
- "margoengine",
7
- "webgpu",
8
- "3d",
9
- "dof"
10
- ],
11
- "homepage": "https://margoengine.com",
12
- "bugs": {
13
- "url": "https://github.com/scottcampbelldata/margoengine/issues"
14
- },
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/scottcampbelldata/margoengine.git",
18
- "directory": "packages/dof"
19
- },
20
- "license": "Apache-2.0",
21
- "author": "Scott Campbell",
22
- "type": "module",
23
- "sideEffects": false,
24
- "exports": {
25
- ".": {
26
- "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js"
28
- },
29
- "./lens": {
30
- "types": "./dist/lens.d.ts",
31
- "import": "./dist/lens.js"
32
- },
33
- "./autofocus": {
34
- "types": "./dist/autofocus.d.ts",
35
- "import": "./dist/autofocus.js"
36
- }
37
- },
38
- "files": [
39
- "dist",
40
- "LICENSE",
41
- "NOTICE"
42
- ],
43
- "publishConfig": {
44
- "access": "public"
45
- },
46
- "dependencies": {
47
- "@margoengine/math": "^0.1.0"
48
- },
49
- "peerDependencies": {
50
- "@margoengine/core": "^0.1.0"
51
- },
52
- "scripts": {
53
- "build": "node ../../scripts/build-postfx.js dof",
54
- "prepack": "npm run build",
55
- "test": "node --test tests/*.test.js ../../examples/package-benchmarks/proofs/package-guard.mjs",
56
- "dev": "vite --config vite.config.js --open /examples/index.html",
57
- "build:demo": "vite build --config vite.config.js",
58
- "test:gpu": "cd ../.. && node packages/dof/tests/gpu/lens-check.mjs && node packages/dof/tests/gpu/compat-check.mjs",
59
- "test:gpu:tiers": "cd ../.. && node packages/webgl2-compat/test/tier-packages-browser.mjs --only=dof%20HDR",
60
- "test:gpu:restore-tier": "cd ../.. && node packages/dof/tests/gpu/restore-tier-check.mjs",
61
- "test:gpu:postfx": "cd ../.. && npm run modern:test:postfx:browser"
62
- }
63
- }
1
+ {
2
+ "name": "@margoengine/dof",
3
+ "version": "1.0.0",
4
+ "description": "Optional two-pass WebGPU depth of field with circular bokeh.",
5
+ "keywords": [
6
+ "margoengine",
7
+ "webgpu",
8
+ "3d",
9
+ "dof"
10
+ ],
11
+ "homepage": "https://margoengine.com",
12
+ "bugs": {
13
+ "url": "https://github.com/scottcampbelldata/margoengine/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/scottcampbelldata/margoengine.git",
18
+ "directory": "packages/dof"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "author": "Scott Campbell",
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js"
28
+ },
29
+ "./lens": {
30
+ "types": "./dist/lens.d.ts",
31
+ "import": "./dist/lens.js"
32
+ },
33
+ "./autofocus": {
34
+ "types": "./dist/autofocus.d.ts",
35
+ "import": "./dist/autofocus.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "LICENSE",
41
+ "NOTICE"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "dependencies": {
47
+ "@margoengine/math": "^1.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "@margoengine/core": "^1.0.0"
51
+ },
52
+ "scripts": {
53
+ "build": "node ../../scripts/build-postfx.js dof",
54
+ "prepack": "npm run build",
55
+ "test": "node --test tests/*.test.js ../../examples/package-benchmarks/proofs/package-guard.mjs",
56
+ "dev": "vite --config vite.config.js --open /examples/index.html",
57
+ "build:demo": "vite build --config vite.config.js",
58
+ "test:gpu": "cd ../.. && node packages/dof/tests/gpu/lens-check.mjs && node packages/dof/tests/gpu/compat-check.mjs && node packages/dof/tests/gpu/alpha-check.mjs && node packages/dof/tests/gpu/alpha-check.mjs --compat",
59
+ "test:gpu:tiers": "cd ../.. && node packages/webgl2-compat/test/tier-packages-browser.mjs --only=dof%20HDR",
60
+ "test:gpu:restore-tier": "cd ../.. && node packages/dof/tests/gpu/restore-tier-check.mjs",
61
+ "test:gpu:postfx": "cd ../.. && npm run modern:test:postfx:browser"
62
+ }
63
+ }