Skip to content

[WIP] add imgui controls for define macros - #46

Draft
Vipitis wants to merge 26 commits into
mainfrom
imgui
Draft

[WIP] add imgui controls for define macros#46
Vipitis wants to merge 26 commits into
mainfrom
imgui

Conversation

@Vipitis

@Vipitis Vipitis commented May 5, 2025

Copy link
Copy Markdown
Collaborator

Very WIP, so the branch is messy. Mentioned in #8

I threw this together at the airport just now after thinking about it for the past week.

Currently works with the example provided but theoretically should work with all single pass shaders.
Only float and int dtypes and only glsl just now. Also missing common code.

Based on the imgui example in wgpu, but I can already think of a bunch of ways to make it fit better with the existing structures.

most likely todos:

  • better example, perhaps this: https://www.shadertoy.com/view/Wf3SWn (needs to loop in L73)
  • can we somehow access the preprocessor from naga (or via tree-sitter?)
  • add a dataclass to hold all the information
  • support common and buffer passes like buffer_a.value
  • can imgui be it's own renderpass (instead of attaching to the image?)
  • Sliders should have an option to reset to default
  • Print the value off all constants upon exit (on_close event?)
  • skip common constants (pi, tau, eps?, ...)
  • vec3 dtype for color picker and directions!?
  • can we get const float name 1.23 too?
  • a bunch of tests
  • should this be an optional dependency
  • does imgui-bundle work with python3.9 or do we need to drop it?
  • WGSL has no #define - do we support any patterns there?
  • cleanup

@Vipitis Vipitis mentioned this pull request May 5, 2025
12 tasks
@Vipitis

Vipitis commented May 20, 2025

Copy link
Copy Markdown
Collaborator Author

little demo video to show the poc working from cli:

imgui_demo.mp4

@Korijn

Korijn commented Jun 8, 2025

Copy link
Copy Markdown

This is super cool!

@ShnitzelKiller

Copy link
Copy Markdown

I get the error AttributeError: 'imgui_bundle._imgui_bundle.imgui.ImFontAtlas' object has no attribute 'get_tex_data_as_rgba32' when I try to launch a shader with the --imgui argument. On macOSX.

@Vipitis

Vipitis commented Aug 26, 2025

Copy link
Copy Markdown
Collaborator Author

Hey @ShnitzelKiller can you try out the wgpu main brach? The latest release is missing some fixes for the most recent imgui-bundle release see pygfx/wgpu-py#725

Otherwise downgrading imgui-bundle might do it.

@ShnitzelKiller

Copy link
Copy Markdown

Installing main branch of wgpu fixed it.

Comment thread wgpu_shadertoy/imgui.py
Comment on lines +191 to +192
front_view = rp.texture_front.create_view()
front_ref = rp.main._imgui_backend.register_texture(front_view)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi, came cross here from pygfx/wgpu-py#729 (comment).
It’s generally better not to create and register new texture views every frame in the render loop. Instead, a global texture view should be registered and used during initialization, or a imgui.TextureRef can be registered and created only at the first time the GUI is rendered.
If it’s absolutely necessary to create and register new texture views each frame in the render loop, you must manually call the newly added unregister method in pygfx/wgpu-py#749 to release the old texture view resources.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

cheers for the heads up,
the render target for the buffer passes is switching back and forth between two textures(maybe I should also keep both views...) so I will likely have to register both of them during initialization and figure out a way to select the correct one in the gui function or swap them around after the draw function too. Sorta is a little against the "intermediate mode" concept.

I will have a think since this whole branch needs a better pattern anyway, why too many if self._imgui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants