Dimchikkk / bevy_cosmic_edit

Apache License 2.0
86 stars 9 forks source link

Add Shaders #110

Closed bytemunch closed 7 months ago

bytemunch commented 1 year ago

closes #66

I'm not that experienced with traits and the like but this feels like the idiomatic way to add shader support, public facing API feels okay-ish.

Branches off #106 so might need some history tidying up lol

TODO:

I'm not too sure about the differences between Sprite and Quad meshes, might be an idea to move to using quads directly if that's what sprites do, save having an extra display method.

Dimchikkk commented 1 year ago

@bytemunch nice stuff. What do you think about having 2 ways for public facing API:

?

bytemunch commented 1 year ago

@StaffEngineer I was thinking about a default internal shader yeah, definitely a good idea, think I need to work with shaders for a while longer before I understand if they can be added to eachother, or if we wanted both rounded corners and shadows (for example) they would need to be defined in a single .wgsl file and triggered on struct conditions. I'm sure there's a way to use the output of one shader as input for the next, I just haven't got that far yet lol.

I do think shadows and corners should be available to the user without messing with shader code.

Dimchikkk commented 1 year ago

@bytemunch yeah, you can pass flags from rust side to shader code to enable specific features.... so it's possible to have one shader for all features... as a tradeoff it's definitely gonna be slower than separate shaders due to if branching in shader's code.

Dimchikkk commented 1 year ago

This might be useful to test performance of rendering pipeline when working with shaders: https://github.com/bevyengine/bevy/blob/main/docs/profiling.md#chrome-tracing-format

bytemunch commented 1 year ago

Yea far as my reading has taken me so far conditions on the GPU is something to avoid. The other approach seems to be building shaders on eachother with render passes and rendering to textures and stuff.. Seems complicated, might get easier once I've wrapped my head around it all.

Dimchikkk commented 1 year ago

Nice bevy example! Shaders are fun, I am sure you love it :D

For inspiration if you haven't seen it: https://youtu.be/BFld4EBO2RE

Dimchikkk commented 1 year ago

I wish we have cosmic text widget on all sides of 3d cube with ability to rotate cube... could be nice showcase demo :)

bytemunch commented 1 year ago

Note to self: do NOT try and read a spec while parenting.

Found naga_oil which looks like it solves most of the complicated shader bits, but further research required lol

bytemunch commented 1 year ago

so that's how modular shaders work, okay. and after looking at bevy's mesh2d shader I'm less worried about putting a few branches in shader code. Can write rounded_corners.wgsl and shadows.wgsl, then import their fns into a mixing shader that applies to the material, using friendly user-facing structs to toggle inputs for the shader.

Dimchikkk commented 1 year ago

naga_oil is adopted by bevy in 0.11 release to enable better (more explicit) importing/exporting functionality afaik. So yeah, your approach sounds good to me.

Dimchikkk commented 1 year ago

ui materials are merged fyi :)

Dimchikkk commented 7 months ago

Let's re-open if/once active :)