rustial-renderer-wgpu 0.0.1

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! 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,
                },
            ],
        }
    }
}