bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.53k stars 3.52k forks source link

Improve Ui custom material example #11685

Open viridia opened 8 months ago

viridia commented 8 months ago

What problem does this solve or what need does it fill?

I was attempting to implement my own "border radius" shader using the custom ui material example as a basis. However, I could not figure out how to get the actual width and height of the entity. The default UI shader pipeline knows this, as it's needed for drawing borders whose thickness is not tied to the overall width/height. But the example doesn't show how to access this information.

What solution would you like?

Rather than making the existing example more complex, I would like to see a second example that shows off some more advanced techniques. Particularly, it should show what kinds of uniforms and inputs are available for shaders to use.

What alternative(s) have you considered?

Yes, I could ask on Discord, but I think that others will want to know the answer to this, and an example could be helpful.

ickshonpe commented 3 weeks ago

This is a problem with the UI material shader, maybe we need more a second more complex UiMaterial that provides the size and border radius info.

viridia commented 3 weeks ago

UiVertexOutput has the node size now: https://github.com/bevyengine/bevy/blob/8bfe635c3e119fa9324ba738ac11d30e7b988ac1/crates/bevy_ui/src/render/ui_vertex_output.wgsl#L9

I think this was changed as part of the border radius rework.