mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 05:03:47 +00:00
fd232ad360
# Objective - Add Ui Materials so that UI can render more complex and animated widgets. - Fixes #5607 ## Solution - Create a UiMaterial trait for specifying a Shader Asset and Bind Group Layout/Data. - Create a pipeline for rendering these Materials inside the Ui layout/tree. - Create a MaterialNodeBundle for simple spawning. ## Changelog - Created a `UiMaterial` trait for specifying a Shader asset and Bind Group. - Created a `UiMaterialPipeline` for rendering said Materials. - Added Example [`ui_material` ](https://github.com/MarkusTheOrt/bevy/blob/ui_material/examples/ui/ui_material.rs) for example usage. - Created [`UiVertexOutput`](https://github.com/MarkusTheOrt/bevy/blob/ui_material/crates/bevy_ui/src/render/ui_vertex_output.wgsl) export as VertexData for shaders. - Created [`material_ui`](https://github.com/MarkusTheOrt/bevy/blob/ui_material/crates/bevy_ui/src/render/ui_material.wgsl) shader as default for both Vertex and Fragment shaders. --------- Co-authored-by: ickshonpe <david.curthoys@googlemail.com> Co-authored-by: François <mockersf@gmail.com>
21 lines
570 B
WebGPU Shading Language
21 lines
570 B
WebGPU Shading Language
// This shader draws a circle with a given input color
|
|
#import bevy_ui::ui_vertex_output::UiVertexOutput
|
|
|
|
struct CustomUiMaterial {
|
|
@location(0) color: vec4<f32>
|
|
}
|
|
|
|
@group(1) @binding(0)
|
|
var<uniform> input: CustomUiMaterial;
|
|
|
|
@fragment
|
|
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
|
|
// the UVs are now adjusted around the middle of the rect.
|
|
let uv = in.uv * 2.0 - 1.0;
|
|
|
|
// circle alpha, the higher the power the harsher the falloff.
|
|
let alpha = 1.0 - pow(sqrt(dot(uv, uv)), 100.0);
|
|
|
|
return vec4<f32>(input.color.rgb, alpha);
|
|
}
|
|
|