Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Multipass shaders (buffer A ...) #30

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
786f8a2
Initial texture channel refactor
Vipitis May 9, 2024
c49f43d
small clarification on .snapshot usage
Vipitis May 11, 2024
5414d0d
keep base channels working
Vipitis May 13, 2024
d4c943a
consider renderpasses in main
Vipitis May 14, 2024
a07c201
add renderpass classe stubs
Vipitis May 17, 2024
5242c70
refactor some code to the channel classes
Vipitis May 17, 2024
e667479
start move to ImagePass for main image code and channels
Vipitis May 18, 2024
451f9f4
start draw_buffer function
Vipitis May 21, 2024
18c0990
split up _prepare_render
Vipitis May 21, 2024
71d97d4
initialize buffers with zero
Vipitis May 21, 2024
f182699
move prepare_render function to passes
Vipitis May 21, 2024
60e8a3a
static buffer pass working?
Vipitis May 21, 2024
e5b67fe
put passes into it's own file
Vipitis May 22, 2024
2bcbac8
naive update textures function
Vipitis May 22, 2024
e10aa81
fix color and orientation
Vipitis May 22, 2024
8529aeb
fix type annotations
Vipitis May 22, 2024
8e2b577
only update dynamic channels
Vipitis May 23, 2024
cfc388f
refactor duplicate code to method
Vipitis May 23, 2024
040d9e9
add row padding, resizing still broken
Vipitis May 23, 2024
57df916
fix detected channels in common
Vipitis May 25, 2024
24b523f
add buffer resizing
Vipitis May 27, 2024
ecc8775
fix channel order
Vipitis May 28, 2024
299e5f7
reuse texture for performance
Vipitis Jun 5, 2024
bdd6d18
fix resize
Vipitis Jun 6, 2024
50515a6
fix vflip buffers
Vipitis Jun 6, 2024
26f7841
cleanup
Vipitis Jun 7, 2024
71ca014
use rgba32float for buffers
Vipitis Jun 7, 2024
682398d
add logic for device features
Vipitis Jun 13, 2024
74c4c76
increase CI verbosity
Vipitis Jun 13, 2024
6f81212
dynamic input headers
Vipitis Jun 18, 2024
8b7e10b
cleanup redundant logic
Vipitis Jun 18, 2024
96ac7dd
add buffers test from api
Vipitis Jun 19, 2024
4027a7f
add test for buffers
Vipitis Jun 21, 2024
7bacf78
fix empty buffer case
Vipitis Jun 28, 2024
964e40d
omit test due to caching issue
Vipitis Jun 28, 2024
1aa5ce0
fix lint
Vipitis Jun 28, 2024
6957cc3
update ruff
Vipitis Jun 28, 2024
00c0ee2
initialize inputs_complete
Vipitis Jun 28, 2024
253c5e1
fix lint
Vipitis Jul 25, 2024
46833c7
fix wgsl buffer vertex code
Vipitis Jul 25, 2024
589ce4e
avoid duplicated glsl vertex code
Vipitis Jul 26, 2024
8e2089a
address comments
Vipitis Aug 15, 2024
26295e7
expand buffers test
Vipitis Sep 1, 2024
4db5990
use texture view
Vipitis Sep 4, 2024
c4d3140
Add more type hints
Vipitis Sep 11, 2024
4606609
readd buffer resizing
Vipitis Sep 23, 2024
fde4501
typo in link
Vipitis Sep 28, 2024
b2ee401
update deps
Vipitis Sep 28, 2024
634b7e2
use perferred format
Vipitis Sep 28, 2024
039ece8
fix missing buffer pass
Vipitis Nov 20, 2024
2c36068
fix example
Vipitis Nov 21, 2024
a16ee5f
fix gamma
Vipitis Nov 25, 2024
452013f
submit the command buffers once
Vipitis Dec 9, 2024
5b5befd
add simple profiling
Vipitis Dec 10, 2024
1ce5500
make profiling optional
Vipitis Dec 10, 2024
47e561c
fix profiling for fewer passes
Vipitis Dec 17, 2024
f67a247
refactor glsl vertex
Vipitis Dec 18, 2024
7544126
refactor wgsl vertex and fragment
Vipitis Dec 20, 2024
91d364e
simplify GLSL uniforms
Vipitis Dec 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Possible sections in each release:

