Closed bytemunch closed 7 months ago
@bytemunch nice stuff. What do you think about having 2 ways for public facing API:
CosmicRoundedCorners { radius: usize }
, CosmicShadow { size: usize, type: 'inner' | 'outer', color: u8 }
components for enabling shader?
@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.
@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.
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
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.
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
I wish we have cosmic text widget on all sides of 3d cube with ability to rotate cube... could be nice showcase demo :)
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
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.
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.
ui materials are merged fyi :)
Let's re-open if/once active :)
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
andQuad
meshes, might be an idea to move to using quads directly if that's what sprites do, save having an extra display method.