Skip to main content

rustial_renderer_wgpu/gpu/
line_pattern_vertex.rs

1//! Vertex type for line-pattern rendering (line vertex + pattern UV).
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for the line-pattern GPU pipeline.
6///
7/// Extends [`super::line_vertex::LineVertex`] with per-vertex UV
8/// coordinates used to sample the repeating pattern texture.
9/// U maps along the line centreline (distance / pattern width) and
10/// V maps across the line width (0 = left edge, 1 = right edge).
11#[repr(C)]
12#[derive(Debug, Clone, Copy, Pod, Zeroable)]
13pub struct LinePatternVertex {
14    /// Position `[x, y, z]` in camera-relative meters.
15    pub position: [f32; 3],
16    /// Per-vertex RGBA color (used as fallback / tint).
17    pub color: [f32; 4],
18    /// Extrusion normal `[nx, ny]` perpendicular to the line centreline.
19    pub line_normal: [f32; 2],
20    /// Distance along the polyline centreline (world-space meters).
21    pub line_distance: f32,
22    /// Cap/join flag: `1.0` for round cap/join fan vertices, `0.0` for
23    /// ribbon body.
24    pub cap_join: f32,
25    /// Pattern UV coordinates.
26    ///
27    /// U = distance along line / pattern width (repeats via GPU sampler).
28    /// V = perpendicular position across line width [0 = left, 1 = right].
29    pub uv: [f32; 2],
30}
31
32impl LinePatternVertex {
33    /// Vertex buffer layout for the line-pattern pipeline.
34    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
35        wgpu::VertexBufferLayout {
36            array_stride: std::mem::size_of::<LinePatternVertex>() as wgpu::BufferAddress,
37            step_mode: wgpu::VertexStepMode::Vertex,
38            attributes: &[
39                // position
40                wgpu::VertexAttribute {
41                    offset: 0,
42                    shader_location: 0,
43                    format: wgpu::VertexFormat::Float32x3,
44                },
45                // color
46                wgpu::VertexAttribute {
47                    offset: 12,
48                    shader_location: 1,
49                    format: wgpu::VertexFormat::Float32x4,
50                },
51                // line_normal
52                wgpu::VertexAttribute {
53                    offset: 28,
54                    shader_location: 2,
55                    format: wgpu::VertexFormat::Float32x2,
56                },
57                // line_distance
58                wgpu::VertexAttribute {
59                    offset: 36,
60                    shader_location: 3,
61                    format: wgpu::VertexFormat::Float32,
62                },
63                // cap_join
64                wgpu::VertexAttribute {
65                    offset: 40,
66                    shader_location: 4,
67                    format: wgpu::VertexFormat::Float32,
68                },
69                // uv
70                wgpu::VertexAttribute {
71                    offset: 44,
72                    shader_location: 5,
73                    format: wgpu::VertexFormat::Float32x2,
74                },
75            ],
76        }
77    }
78}