fix(render): render wide polyline segments as flat 2D rectangles instead of rounded pill shapes

This commit is contained in:
Karim Jerbi committed 2026-09-09 13:44:57 +01:00
1 parent 2875d4ae61
commit 76e1610dcc
5 files changed
+40 -4

No files matched your search

+26
View File
@@ -1464,4 +1464,30 @@ mod block_wire_storage_tests {
};
assert_eq!(names(&packed), names(&storage));
}
#[test]
fn wire_shader_validates_with_naga() {
let source = include_str!("../../shaders/wire.wgsl");
let module = naga::front::wgsl::parse_str(source).expect("wire.wgsl parses cleanly");
let mut validator = naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::all(),
);
validator
.validate(&module)
.expect("wire.wgsl validates cleanly with naga");
}
#[test]
fn wire_indexed_shader_validates_with_naga() {
let source = include_str!("../../shaders/wire_indexed.wgsl");
let module = naga::front::wgsl::parse_str(source).expect("wire_indexed.wgsl parses cleanly");
let mut validator = naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::all(),
);
validator
.validate(&module)
.expect("wire_indexed.wgsl validates cleanly with naga");
}
}
+2 -1
View File
@@ -144,7 +144,8 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32, in: VertexIn) -> VertexOut
wire_const.half_width,
);
let half_width = mix(half_width_a, half_width_b, which_end);
let extension = which_end * 2.0 - 1.0;
let is_world = wire_const.world_half_width > 0.0 || in.taper_ratio.x > 0.0 || in.taper_ratio.y > 0.0;
let extension = select(which_end * 2.0 - 1.0, 0.0, is_world);
let offset_px = perpendicular * half_width * side
+ direction * half_width * extension;
let ndc_offset = offset_px / (u.viewport_size * 0.5);
+2 -1
View File
@@ -175,7 +175,8 @@ fn vs_main(@builtin(vertex_index) vertex_index: u32, in: VertexIn) -> VertexOut
wire_const.half_width,
);
let half_width = mix(half_width_a, half_width_b, which_end);
let extension = which_end * 2.0 - 1.0;
let is_world = wire_const.world_half_width > 0.0 || seg_taper_ratio.x > 0.0 || seg_taper_ratio.y > 0.0;
let extension = select(which_end * 2.0 - 1.0, 0.0, is_world);
let offset_px = perpendicular * half_width * side
+ direction * half_width * extension;
let ndc_offset = offset_px / (u.viewport_size * 0.5);
+5 -1
View File
@@ -196,7 +196,11 @@ fn marker_relative(position_high: vec3<f32>, position_low: vec3<f32>, instance:
// fragment stage round the overhang off: adjoining segments then meet in
// overlapping round joints, closing the wedge gaps a perpendicular-only
// expansion leaves on the outside of corners and along tessellated arcs.
let ext = which_end * 2.0 - 1.0; // -1 at the A end, +1 at the B end
// Wide polylines have physical world-unit width (in.misc.w or in.taper > 0);
// in CAD, wide polyline segments are flat/square-ended 2D rectangles (or
// trapezoids), not rounded pill shapes.
let is_world = in.misc.w > 0.0 || in.taper.x > 0.0 || in.taper.y > 0.0;
let ext = select(which_end * 2.0 - 1.0, 0.0, is_world);
let offset_px = perp * hw * side + dir * hw * ext;
let ndc_offset = offset_px / (u.viewport_size * 0.5);
let final_clip = clip_pos + vec4<f32>(ndc_offset * clip_pos.w, 0.0, 0.0);
+5 -1
View File
@@ -165,7 +165,11 @@ fn marker_relative(position_high: vec3<f32>, position_low: vec3<f32>, c: WireCon
// fragment stage round the overhang off: adjoining segments then meet in
// overlapping round joints, closing the wedge gaps a perpendicular-only
// expansion leaves on the outside of corners and along tessellated arcs.
let ext = which_end * 2.0 - 1.0; // -1 at the A end, +1 at the B end
// Wide polylines have physical world-unit width (world_half_width or taper > 0);
// in CAD, wide polyline segments are flat/square-ended 2D rectangles (or
// trapezoids), not rounded pill shapes.
let is_world = c.world_half_width > 0.0 || in.taper_ratio.x > 0.0 || in.taper_ratio.y > 0.0;
let ext = select(which_end * 2.0 - 1.0, 0.0, is_world);
let offset_px = perp * hw * side + dir * hw * ext;
let ndc_offset = offset_px / (u.viewport_size * 0.5);
let final_clip = clip_pos + vec4<f32>(ndc_offset * clip_pos.w, 0.0, 0.0);