forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective - Add Ui Materials so that UI can render more complex and animated widgets. - Fixes bevyengine#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 <[email protected]> Co-authored-by: François <[email protected]>
- Loading branch information
1 parent
068c11a
commit a50a0c7
Showing
11 changed files
with
1,090 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import bevy_render::view::View | ||
#import bevy_ui::ui_vertex_output::UiVertexOutput | ||
|
||
@group(0) @binding(0) | ||
var<uniform> view: View; | ||
|
||
@vertex | ||
fn vertex( | ||
@location(0) vertex_position: vec3<f32>, | ||
@location(1) vertex_uv: vec2<f32>, | ||
@location(2) border_widths: vec4<f32>, | ||
) -> UiVertexOutput { | ||
var out: UiVertexOutput; | ||
out.uv = vertex_uv; | ||
out.position = view.view_proj * vec4<f32>(vertex_position, 1.0); | ||
out.border_widths = border_widths; | ||
return out; | ||
} | ||
|
||
@fragment | ||
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0); | ||
} |
Oops, something went wrong.