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 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pip install wgpu-shadertoy
```
To install the latest development version, use:
```bash
pip install git+https://gihub.com/pygfx/shadertoy.git@main
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.
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ build-backend = "setuptools.build_meta"
name = "wgpu-shadertoy"
dynamic = ["version", "readme"]
dependencies = [
"wgpu>=0.16.0,<0.17.0",
"wgpu>=0.16.0,<0.19.0",
"requests",
"numpy",
"Pillow",
]
description = "Shadertoy implementation based on wgpu-py"
license = {file = "LICENSE"}
requires-python = ">=3.8.0"
requires-python = ">=3.9.0"
authors = [
{name = "Jan Kels", email = "[email protected]"},
]
Expand All @@ -29,7 +29,6 @@ Repository = "https://github.com/pygfx/shadertoy"

[project.optional-dependencies]
dev = [
"numpy",
"pytest",
"ruff",
"imageio",
Expand Down
2 changes: 1 addition & 1 deletion wgpu_shadertoy/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def __init__(
self._input_headers = ""
# self.channels = self._attach_inputs(inputs)
self._format: wgpu.TextureFormat = (
wgpu.TextureFormat.bgra8unorm
wgpu.TextureFormat.bgra8unorm_srgb,
) # assume default?

@property
Expand Down
6 changes: 5 additions & 1 deletion wgpu_shadertoy/shadertoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def __init__(
self.title += " (incomplete)"

self._prepare_canvas()
self.image._format = self._format
self._bind_events()
# TODO: could this be part of the __init__ of each renderpass? (but we need the device)
for rpass in (self.image, *self.buffers.values()):
Expand Down Expand Up @@ -240,9 +241,12 @@ def _prepare_canvas(self):
self._present_context: wgpu.GPUCanvasContext = self._canvas.get_context()

# We use "bgra8unorm" not "bgra8unorm-srgb" here because we want to let the shader fully control the color-space.
# broken in newer versions of wgpu-py it seems... due to the minimal Vulkan capabilities...
# TODO: instead use canvas preference? ref: GPUCanvasContext.get_preferred_format()
self._format = self._present_context.get_preferred_format(adapter=self._device.adapter)

self._present_context.configure(
device=self._device, format=wgpu.TextureFormat.bgra8unorm
device=self._device, format=self._format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also set to None to have it select the preferred format. Less code, unless you need self._format. Note that the format is also accessible in texture.format on the texture obtained via get_current_texture().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I had a look and the only other solution I can think of is to make it a property of the ImageRenderPass, as it's needed to create the render pipeline. The awful part is that at init time for the Image class, the canvas(_present_context) might not be accessible via the parent instance of Shadertoy.
It could be returned by this method instead of passed via an attribute. It could be useful to have available when translating the snapshot back into RGB.

)

def _bind_events(self):
Expand Down
Loading