rustial-renderer-wgpu 0.0.1

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! Terrain vertex definition.

use bytemuck::{Pod, Zeroable};

/// Vertex for terrain mesh rendering (position + UV + normal).
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct TerrainVertex {
    /// Position `[x, y, z]` in camera-relative meters.
    pub position: [f32; 3],
    /// Texture coordinate `[u, v]`.
    pub uv: [f32; 2],
    /// Surface normal `[nx, ny, nz]`.
    pub normal: [f32; 3],
}

impl TerrainVertex {
    /// Vertex buffer layout descriptor.
    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: std::mem::size_of::<TerrainVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                // position
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                // uv
                wgpu::VertexAttribute {
                    offset: 12,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x2,
                },
                // normal
                wgpu::VertexAttribute {
                    offset: 20,
                    shader_location: 2,
                    format: wgpu::VertexFormat::Float32x3,
                },
            ],
        }
    }
}