diff --git a/assets/shaders/circle_shader.wgsl b/assets/shaders/circle_shader.wgsl deleted file mode 100644 index 7e3f676626..0000000000 --- a/assets/shaders/circle_shader.wgsl +++ /dev/null @@ -1,20 +0,0 @@ -// This shader draws a circle with a given input color -#import bevy_ui::ui_vertex_output::UiVertexOutput - -struct CustomUiMaterial { - @location(0) color: vec4 -} - -@group(1) @binding(0) -var input: CustomUiMaterial; - -@fragment -fn fragment(in: UiVertexOutput) -> @location(0) vec4 { - // 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(input.color.rgb, alpha); -} diff --git a/assets/shaders/custom_ui_material.wgsl b/assets/shaders/custom_ui_material.wgsl new file mode 100644 index 0000000000..fa0344930d --- /dev/null +++ b/assets/shaders/custom_ui_material.wgsl @@ -0,0 +1,18 @@ +// This shader draws a circle with a given input color +#import bevy_ui::ui_vertex_output::UiVertexOutput + +@group(1) @binding(0) var color: vec4; +@group(1) @binding(1) var slider: f32; +@group(1) @binding(2) var material_color_texture: texture_2d; +@group(1) @binding(3) var material_color_sampler: sampler; + + +@fragment +fn fragment(in: UiVertexOutput) -> @location(0) vec4 { + if in.uv.x < slider { + let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color; + return output_color; + } else { + return vec4(0.0); + } +} diff --git a/examples/ui/ui_material.rs b/examples/ui/ui_material.rs index 89156cf53c..bfd06ad58f 100644 --- a/examples/ui/ui_material.rs +++ b/examples/ui/ui_material.rs @@ -5,26 +5,22 @@ use bevy::reflect::TypePath; use bevy::render::render_resource::*; /// This example uses a shader source file from the assets subdirectory -const SHADER_ASSET_PATH: &str = "shaders/circle_shader.wgsl"; +const SHADER_ASSET_PATH: &str = "shaders/custom_ui_material.wgsl"; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(UiMaterialPlugin::::default()) .add_systems(Startup, setup) - .add_systems(Update, update) + .add_systems(Update, animate) .run(); } -fn update(time: Res