Skip to content
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

custom_ui_material border fix #17282

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions assets/shaders/custom_ui_material.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,24 @@

@fragment
fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
// normalized position relative to the center of the UI node
let r = in.uv - 0.5;

// normalized size of the border closest to the current position
let b = vec2(
select(in.border_widths.x, in.border_widths.y, r.x < 0.),
select(in.border_widths.z, in.border_widths.w, r.y < 0.)
select(in.border_widths.x, in.border_widths.y, 0. < r.x),
select(in.border_widths.z, in.border_widths.w, 0. < r.y)
);

// if the distance to the edge from the current position on any axis
// is less than the border width on that axis then the position is within
// the border and we return the border color
if any(0.5 - b < abs(r)) {
return border_color;
}

// sample the texture at this position if it's to the left of the slider value
// otherwise return a fully transparent color
if in.uv.x < slider {
let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color;
return output_color;
Expand Down
Loading