@thi.ng/webgl-shadertoy 0.4.99 → 0.4.101

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-03T12:13:32Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/webgl-shadertoy",
3
- "version": "0.4.99",
3
+ "version": "0.4.101",
4
4
  "description": "Basic WebGL scaffolding for running interactive fragment shaders via @thi.ng/shader-ast",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,15 +35,15 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.10",
37
- "@thi.ng/shader-ast": "^0.12.83",
38
- "@thi.ng/shader-ast-glsl": "^0.4.83",
39
- "@thi.ng/webgl": "^6.6.10"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/shader-ast": "^0.12.85",
40
+ "@thi.ng/shader-ast-glsl": "^0.4.85",
41
+ "@thi.ng/webgl": "^6.6.12"
40
42
  },
41
43
  "devDependencies": {
42
44
  "@microsoft/api-extractor": "^7.38.3",
43
- "@thi.ng/testament": "^0.4.3",
44
45
  "@types/node": "^20.10.2",
46
+ "esbuild": "^0.19.8",
45
47
  "rimraf": "^5.0.5",
46
48
  "tools": "^0.0.1",
47
49
  "typedoc": "^0.25.4",
@@ -89,5 +91,5 @@
89
91
  "status": "alpha",
90
92
  "year": 2019
91
93
  },
92
- "gitHead": "04d1de79f256d7a53c6b5fd157b37f49bc88e11d\n"
94
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
93
95
  }
package/shadertoy.js CHANGED
@@ -5,80 +5,98 @@ import { compileModel } from "@thi.ng/webgl/buffer";
5
5
  import { draw } from "@thi.ng/webgl/draw";
6
6
  import { defQuadModel } from "@thi.ng/webgl/geo/quad";
7
7
  import { defShader } from "@thi.ng/webgl/shader";
8
- export const shaderToy = (opts) => {
9
- const gl = opts.gl;
10
- const model = defQuadModel({ uv: false });
11
- model.textures = opts.textures || [];
12
- compileModel(gl, model);
13
- opts.canvas.addEventListener("mousemove", (e) => {
14
- const rect = opts.canvas.getBoundingClientRect();
15
- const dpr = window.devicePixelRatio;
16
- model.uniforms.mouse = [
17
- (e.clientX - rect.left) * dpr,
18
- (rect.height - (e.clientY - rect.top)) * dpr,
19
- ];
20
- });
21
- opts.canvas.addEventListener("mousedown", (e) => {
22
- model.uniforms.mouseButtons = e.buttons;
23
- });
24
- opts.canvas.addEventListener("mouseup", (e) => {
25
- model.uniforms.mouseButtons = e.buttons;
26
- });
27
- let active;
28
- let t0;
29
- const update = (time) => {
30
- const w = gl.drawingBufferWidth;
31
- const h = gl.drawingBufferHeight;
32
- model.uniforms.time = time;
33
- model.uniforms.resolution = [w, h];
34
- gl.viewport(0, 0, w, h);
35
- draw(model);
36
- };
37
- const updateRAF = () => {
38
- update((Date.now() - t0) * 1e-3);
39
- active && requestAnimationFrame(updateRAF);
40
- };
41
- const instance = {
42
- start() {
43
- t0 = Date.now();
44
- active = true;
45
- requestAnimationFrame(updateRAF);
8
+ const shaderToy = (opts) => {
9
+ const gl = opts.gl;
10
+ const model = defQuadModel({ uv: false });
11
+ model.textures = opts.textures || [];
12
+ compileModel(gl, model);
13
+ opts.canvas.addEventListener("mousemove", (e) => {
14
+ const rect = opts.canvas.getBoundingClientRect();
15
+ const dpr = window.devicePixelRatio;
16
+ model.uniforms.mouse = [
17
+ (e.clientX - rect.left) * dpr,
18
+ (rect.height - (e.clientY - rect.top)) * dpr
19
+ ];
20
+ });
21
+ opts.canvas.addEventListener("mousedown", (e) => {
22
+ model.uniforms.mouseButtons = e.buttons;
23
+ });
24
+ opts.canvas.addEventListener("mouseup", (e) => {
25
+ model.uniforms.mouseButtons = e.buttons;
26
+ });
27
+ let active;
28
+ let t0;
29
+ const update = (time) => {
30
+ const w = gl.drawingBufferWidth;
31
+ const h = gl.drawingBufferHeight;
32
+ model.uniforms.time = time;
33
+ model.uniforms.resolution = [w, h];
34
+ gl.viewport(0, 0, w, h);
35
+ draw(model);
36
+ };
37
+ const updateRAF = () => {
38
+ update((Date.now() - t0) * 1e-3);
39
+ active && requestAnimationFrame(updateRAF);
40
+ };
41
+ const instance = {
42
+ start() {
43
+ t0 = Date.now();
44
+ active = true;
45
+ requestAnimationFrame(updateRAF);
46
+ },
47
+ stop() {
48
+ active = false;
49
+ },
50
+ update(time) {
51
+ update(time);
52
+ },
53
+ recompile(main, shaderOpts) {
54
+ if (model.shader) {
55
+ model.shader.release();
56
+ }
57
+ model.shader = defShader(
58
+ gl,
59
+ {
60
+ vs: (gl2, _, ins) => [
61
+ defMain(() => [
62
+ assign(
63
+ gl2.gl_Position,
64
+ vec4(ins.position, FLOAT0, FLOAT1)
65
+ )
66
+ ])
67
+ ],
68
+ fs: (gl2, unis, _, outputs) => [
69
+ defMain(() => [
70
+ assign(
71
+ outputs.fragColor,
72
+ defn(
73
+ "vec4",
74
+ "mainImage",
75
+ [],
76
+ () => main(gl2, unis)
77
+ )()
78
+ )
79
+ ])
80
+ ],
81
+ attribs: {
82
+ position: "vec2"
83
+ },
84
+ uniforms: {
85
+ resolution: "vec2",
86
+ mouse: ["vec2", [0, 0]],
87
+ mouseButtons: ["int", 0],
88
+ time: "float",
89
+ ...opts.uniforms
90
+ }
46
91
  },
47
- stop() {
48
- active = false;
49
- },
50
- update(time) {
51
- update(time);
52
- },
53
- recompile(main, shaderOpts) {
54
- if (model.shader) {
55
- model.shader.release();
56
- }
57
- model.shader = defShader(gl, {
58
- vs: (gl, _, ins) => [
59
- defMain(() => [
60
- assign(gl.gl_Position, vec4(ins.position, FLOAT0, FLOAT1)),
61
- ]),
62
- ],
63
- fs: (gl, unis, _, outputs) => [
64
- defMain(() => [
65
- assign(outputs.fragColor, defn("vec4", "mainImage", [], () => main(gl, unis))()),
66
- ]),
67
- ],
68
- attribs: {
69
- position: "vec2",
70
- },
71
- uniforms: {
72
- resolution: "vec2",
73
- mouse: ["vec2", [0, 0]],
74
- mouseButtons: ["int", 0],
75
- time: "float",
76
- ...opts.uniforms,
77
- },
78
- }, shaderOpts || opts.opts);
79
- },
80
- model,
81
- };
82
- instance.recompile(opts.main);
83
- return instance;
92
+ shaderOpts || opts.opts
93
+ );
94
+ },
95
+ model
96
+ };
97
+ instance.recompile(opts.main);
98
+ return instance;
99
+ };
100
+ export {
101
+ shaderToy
84
102
  };