@thi.ng/webgl-shadertoy 1.0.50 → 1.1.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 +10 -1
- package/api.d.ts +26 -1
- package/package.json +5 -5
- package/shadertoy.d.ts +13 -1
- package/shadertoy.js +88 -85
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-
|
|
3
|
+
- **Last updated**: 2025-10-07T11:51:57Z
|
|
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.
|
|
@@ -11,6 +11,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
11
11
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
12
12
|
and/or version bumps of transitive dependencies.
|
|
13
13
|
|
|
14
|
+
## [1.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl-shadertoy@1.1.0) (2025-10-07)
|
|
15
|
+
|
|
16
|
+
#### 🚀 Features
|
|
17
|
+
|
|
18
|
+
- refactor/update types & impl ([4e9e929](https://github.com/thi-ng/umbrella/commit/4e9e929))
|
|
19
|
+
- rename `ShaderToy` interface => `IShaderToy`
|
|
20
|
+
- update impl to use proper class `ShaderToy`, thus allowing
|
|
21
|
+
custom extensions to update loop etc.
|
|
22
|
+
|
|
14
23
|
### [0.4.115](https://github.com/thi-ng/umbrella/tree/@thi.ng/webgl-shadertoy@0.4.115) (2024-02-06)
|
|
15
24
|
|
|
16
25
|
#### ♻️ Refactoring
|
package/api.d.ts
CHANGED
|
@@ -30,11 +30,36 @@ export interface ShaderToyOpts<U extends ShaderToyUniforms> {
|
|
|
30
30
|
*/
|
|
31
31
|
opts?: Partial<DefShaderOpts>;
|
|
32
32
|
}
|
|
33
|
-
export interface
|
|
33
|
+
export interface IShaderToy<U extends ShaderToyUniforms> {
|
|
34
|
+
/**
|
|
35
|
+
* Starts automatic update/render loop, driven by `requestAnimationFrame()`.
|
|
36
|
+
* Alternatively, use {@link IShaderToy.update} directly to update/draw a
|
|
37
|
+
* single frame.
|
|
38
|
+
*/
|
|
34
39
|
start(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Stops automatic update/render loop.
|
|
42
|
+
*/
|
|
35
43
|
stop(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Updates and renders a single frame. The given `time` value will be stored
|
|
46
|
+
* in the eponymous shader uniform.
|
|
47
|
+
*
|
|
48
|
+
* @param time
|
|
49
|
+
*/
|
|
36
50
|
update(time?: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Recompiles shader using new given shader `main` function and options.
|
|
53
|
+
* Updates {@link IShaderToy.model} spec.
|
|
54
|
+
*
|
|
55
|
+
* @param main
|
|
56
|
+
* @param opts
|
|
57
|
+
*/
|
|
37
58
|
recompile(main: MainImageFn<U>, opts?: Partial<DefShaderOpts>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Generated thi.ng/webgl model spec (full-canvas rect), incl. exposed
|
|
61
|
+
* uniforms and compiled shader.
|
|
62
|
+
*/
|
|
38
63
|
model: ModelSpec;
|
|
39
64
|
}
|
|
40
65
|
//# sourceMappingURL=api.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/webgl-shadertoy",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@thi.ng/api": "^8.12.2",
|
|
43
|
-
"@thi.ng/shader-ast": "^1.1.
|
|
44
|
-
"@thi.ng/shader-ast-glsl": "^1.0.
|
|
45
|
-
"@thi.ng/webgl": "^6.9.
|
|
43
|
+
"@thi.ng/shader-ast": "^1.1.23",
|
|
44
|
+
"@thi.ng/shader-ast-glsl": "^1.0.42",
|
|
45
|
+
"@thi.ng/webgl": "^6.9.79"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"esbuild": "^0.25.9",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"status": "alpha",
|
|
92
92
|
"year": 2019
|
|
93
93
|
},
|
|
94
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "fbf4b46ba8a5ecff8c5423f4c2d158d208d20fc8\n"
|
|
95
95
|
}
|
package/shadertoy.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DefShaderOpts, ModelSpec } from "@thi.ng/webgl";
|
|
2
|
+
import type { IShaderToy, MainImageFn, ShaderToyOpts, ShaderToyUniforms } from "./api.js";
|
|
3
|
+
export declare class ShaderToy<U extends ShaderToyUniforms> implements IShaderToy<U> {
|
|
4
|
+
opts: ShaderToyOpts<U>;
|
|
5
|
+
model: ModelSpec;
|
|
6
|
+
t0: number;
|
|
7
|
+
active: boolean;
|
|
8
|
+
constructor(opts: ShaderToyOpts<U>);
|
|
9
|
+
start(): void;
|
|
10
|
+
stop(): void;
|
|
11
|
+
update(time: number): void;
|
|
12
|
+
recompile(main: MainImageFn<U>, shaderOpts?: Partial<DefShaderOpts>): void;
|
|
13
|
+
}
|
|
2
14
|
export declare const shaderToy: <U extends ShaderToyUniforms>(opts: ShaderToyOpts<U>) => ShaderToy<U>;
|
|
3
15
|
//# sourceMappingURL=shadertoy.d.ts.map
|
package/shadertoy.js
CHANGED
|
@@ -6,98 +6,101 @@ import { compileModel } from "@thi.ng/webgl/buffer";
|
|
|
6
6
|
import { draw } from "@thi.ng/webgl/draw";
|
|
7
7
|
import { defQuadModel } from "@thi.ng/webgl/geo/quad";
|
|
8
8
|
import { defShader } from "@thi.ng/webgl/shader";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
class ShaderToy {
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
this.opts = opts;
|
|
12
|
+
this.model = defQuadModel({ uv: false });
|
|
13
|
+
this.model.textures = opts.textures || [];
|
|
14
|
+
compileModel(opts.gl, this.model);
|
|
15
|
+
opts.canvas.addEventListener("mousemove", (e) => {
|
|
16
|
+
const rect = opts.canvas.getBoundingClientRect();
|
|
17
|
+
const dpr = window.devicePixelRatio;
|
|
18
|
+
this.model.uniforms.mouse = [
|
|
19
|
+
(e.clientX - rect.left) * dpr,
|
|
20
|
+
(rect.height - (e.clientY - rect.top)) * dpr
|
|
21
|
+
];
|
|
22
|
+
});
|
|
23
|
+
opts.canvas.addEventListener("mousedown", (e) => {
|
|
24
|
+
this.model.uniforms.mouseButtons = e.buttons;
|
|
25
|
+
});
|
|
26
|
+
opts.canvas.addEventListener("mouseup", (e) => {
|
|
27
|
+
this.model.uniforms.mouseButtons = e.buttons;
|
|
28
|
+
});
|
|
29
|
+
this.recompile(opts.main);
|
|
30
|
+
}
|
|
31
|
+
model;
|
|
32
|
+
t0;
|
|
33
|
+
active = false;
|
|
34
|
+
start() {
|
|
35
|
+
this.t0 = Date.now();
|
|
36
|
+
this.active = true;
|
|
37
|
+
const update = () => {
|
|
38
|
+
this.update((Date.now() - this.t0) * 1e-3);
|
|
39
|
+
this.active && requestAnimationFrame(update);
|
|
40
|
+
};
|
|
41
|
+
requestAnimationFrame(update);
|
|
42
|
+
}
|
|
43
|
+
stop() {
|
|
44
|
+
this.active = false;
|
|
45
|
+
}
|
|
46
|
+
update(time) {
|
|
47
|
+
const {
|
|
48
|
+
opts: { gl },
|
|
49
|
+
model
|
|
50
|
+
} = this;
|
|
31
51
|
const w = gl.drawingBufferWidth;
|
|
32
52
|
const h = gl.drawingBufferHeight;
|
|
33
53
|
model.uniforms.time = time;
|
|
34
54
|
model.uniforms.resolution = [w, h];
|
|
35
55
|
gl.viewport(0, 0, w, h);
|
|
36
56
|
draw(model);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
fs: (gl2, unis, _, outputs) => [
|
|
70
|
-
defMain(() => [
|
|
71
|
-
assign(
|
|
72
|
-
outputs.fragColor,
|
|
73
|
-
defn(
|
|
74
|
-
V4,
|
|
75
|
-
"mainImage",
|
|
76
|
-
[],
|
|
77
|
-
() => main(gl2, unis)
|
|
78
|
-
)()
|
|
79
|
-
)
|
|
80
|
-
])
|
|
81
|
-
],
|
|
82
|
-
attribs: {
|
|
83
|
-
position: V2
|
|
84
|
-
},
|
|
85
|
-
uniforms: {
|
|
86
|
-
resolution: V2,
|
|
87
|
-
mouse: [V2, [0, 0]],
|
|
88
|
-
mouseButtons: [I, 0],
|
|
89
|
-
time: F,
|
|
90
|
-
...opts.uniforms
|
|
91
|
-
}
|
|
57
|
+
}
|
|
58
|
+
recompile(main, shaderOpts) {
|
|
59
|
+
const { opts, model } = this;
|
|
60
|
+
if (model.shader) {
|
|
61
|
+
model.shader.release();
|
|
62
|
+
}
|
|
63
|
+
model.shader = defShader(
|
|
64
|
+
opts.gl,
|
|
65
|
+
{
|
|
66
|
+
vs: (gl, _, ins) => [
|
|
67
|
+
defMain(() => [
|
|
68
|
+
assign(
|
|
69
|
+
gl.gl_Position,
|
|
70
|
+
vec4(ins.position, FLOAT0, FLOAT1)
|
|
71
|
+
)
|
|
72
|
+
])
|
|
73
|
+
],
|
|
74
|
+
fs: (gl, unis, _, outputs) => [
|
|
75
|
+
defMain(() => [
|
|
76
|
+
assign(
|
|
77
|
+
outputs.fragColor,
|
|
78
|
+
defn(
|
|
79
|
+
V4,
|
|
80
|
+
"mainImage",
|
|
81
|
+
[],
|
|
82
|
+
() => main(gl, unis)
|
|
83
|
+
)()
|
|
84
|
+
)
|
|
85
|
+
])
|
|
86
|
+
],
|
|
87
|
+
attribs: {
|
|
88
|
+
position: V2
|
|
92
89
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
90
|
+
uniforms: {
|
|
91
|
+
resolution: V2,
|
|
92
|
+
mouse: [V2, [0, 0]],
|
|
93
|
+
mouseButtons: [I, 0],
|
|
94
|
+
time: F,
|
|
95
|
+
...opts.uniforms
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
shaderOpts || opts.opts
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const shaderToy = (opts) => new ShaderToy(opts);
|
|
101
103
|
export {
|
|
104
|
+
ShaderToy,
|
|
102
105
|
shaderToy
|
|
103
106
|
};
|