fragmentcolor 0.10.6 → 0.10.7

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/README.md CHANGED
@@ -1,198 +1,125 @@
1
- # FragmentColor
1
+ # FragmentColor for JavaScript (WASM)
2
2
 
3
- [FragmentColor](https://fragmentcolor.org) is a cross-platform GPU programming library implemented in Rust and [wgpu](https://wgpu.rs).
3
+ [FragmentColor](https://fragmentcolor.org) is a cross‑platform GPU programming library implemented in Rust and wgpu, compiled to WebAssembly for JavaScript.
4
4
 
5
- It has bindings for **Javascript**, **Python**, **Swift**, and **Kotlin**
6
- and targets each platform's native graphics API: **Vulkan**, **Metal**, **DirectX**, **OpenGL**, **WebGL**, or **WebGPU**.\
7
- See [Platform Support](#platform-support) for details.
5
+ This README is specific to the npm package. For Rust usage, see the repository README.md. For Python, see README_PY.md.
8
6
 
9
- The API encourages a simple shader composition workflow. You can use **WGSL** or **GLSL** shaders
10
- for visual consistency across platforms, while avoiding the verbosity of modern GPU APIs.
7
+ - Documentation: https://fragmentcolor.org/welcome
8
+ - API Reference: https://fragmentcolor.org/api
11
9
 
12
- **We strive to remove the complexity without sacrificing control**. Because of the composition primitives, you can
13
- build a highly customized render graph with multiple render passes.
14
-
15
- Check the [Documentation](/welcome) and the [API Reference](/api) for more information.
16
-
17
- > ⚠️ **This library is its early days of development**
18
- >
19
- > The API is subject to frequent changes in minor versions. Documentation is not always in sync.
20
- >
21
- > Check the [Roadmap](/ROADMAP.md) and [Changelog](/CHANGELOG.md) on [GitHub](https://github.com/vista-art/fragmentcolor) to stay tuned on the latest updates.
22
-
23
- ## Example
24
-
25
- From a given shader source, our library will:
26
-
27
- - parse the shader
28
- - compile/reload it at runtime
29
- - create the Uniform bindings in your platform's native graphics API
30
- - expose them with the dot notation.
31
-
32
- ### Example usage (Python)
10
+ ## Install
33
11
 
34
12
  ```bash
35
- pip install fragmentcolor glfw rendercanvas
36
- ```
37
-
38
- ```python
39
- from fragmentcolor import FragmentColor as fc, Renderer, Shader, Pass, Frame
40
- from rendercanvas.auto import RenderCanvas, loop
41
-
42
- # Initializes a renderer and a target compatible with the given canvas
43
- canvas = RenderCanvas(size=(800, 600))
44
- renderer = Renderer()
45
- target = renderer.create_target(canvas)
46
-
47
- # You can pass the shader as a source string, file path, or URL:
48
- circle = Shader("./path/to/circle.wgsl")
49
- triangle = Shader("https://fragmentcolor.org/shaders/triangle.wgsl")
50
- my_shader = Shader("""
51
- struct VertexOutput {
52
- @builtin(position) coords: vec4<f32>,
53
- }
54
-
55
- struct MyStruct {
56
- my_field: vec3<f32>,
57
- }
58
-
59
- @group(0) @binding(0)
60
- var<uniform> my_struct: MyStruct;
61
-
62
- @group(0) @binding(1)
63
- var<uniform> my_vec2: vec2<f32>;
64
-
65
- @vertex
66
- fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
67
- const vertices = array(
68
- vec2( -1., -1.),
69
- vec2( 3., -1.),
70
- vec2( -1., 3.)
71
- );
72
- return VertexOutput(vec4<f32>(vertices[in_vertex_index], 0.0, 1.0));
73
- }
74
-
75
- @fragment
76
- fn fs_main() -> @location(0) vec4<f32> {
77
- return vec4<f32>(my_struct.my_field, 1.0);
78
- }
79
- """)
80
-
81
- # The library binds and updates the uniforms automatically
82
- my_shader.set("my_struct.my_field", [0.1, 0.8, 0.9])
83
- my_shader.set("my_vec2", [1.0, 1.0])
84
-
85
- # One shader is all you need to render
86
- renderer.render(shader, target)
87
-
88
- # But you can also combine multiple shaders in a render Pass
89
- rpass = Pass("single pass")
90
- rpass.add_shader(circle)
91
- rpass.add_shader(triangle)
92
- rpass.add_shader(my_shader)
93
- renderer.render(rpass, target)
94
-
95
- # Finally, you can combine multiple passes in a Frame
96
- frame = Frame()
97
- frame.add_pass(rpass)
98
- frame.add_pass(Pass("GUI pass"))
99
- renderer.render(frame, target)
100
-
101
- # To animate, simply update the uniforms in a loop
102
- @canvas.request_draw
103
- def animate():
104
- circle.set("position", [0.0, 0.0])
105
- renderer.render(frame, target)
106
-
107
- loop.run()
13
+ npm install fragmentcolor
14
+ # or
15
+ pnpm add fragmentcolor
16
+ # or
17
+ yarn add fragmentcolor
108
18
  ```
109
19
 
110
- ### Example usage (Javascript)
111
-
112
- ```javascript
113
- import { Shader, Renderer } from "fragmentcolor";
114
-
115
- const canvas = document.getElementById("my-canvas");
116
- const renderer = new Renderer();
117
- const target = renderer.init(canvas);
118
-
119
- const shader = new Shader("https://fragmentcolor.org/shaders/circle.wgsl");
120
- shader.set("resolution", [canvas.width, canvas.heigth]);
121
- shader.set("circle.radius", 0.05);
122
- shader.set("circle.color", [1.0, 0.0, 0.0, 0.8]);
123
-
124
- const renderer = new Renderer();
125
-
126
- function animate() {
127
- shader.set("circle.position", [mouseX, mouseY]);
128
- renderer.render(shader, target);
129
-
130
- requestAnimationFrame(animate);
20
+ ## Quick start
21
+
22
+ ```js
23
+ import init, { Renderer, Shader, Pass, Frame } from "fragmentcolor";
24
+
25
+ async function start() {
26
+ // Initializes the WASM module
27
+ await init();
28
+
29
+ // Initializes a renderer and a target compatible with the given canvas
30
+ const canvas = document.getElementById("my-canvas");
31
+ const renderer = new Renderer();
32
+ const target = await renderer.createTarget(canvas);
33
+
34
+ // You can pass the shader as a source string, file path, or URL:
35
+ const circle = new Shader("./path/to/circle.wgsl");
36
+ const triangle = new Shader("https://fragmentcolor.org/shaders/triangle.wgsl");
37
+ const shader = new Shader(`
38
+ struct VertexOutput {
39
+ @builtin(position) coords: vec4<f32>,
40
+ }
41
+
42
+ struct MyStruct {
43
+ my_field: vec3<f32>,
44
+ }
45
+
46
+ @group(0) @binding(0)
47
+ var<uniform> my_struct: MyStruct;
48
+
49
+ @group(0) @binding(1)
50
+ var<uniform> my_vec2: vec2<f32>;
51
+
52
+ @vertex
53
+ fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput {
54
+ const vertices = array(
55
+ vec2( -1., -1.),
56
+ vec2( 3., -1.),
57
+ vec2( -1., 3.)
58
+ );
59
+ return VertexOutput(vec4<f32>(vertices[in_vertex_index], 0.0, 1.0));
60
+ }
61
+
62
+ @fragment
63
+ fn fs_main() -> @location(0) vec4<f32> {
64
+ return vec4<f32>(my_struct.my_field, 1.0);
65
+ }
66
+ `);
67
+
68
+ // The library binds and updates the uniforms automatically
69
+ shader.set("my_struct.my_field", [0.1, 0.8, 0.9]);
70
+ shader.set("my_vec2", [1.0, 1.0]);
71
+
72
+ // One shader is all you need to render
73
+ renderer.render(circle, target);
74
+
75
+ // But you can also combine multiple shaders in a render Pass
76
+ const rpass = new Pass("single pass");
77
+ rpass.addShader(circle);
78
+ rpass.addShader(triangle);
79
+ rpass.addShader(shader);
80
+ renderer.render(rpass, target);
81
+
82
+ // Finally, you can combine multiple passes in a Frame
83
+ const frame = new Frame();
84
+ frame.addPass(rpass);
85
+ frame.addPass(new Pass("GUI pass"));
86
+ renderer.render(frame, target);
87
+
88
+ // To animate, simply update the uniforms in a loop
89
+ function animate() {
90
+ circle.set("position", [0.0, 0.0]);
91
+ renderer.render(frame, target);
92
+ requestAnimationFrame(animate);
93
+ }
94
+ animate();
131
95
  }
132
- animate();
133
- ```
134
96
 
135
- ## Limitations
136
-
137
- - The current version of this library **always use a fullscreen triangle for every shader**. Support for custom geometries and instanced rendering is planned.
138
-
139
- - In Python, we depend on [rendercanvas](https://github.com/pygfx/rendercanvas) adapter to support multiple window libraries. Direct support for other libraries is planned.
140
-
141
- - Textures and Samplers are currently not supported, but are also planned.
142
-
143
- - Javascript, Swift, and Kotlin are currently WIP.
144
-
145
- ## Running this project
146
-
147
- ### Target: Desktop (Rust library)
148
-
149
- For Rust, check the examples folder and run them with:
150
-
151
- ```bash
152
- cargo run --example circle
153
- cargo run --example triangle
154
- cargo run --example multiobject
155
- cargo run --example multipass
156
- ```
157
-
158
- ### Target: Desktop (Python module)
159
-
160
- **NOTE:** Pip Package currently only available for MacOS (Apple Silicon)
161
-
162
- ```bash
163
- pip install fragmentcolor glfw rendercanvas
97
+ start();
164
98
  ```
165
99
 
166
- Alternativaly, You can build it locally with [maturin](https://www.maturin.rs/installation.html):
100
+ ## Web (WASM) development
167
101
 
168
102
  ```bash
169
- pipx install maturin
170
- maturin develop
171
- pip install glfw rendercanvas
172
- ```
103
+ # Build WASM package (wasm-pack target web) and sync into local JS examples
104
+ ./build_web # add --debug for a debug build
173
105
 
174
- The built library is located in `platforms/python/fragmentcolor`
106
+ # Run JS demos (Vite dev server) and open browser
107
+ ./run_web repl # or: ./run_web multipass | ./run_web headless
175
108
 
176
- ```bash
177
- cd platforms/python/fragmentcolor
178
- python3 main.py
109
+ # Manual alternative
110
+ pnpm --dir examples/javascript install
111
+ pnpm --dir examples/javascript dev
179
112
  ```
180
113
 
181
- ### Target: Web browser (WASM module)
182
-
183
- - TBD
184
-
185
- ### Target: iOS (Swift library)
114
+ ## Documentation & website
186
115
 
187
- - TBD
188
-
189
- ### Target: Android (Kotlin library)
190
-
191
- - TBD
116
+ - Docs source of truth lives in docs/api and is referenced from code via `#[lsp_doc]`.
117
+ - Examples on method pages are sliced from the healthcheck scripts; no filesystem reads in docs.
118
+ - Doc examples follow async + pollster patterns on the Rust side and are converted to JavaScript automatically.
192
119
 
193
120
  ## Platform support
194
121
 
195
- Platform support is the same as upstream [wgpu](https://github.com/gfx-rs/wgpu):
122
+ Platform support is aligned with upstream wgpu:
196
123
 
197
124
  | API | Windows | Linux/Android | macOS/iOS | Web (wasm) |
198
125
  | ------ | ------------ | --------------- | --------- | ----------- |
@@ -203,6 +130,14 @@ Platform support is the same as upstream [wgpu](https://github.com/gfx-rs/wgpu):
203
130
  | WebGPU | | | | ✅ |
204
131
 
205
132
  ✅ = First Class Support
206
- 🆗 = Downlevel/Best Effort Support
207
- 📐 = Requires the [ANGLE](http://angleproject.org/) translation layer (GL ES 3.0 only)
208
- 🌋 = Requires the [MoltenVK](https://vulkan.lunarg.com/sdk/home#mac) translation layer
133
+ 🆗 = Downlevel/Best Effort Support
134
+ 📐 = Requires the ANGLE translation layer (GL ES 3.0 only)
135
+ 🌋 = Requires the MoltenVK translation layer
136
+
137
+ ## Limitations (planned features)
138
+
139
+ - Swift & Kotlin bindings are not supported yet, but planned.
140
+
141
+ ---
142
+
143
+ Note on generation: this README_JS.md is generated from this template (README_JS.tpl.md) and the repository README.md examples by the build script. Do not edit the generated README_JS.md directly.