rustial-renderer-wgpu 1.0.0

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! View-projection uniform buffer with distance fog and hillshade parameters.

use bytemuck::{Pod, Zeroable};

/// GPU-side uniform containing the view-projection matrix, fog parameters,
/// and terrain hillshade parameters.
///
/// Layout (std140-aligned):
/// - `view_proj`:            mat4x4<f32>
/// - `fog_color`:            vec4<f32>
/// - `eye_pos`:              vec4<f32>
/// - `fog_params`:           vec4<f32>
/// - `hillshade_highlight`:  vec4<f32>
/// - `hillshade_shadow`:     vec4<f32>
/// - `hillshade_accent`:     vec4<f32>
/// - `hillshade_light`:      vec4<f32> = (dir_rad, altitude_rad, exaggeration, opacity)
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct ViewProjUniform {
    /// Column-major 4x4 view-projection matrix (`projection * view`).
    pub view_proj: [[f32; 4]; 4],
    /// Fog / horizon colour (RGBA, typically the clear colour).
    pub fog_color: [f32; 4],
    /// Camera eye position in camera-relative world coordinates (w = 0).
    pub eye_pos: [f32; 4],
    /// `[fog_start, fog_end, fog_density, 0.0]`
    pub fog_params: [f32; 4],
    /// Hillshade highlight colour.
    pub hillshade_highlight: [f32; 4],
    /// Hillshade shadow colour.
    pub hillshade_shadow: [f32; 4],
    /// Hillshade accent colour.
    pub hillshade_accent: [f32; 4],
    /// `(illumination_direction_rad, illumination_altitude_rad, exaggeration, opacity)`.
    pub hillshade_light: [f32; 4],
}

impl ViewProjUniform {
    /// Create from a glam DMat4 (f64 -> f32 truncation) with default fog and hillshade.
    pub fn from_dmat4(m: &glam::DMat4) -> Self {
        let m32 = m.as_mat4();
        Self {
            view_proj: m32.to_cols_array_2d(),
            fog_color: [1.0, 1.0, 1.0, 1.0],
            eye_pos: [0.0, 0.0, 0.0, 0.0],
            fog_params: [0.0, 1.0, 0.0, 0.0],
            hillshade_highlight: [1.0, 1.0, 1.0, 1.0],
            hillshade_shadow: [0.0, 0.0, 0.0, 1.0],
            hillshade_accent: [0.42, 0.48, 0.42, 1.0],
            hillshade_light: [335.0f32.to_radians(), 45.0f32.to_radians(), 1.0, 0.0],
        }
    }
}