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

Add Shaders #110

Closed
wants to merge 16 commits into from
Closed

Add Shaders #110

wants to merge 16 commits into from

Conversation

bytemunch
Copy link
Collaborator

@bytemunch bytemunch commented Nov 2, 2023

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:

  • Mesh click functions (2d + 3d)
  • Make 2d example show shadows + rounded corners
  • 3d material support
  • 3d shader example
  • Autosizing of editor texture based on mesh size
  • Documentation

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.

breaks loads of stuff: sizing, click functions, cursor hovering just a few

Only tested on login example

not optimized; spams handle weak clones to ensure got correct handle (will be fixed by new handle swapping routine)

not sure about the API changes but might just need to get used to it, is much more extensible
centered padding now broken, not tested other text positions
@Dimchikkk
Copy link
Owner

Dimchikkk commented Nov 2, 2023

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

  • user can define any shader they want to apply for text widget
  • pre-defined built-in plugin shaders like CosmicRoundedCorners { radius: usize }, CosmicShadow { size: usize, type: 'inner' | 'outer', color: u8 } components for enabling shader

?

@bytemunch
Copy link
Collaborator Author

@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
Copy link
Owner

Dimchikkk commented Nov 2, 2023

@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
Copy link
Owner

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
Copy link
Collaborator Author

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
Copy link
Owner

Dimchikkk commented Nov 2, 2023

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
Copy link
Owner

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

@bytemunch
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Owner

Dimchikkk commented Nov 2, 2023

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
Copy link
Owner

Dimchikkk commented Nov 3, 2023

ui materials are merged fyi :)

@Dimchikkk
Copy link
Owner

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

@Dimchikkk Dimchikkk closed this Mar 19, 2024
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.

Add shadow shader
2 participants