From 534b6bb9e1c1239ddc3e041e26a4d7f269b9b9e8 Mon Sep 17 00:00:00 2001 From: Brian Schwind Date: Mon, 25 Mar 2024 20:00:41 +0900 Subject: [PATCH] Experiment with clipping edges as well --- crates/viewer/shaders/edge.wgsl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/viewer/shaders/edge.wgsl b/crates/viewer/shaders/edge.wgsl index ce2e3c76..ff2ff817 100644 --- a/crates/viewer/shaders/edge.wgsl +++ b/crates/viewer/shaders/edge.wgsl @@ -33,6 +33,9 @@ struct VertexOutput { @location(0) dist: f32, + + @location(1) + plane_distance: f32, }; @vertex @@ -46,6 +49,8 @@ fn main_vs(input: VertexInput) -> VertexOutput { let clip0 = globals.proj * globals.transform * vec4(input.point_a.xyz, 1.0); let clip1 = globals.proj * globals.transform * vec4(input.point_b.xyz, 1.0); + let interpolated_pos = vec4(mix(input.point_a.xyz, input.point_b.xyz, vec3(input.pos.z)), 1.0); + // Transform the segment endpoints to screen space let a = globals.resolution.xy * (0.5 * clip0.xy / clip0.w + 0.5); let b = globals.resolution.xy * (0.5 * clip1.xy / clip1.w + 0.5); @@ -63,11 +68,18 @@ fn main_vs(input: VertexInput) -> VertexOutput { out.pos = vec4(clip.w * ((2.0 * final_pos) / globals.resolution.xy - 1.0), clip.z, clip.w); out.dist = mix(input.length_so_far_a.x, input.length_so_far_b.x, input.pos.z); + var plane = vec4(-1.0, 0.8, 1.2, 40.0); + out.plane_distance = dot(plane, interpolated_pos); + return out; } @fragment fn main_fs(input: VertexOutput) -> @location(0) vec4 { + if input.plane_distance > 0.0 { + discard; + } + let r = 0.0; let g = 0.0; let b = 0.0;