1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! Vertex type for dedicated line rendering with dash-pattern and SDF
//! cap/join antialiasing support.
use bytemuck::{Pod, Zeroable};
/// A vertex for the dedicated line GPU pipeline.
///
/// Extends the basic vector vertex with per-vertex distance along the
/// polyline centreline, an extrusion normal, and a cap/join flag.
/// The fragment shader uses the distance for dash-pattern evaluation
/// and the cap/join flag to switch between linear edge AA (ribbon body)
/// and SDF circle-based AA (round caps/joins).
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct LineVertex {
/// Position `[x, y, z]` in camera-relative meters.
pub position: [f32; 3],
/// Per-vertex RGBA color.
pub color: [f32; 4],
/// Extrusion normal `[nx, ny]` perpendicular to the line centreline.
///
/// For ribbon body vertices the magnitude is 1.0. For round cap/join
/// fan vertices the magnitude is slightly > 1.0 (circumscribed) so
/// that the SDF clip at magnitude 1.0 traces a perfect circle.
pub line_normal: [f32; 2],
/// Distance along the polyline centreline (world-space meters).
pub line_distance: f32,
/// Cap/join flag: `1.0` for round cap/join fan vertices, `0.0` for
/// ribbon body. When > 0.5, the fragment shader uses SDF circle AA
/// instead of linear edge AA and discards fragments beyond the
/// ideal circle boundary.
pub cap_join: f32,
}
impl LineVertex {
/// Vertex buffer layout for the line pipeline.
pub fn layout() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<LineVertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
// position
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float32x3,
},
// color
wgpu::VertexAttribute {
offset: 12,
shader_location: 1,
format: wgpu::VertexFormat::Float32x4,
},
// line_normal
wgpu::VertexAttribute {
offset: 28,
shader_location: 2,
format: wgpu::VertexFormat::Float32x2,
},
// line_distance
wgpu::VertexAttribute {
offset: 36,
shader_location: 3,
format: wgpu::VertexFormat::Float32,
},
// cap_join
wgpu::VertexAttribute {
offset: 40,
shader_location: 4,
format: wgpu::VertexFormat::Float32,
},
],
}
}
}