-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add UI Materials #9506
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 UI Materials #9506
Changes from all commits
2d37454
fb90baa
7a98e22
ccba0a2
4298848
cbbbd88
7ed8914
e65163e
d5e12d4
bb19f42
3b8022a
ced9292
62709a0
62a51e0
d4327cc
7706744
493d3cc
f637d7a
033dee0
86ae1b8
66a4cd9
ac911ba
d800744
4c65b29
794b722
4a150cd
c9fcabe
193197a
d2fbd1d
930ec95
fef7fac
7eeb644
6294a17
1226bf1
301b193
e77172b
239faf9
1239117
bc2c029
84ef0ac
62b99d6
1e0727a
781fb57
7988610
b51c143
57419c0
4a9bf5f
08cf2f3
a978a1e
a3c613e
fb49734
83d703a
b0c6ec9
12b6a33
3ea88ca
65ae48a
b412839
349af3c
d5909ba
c61a2aa
afe56e5
f8267d1
2425a10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ use crate::widget::TextFlags; | |
use crate::{ | ||
widget::{Button, UiImageSize}, | ||
BackgroundColor, BorderColor, ContentSize, FocusPolicy, Interaction, Node, Style, UiImage, | ||
UiTextureAtlasImage, ZIndex, | ||
UiMaterial, UiTextureAtlasImage, ZIndex, | ||
}; | ||
use bevy_asset::Handle; | ||
use bevy_ecs::bundle::Bundle; | ||
|
@@ -342,3 +342,52 @@ impl Default for ButtonBundle { | |
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah noticed a snag, ideally we want some sort of
The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be fine not to worry about measurefuncs for this PR though, the implementation looks great, really nice and clean. It's not essential as users can create their own system to add a measurefunc, which isn't very hard. We do need a custom measurefunc example, it would make sense to base one around a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great suggestion, I agree with you there, I wasn't aware of I'd like to get this PR done and would be happy to take on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn’t the image just be a member of the material type? @ickshonpe as well as other data needed - the image size. |
||
/// A UI node that is rendered using a [`UiMaterial`] | ||
#[derive(Bundle, Clone, Debug)] | ||
pub struct MaterialNodeBundle<M: UiMaterial> { | ||
/// Describes the logical size of the node | ||
pub node: Node, | ||
/// Styles which control the layout (size and position) of the node and it's children | ||
/// In some cases these styles also affect how the node drawn/painted. | ||
pub style: Style, | ||
/// The [`UiMaterial`] used to render the node. | ||
pub material: Handle<M>, | ||
/// Whether this node should block interaction with lower nodes | ||
pub focus_policy: FocusPolicy, | ||
/// The transform of the node | ||
/// | ||
/// This field is automatically managed by the UI layout system. | ||
/// To alter the position of the `NodeBundle`, use the properties of the [`Style`] component. | ||
pub transform: Transform, | ||
/// The global transform of the node | ||
/// | ||
/// This field is automatically managed by the UI layout system. | ||
/// To alter the position of the `NodeBundle`, use the properties of the [`Style`] component. | ||
pub global_transform: GlobalTransform, | ||
/// Describes the visibility properties of the node | ||
pub visibility: Visibility, | ||
/// Inherited visibility of an entity. | ||
pub inherited_visibility: InheritedVisibility, | ||
/// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering | ||
pub view_visibility: ViewVisibility, | ||
/// Indicates the depth at which the node should appear in the UI | ||
pub z_index: ZIndex, | ||
} | ||
|
||
impl<M: UiMaterial> Default for MaterialNodeBundle<M> { | ||
fn default() -> Self { | ||
Self { | ||
node: Default::default(), | ||
style: Default::default(), | ||
material: Default::default(), | ||
focus_policy: Default::default(), | ||
transform: Default::default(), | ||
global_transform: Default::default(), | ||
visibility: Default::default(), | ||
inherited_visibility: Default::default(), | ||
view_visibility: Default::default(), | ||
z_index: Default::default(), | ||
} | ||
} | ||
} |
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); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.