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
76
77
78
//! Vertex type for line-pattern rendering (line vertex + pattern UV).
use bytemuck::{Pod, Zeroable};
/// A vertex for the line-pattern GPU pipeline.
///
/// Extends [`super::line_vertex::LineVertex`] with per-vertex UV
/// coordinates used to sample the repeating pattern texture.
/// U maps along the line centreline (distance / pattern width) and
/// V maps across the line width (0 = left edge, 1 = right edge).
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct LinePatternVertex {
/// Position `[x, y, z]` in camera-relative meters.
pub position: [f32; 3],
/// Per-vertex RGBA color (used as fallback / tint).
pub color: [f32; 4],
/// Extrusion normal `[nx, ny]` perpendicular to the line centreline.
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.
pub cap_join: f32,
/// Pattern UV coordinates.
///
/// U = distance along line / pattern width (repeats via GPU sampler).
/// V = perpendicular position across line width [0 = left, 1 = right].
pub uv: [f32; 2],
}
impl LinePatternVertex {
/// Vertex buffer layout for the line-pattern pipeline.
pub fn layout() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<LinePatternVertex>() 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,
},
// uv
wgpu::VertexAttribute {
offset: 44,
shader_location: 5,
format: wgpu::VertexFormat::Float32x2,
},
],
}
}
}