diff --git a/crates/bevy_ui/src/render/ui.wgsl b/crates/bevy_ui/src/render/ui.wgsl index 5fc77b1d30b23..5fd6f5d96a659 100644 --- a/crates/bevy_ui/src/render/ui.wgsl +++ b/crates/bevy_ui/src/render/ui.wgsl @@ -126,9 +126,7 @@ fn antialias(distance: f32) -> f32 { return clamp(0.0, 1.0, 0.5 - distance); } -fn draw(in: VertexOutput) -> vec4 { - let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv); - +fn draw(in: VertexOutput, texture_color: vec4) -> vec4 { // Only use the color sampled from the texture if the `TEXTURED` flag is enabled. // This allows us to draw both textured and untextured shapes together in the same batch. let color = select(in.color, in.color * texture_color, enabled(in.flags, TEXTURED)); @@ -161,8 +159,7 @@ fn draw(in: VertexOutput) -> vec4 { return vec4(color.rgb, saturate(color.a * t)); } -fn draw_background(in: VertexOutput) -> vec4 { - let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv); +fn draw_background(in: VertexOutput, texture_color: vec4) -> vec4 { let color = select(in.color, in.color * texture_color, enabled(in.flags, TEXTURED)); // When drawing the background only draw the internal area and not the border. @@ -173,9 +170,11 @@ fn draw_background(in: VertexOutput) -> vec4 { @fragment fn fragment(in: VertexOutput) -> @location(0) vec4 { + let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv); + if enabled(in.flags, BORDER) { - return draw(in); + return draw(in, texture_color); } else { - return draw_background(in); + return draw_background(in, texture_color); } }