Added:
* Run shaders from the website API https://github.com/pygfx/shadertoy/pull/25
* Support for Buffer channels and Buffer passes https://github.com/pygfx/shadertoy/pull/30

Changed:
* `ShadertoyChannel` is now more specific `ShadertoyChannelTexture`

### [v0.1.0] - 2024-01-21

Expand Down
37 changes: 31 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This project is not affiliated with shadertoy.com.
```bash
pip install wgpu-shadertoy
```
To install the latest development version, use:
```bash
pip install git+https://github.com/pygfx/shadertoy.git@main
```

To use the Shadertoy.com API, please setup an environment variable with the key `SHADERTOY_KEY`. See [How To](https://www.shadertoy.com/howto#q2) for instructions.

## Usage
Expand All @@ -40,10 +45,10 @@ if __name__ == "__main__":
shader.show()
```

Texture inputs are supported by using the `ShadertoyChannel` class. Up to 4 channels are supported.
Texture inputs are supported by using the `ShadertoyChannelTexture` class. Up to 4 channels are supported.

```python
from wgpu_shadertoy import Shadertoy, ShadertoyChannel
from wgpu_shadertoy import Shadertoy, ShadertoyChannelTexture
from PIL import Image

shader_code = """
Expand All @@ -56,7 +61,7 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
"""

img = Image.open("./examples/screenshots/shadertoy_star.png")
channel0 = ShadertoyChannel(img, wrap="repeat")
channel0 = ShadertoyChannelTexture(img, wrap="repeat")
shader = Shadertoy(shader_code, resolution=(800, 450), inputs=[channel0])
```

Expand All @@ -65,12 +70,13 @@ To easily load shaders from the website make use of the `.from_id` or `.from_jso
shader = Shadertoy.from_id("NslGRN")
```

When passing `off_screen=True` the `.snapshot()` method allows you to render specific frames.
When passing `offscreen=True` the `.snapshot()` method allows you to render specific frames. Use the following code snippet to get an RGB image.
```python
shader = Shadertoy(shader_code, resolution=(800, 450), off_screen=True)
shader = Shadertoy(shader_code, resolution=(800, 450), offscreen=True)
frame0_data = shader.snapshot()
frame10_data = shader.snapshot(10.0)
frame0_img = Image.fromarray(np.asarray(frame0_data))
# reorder the the channels from bgra to rgba
frame0_img = Image.fromarray(np.asarray(frame0_data)[..., [2, 1, 0, 3]]).convert('RGB')
Vipitis marked this conversation as resolved.
Show resolved Hide resolved
frame0_img.save("frame0.png")
```
For more examples see [examples](./examples).
Expand All @@ -82,6 +88,25 @@ To display a shader from the website, simply provide its ID or url.
> wgpu-shadertoy tsXBzS --resolution 1024 640
```

### Uniforms
The Shadertoy uniform format is directly supported for GLSL. However for WGSL the syntax is a bit different.

| Shadertoy.com | GLSL | WGSL |
|--- | --- | --- |
| `vec4 iMouse` | `iMouse` | `i_mouse` |
| `vec4 iDate` | `iDate` | `i_date` |
| `vec3 iResolution` | `iResolution` | `i_resolution` |
| `float iTime` | `iTime` | `i_time` |
| `vec3 iChannelResolution[4]` | `iChannelResolution` | `i_channel_resolution` |
| `float iTimeDelta` | `iTimeDelta` | `i_time_delta` |
| `int iFrame` | `iFrame` | `i_frame` |
| `float iFrameRate` | `iFrameRate` | `i_frame_rate` |
| `sampler2D iChannel0..3` | `iChannel0..3` | `i_channel0..3` |
| `sampler3D iChannel0..3` | not yet supported | not yet supported |
| `samplerCube iChannel0..3` | not yet supported | not yet supported |
| `float iChannelTime[4]` | not yet supported | not yet supported |
| `float iSampleRate` | not yet supported | not yet supported |

## Status

This project is still in development. Some functionality from the Shadertoy [website is missing](https://github.com/pygfx/shadertoy/issues/4) and [new features](https://github.com/pygfx/shadertoy/issues/8) are being added. See the issues to follow the development or [contribute yourself](./CONTRIBUTING.md)! For progress see the [changelog](./CHANGELOG.md).
Expand Down
Loading
Loading