73 lines
1.9 KiB
Rust
73 lines
1.9 KiB
Rust
#![feature(array_zip)]
|
|
|
|
mod renderer;
|
|
mod geometry;
|
|
mod ray;
|
|
mod scene_data;
|
|
mod colors;
|
|
mod math_utils;
|
|
|
|
use std::string::String;
|
|
use cgmath::Vector4;
|
|
use clap::{Parser};
|
|
use easy_gltf::Scene;
|
|
use crate::colors::{map_radmap_to_colors, normalize_colors_global, store_colors_to_image};
|
|
use crate::renderer::render;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
pub struct Args {
|
|
gltf_file_path: String,
|
|
/// which scene to use in the gltf file
|
|
#[arg(long)]
|
|
scene_index: usize,
|
|
/// which camera to render from
|
|
#[arg(long)]
|
|
camera_index: usize,
|
|
/// image width
|
|
#[arg(long)]
|
|
width: usize,
|
|
/// image height
|
|
#[arg(long)]
|
|
height: usize,
|
|
/// rays per pixel
|
|
#[arg(long)]
|
|
multiplier: usize,
|
|
///start in debug mode (e.g. without parallelization)
|
|
#[arg(long)]
|
|
debug: bool,
|
|
///path tracing recursion depth
|
|
#[arg(long)]
|
|
recurse: usize,
|
|
}
|
|
|
|
fn main() {
|
|
//parse clargs
|
|
let args: Args = Args::parse();
|
|
|
|
//load gltf scene
|
|
let scenes: &Vec<Scene> = &easy_gltf::load(
|
|
&args.gltf_file_path)
|
|
.expect(&*format!("Failed to load glTF file {}", &args.gltf_file_path));
|
|
|
|
println!("Path tracing image. Columns finished:");
|
|
let mut radiosity_buffer: Vec<Vec<Vector4<f32>>> = match render(scenes, &args).lock() {
|
|
Ok(buffer) => { buffer.to_vec() }
|
|
Err(_) => { panic!("Unable to lock radiosity buffer!") }
|
|
};
|
|
|
|
//normalize radiosity values globally
|
|
let normalized =
|
|
normalize_colors_global(&mut radiosity_buffer);
|
|
//map radiositys to u8 colors
|
|
let as_colors =
|
|
map_radmap_to_colors(normalized);
|
|
//store colors to image
|
|
let output_image =
|
|
store_colors_to_image(as_colors);
|
|
|
|
output_image
|
|
.save("/home/clemens/repositorys/raytrace-rs/output_image.png")
|
|
.expect("Unable to save image!");
|
|
}
|
|
|