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

Let users access wgpu resources #68

Open
Leif-Rydenfalk opened this issue Jan 16, 2025 · 1 comment
Open

Let users access wgpu resources #68

Leif-Rydenfalk opened this issue Jan 16, 2025 · 1 comment

Comments

@Leif-Rydenfalk
Copy link
Contributor

Leif-Rydenfalk commented Jan 16, 2025

Background

in Swiftui you can create custom shader effects and apply them to images like so:

Image(systemName: "figure.run.circle.fill")
    .font(.system(size: 300))
    .colorEffect(ShaderLibrary.checkerboard(.float(10), .color(.blue))) 

Proposed changes

  • Expose the draw context to the user

What it allows for the user

  • GPU Computation for particle systems etc
  • Rendering custom ui elements
  • Custom renderer

OR / AND

Proposed changes

  • Add a way for the user to create a custom wgsl effect. Example api:
let effect = vger::Effect::from_source("examples/gaussian_blur.wgsl");
vger.apply_effect(effect);

or

view.apply_effect(effect)

in use

// draws a blurred white circle. 
fn main() {
    canvas(|_, rect, vger| {
        vger.translate(rect.center() - LocalPoint::zero());
        let radius = 100.0;
        let paint = vger.color_paint(vger::Color {
            r: 1.0,
            g: 1.0,
            b: 1.0,
            a: 1.0,
        });
        vger.fill_circle(LocalPoint::zero(), radius, paint);
	let effect = vger::Effect::from_source("examples/gaussian_blur.wgsl");
	vger.apply_effect(effect);
    })
    .run()
}

What it allows for the user

  • Shader effects which could be applied in theory to any view like shadows, color grading, blurs
@wtholliday
Copy link
Contributor

What would the shader look like?

In SwiftUI, it's quite easy to write the shaders due to the [[stitchable]] attribute. See https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-metal-shaders-to-swiftui-views-using-layer-effects

Would apply_effect apply to the entire window? That could be expensive and not desired. How would uniforms be passed to the shaders?

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

No branches or pull requests

2 participants