enginerenderer 0.0.1

A zero-dependency offline rendering engine in pure Rust — CPU path tracing, BVH acceleration, 16-band spectral rendering, PBR materials, animation & video export.
Documentation
use std::path::{Path, PathBuf};

use crate::{
    core::engine::config::EngineConfig,
    core::engine::rendering::{environment::procedural::ProceduralEnvironment, raytracing::Vec3},
};

#[derive(Debug, Clone, Copy)]
pub struct SceneEnvironment {
    /// Sky gradient top color.
    pub sky_top: Vec3,
    /// Sky gradient bottom color.
    pub sky_bottom: Vec3,
    /// Sun light direction.
    pub sun_direction: Vec3,
    /// Sun light color.
    pub sun_color: Vec3,
    /// Sun intensity multiplier.
    pub sun_intensity: f64,
    /// Sun apparent angular radius.
    pub sun_angular_radius: f64,
    /// Scene exposure value.
    pub exposure: f64,
    /// Solar elevation value used by environment sampling.
    pub solar_elevation: f64,
}

/// Resource manager for output paths and derived scene environment.
#[derive(Debug, Clone)]
pub struct ResourceManager {
    output_path: PathBuf,
    environment: SceneEnvironment,
    surface_detail_scale: f64,
}

impl ResourceManager {
    /// Builds resource manager data from engine configuration.
    pub fn from_config(config: &EngineConfig) -> Self {
        let pixel_count = (config.width * config.height) as f64;
        let hd_reference = (1280 * 720) as f64;
        let surface_detail_scale = (pixel_count / hd_reference).sqrt().clamp(1.0, 2.5);
        let procedural_environment = ProceduralEnvironment::cinematic_space();
        let solar_elevation: f64 = 0.48;
        let sun_dir = Vec3::new(solar_elevation.cos(), solar_elevation.sin(), 0.0);
        let sky_top = procedural_environment.hdri_probe(Vec3::new(0.0, 1.0, 0.0), sun_dir);
        let sky_bottom =
            procedural_environment.hdri_probe(Vec3::new(0.0, 0.12, 1.0).normalize(), sun_dir);

        Self {
            output_path: config.output_path.clone(),
            environment: SceneEnvironment {
                sky_top,
                sky_bottom,
                sun_direction: Vec3::new(-0.65, -0.35, -1.0).normalize(),
                sun_color: procedural_environment.sun_color(Vec3::new(0.0, 1.0, 0.0), sun_dir),
                sun_intensity: 1.45 + surface_detail_scale * 0.14,
                sun_angular_radius: 0.03,
                exposure: procedural_environment.exposure_for_detail(surface_detail_scale),
                solar_elevation,
            },
            surface_detail_scale,
        }
    }

    /// Returns the configured output path.
    pub fn output_path(&self) -> &Path {
        &self.output_path
    }

    /// Returns the precomputed scene environment.
    pub fn environment(&self) -> SceneEnvironment {
        self.environment
    }

    /// Returns derived surface detail scaling factor.
    pub fn surface_detail_scale(&self) -> f64 {
        self.surface_detail_scale
    }
}