File tree 2 files changed +6
-5
lines changed
2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 2
2
#import bevy_ui ::ui_vertex_output ::UiVertexOutput
3
3
4
4
@group (1 ) @binding (0 ) var <uniform > color : vec4 <f32 >;
5
- @group (1 ) @binding (1 ) var <uniform > slider : f32 ;
5
+ @group (1 ) @binding (1 ) var <uniform > slider : vec4 < f32 > ;
6
6
@group (1 ) @binding (2 ) var material_color_texture : texture_2d <f32 >;
7
7
@group (1 ) @binding (3 ) var material_color_sampler : sampler ;
8
8
@group (1 ) @binding (4 ) var <uniform > border_color : vec4 <f32 >;
@@ -50,7 +50,7 @@ fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
50
50
51
51
// sample the texture at this position if it's to the left of the slider value
52
52
// otherwise return a fully transparent color
53
- if in . uv. x < slider {
53
+ if in . uv. x < slider . x {
54
54
let output_color = textureSample (material_color_texture , material_color_sampler , in . uv) * color ;
55
55
return output_color ;
56
56
} else {
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ fn setup(
44
44
} ,
45
45
MaterialNode ( ui_materials. add ( CustomUiMaterial {
46
46
color : LinearRgba :: WHITE . to_f32_array ( ) . into ( ) ,
47
- slider : 0.5 ,
47
+ slider : Vec4 :: splat ( 0.5 ) ,
48
48
color_texture : asset_server. load ( "branding/banner.png" ) ,
49
49
border_color : LinearRgba :: WHITE . to_f32_array ( ) . into ( ) ,
50
50
} ) ) ,
@@ -66,8 +66,9 @@ struct CustomUiMaterial {
66
66
color : Vec4 ,
67
67
/// Represents how much of the image is visible
68
68
/// Goes from 0 to 1
69
+ /// A `Vec4` is used here because Bevy with webgl2 requires that uniforms are 16-byte aligned but only the first component is read.
69
70
#[ uniform( 1 ) ]
70
- slider : f32 ,
71
+ slider : Vec4 ,
71
72
/// Image used to represent the slider
72
73
#[ texture( 2 ) ]
73
74
#[ sampler( 3 ) ]
@@ -97,7 +98,7 @@ fn animate(
97
98
let new_color = Color :: hsl ( ( time. elapsed_secs ( ) * 60.0 ) % 360.0 , 1. , 0.5 ) ;
98
99
let border_color = Color :: hsl ( ( time. elapsed_secs ( ) * 60.0 ) % 360.0 , 0.75 , 0.75 ) ;
99
100
material. color = new_color. to_linear ( ) . to_vec4 ( ) ;
100
- material. slider =
101
+ material. slider . x =
101
102
( ( time. elapsed_secs ( ) % ( duration * 2.0 ) ) - duration) . abs ( ) / duration;
102
103
material. border_color = border_color. to_linear ( ) . to_vec4 ( ) ;
103
104
}
You can’t perform that action at this time.
0 commit comments