main render loop
This commit is contained in:
parent
af215f8291
commit
11ceb6ebc7
4 changed files with 62 additions and 8 deletions
|
|
@ -8,6 +8,5 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
easy-gltf = "1.1.1"
|
easy-gltf = "1.1.1"
|
||||||
clap = { version = "4.4.8", features = ["derive"] }
|
clap = { version = "4.4.8", features = ["derive"] }
|
||||||
|
cgmath = "0.18.0"
|
||||||
[alias]
|
rayon = "1.8.0"
|
||||||
runx = "run /home/clemens/repositorys/raytrace-rs/scenes/cube_on_plane.glb 0"
|
|
||||||
27
src/geometry.rs
Normal file
27
src/geometry.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
use cgmath::Vector3;
|
||||||
|
use easy_gltf::Camera;
|
||||||
|
use easy_gltf::model::Triangle;
|
||||||
|
|
||||||
|
pub struct Ray {
|
||||||
|
source: Vector3<f64>,
|
||||||
|
direction: Vector3<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Intersectable {
|
||||||
|
/*
|
||||||
|
tests whether the ray intersects the Intersectable.
|
||||||
|
returns: The intersection point or empty if there is none
|
||||||
|
*/
|
||||||
|
fn test_isec(&self, ray: &Ray) -> Option<Vector3<f32>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Intersectable for Triangle {
|
||||||
|
//perform muller trumbore intersection
|
||||||
|
fn test_isec(&self, ray: &Ray) -> Option<Vector3<f32>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn construct_rays(camera: &Camera) -> Vec<Ray> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
14
src/main.rs
14
src/main.rs
|
|
@ -1,15 +1,21 @@
|
||||||
mod renderer;
|
mod renderer;
|
||||||
|
mod geometry;
|
||||||
|
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use clap::{Parser};
|
use clap::{Parser};
|
||||||
|
use easy_gltf::Scene;
|
||||||
use crate::renderer::render;
|
use crate::renderer::render;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
gltf_file_path: String,
|
gltf_file_path: String,
|
||||||
//which scene to use in the gltf file
|
/// which scene to use in the gltf file
|
||||||
scene_index: u32,
|
#[arg(short, long)]
|
||||||
|
scene_index: usize,
|
||||||
|
/// which camera to render from
|
||||||
|
#[arg(short, long)]
|
||||||
|
camera_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
@ -17,10 +23,10 @@ fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
//load gltf scene
|
//load gltf scene
|
||||||
let scenes = easy_gltf::load(
|
let scenes: &Vec<Scene> = &easy_gltf::load(
|
||||||
&args.gltf_file_path)
|
&args.gltf_file_path)
|
||||||
.expect(&*format!("Failed to load glTF file {}", &args.gltf_file_path));
|
.expect(&*format!("Failed to load glTF file {}", &args.gltf_file_path));
|
||||||
|
|
||||||
render(scenes, args.scene_index)
|
render(scenes, args.scene_index, args.camera_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,26 @@
|
||||||
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
|
use easy_gltf::model::{Mode};
|
||||||
use easy_gltf::Scene;
|
use easy_gltf::Scene;
|
||||||
|
use crate::geometry::{construct_rays, Intersectable, Ray};
|
||||||
|
|
||||||
pub fn render(scenes: Vec<Scene>, scene_idx: u32) {
|
|
||||||
|
pub fn render(scenes: &Vec<Scene>, scene_idx: usize, camera_idx: usize) {
|
||||||
|
//construct all rays and cast them all
|
||||||
|
let rays: Vec<Ray> = construct_rays(&scenes[scene_idx].cameras[camera_idx]);
|
||||||
|
rays.into_par_iter().for_each(|ray| {
|
||||||
|
//test intersection with all models in the scene
|
||||||
|
//TODO: Improve, to avoid iterating all models
|
||||||
|
scenes[scene_idx].models.iter().for_each(|model| {
|
||||||
|
match model.mode() {
|
||||||
|
Mode::Triangles => {
|
||||||
|
//in triangle mode there will always be a triangle vector
|
||||||
|
let triangles = model.triangles().unwrap();
|
||||||
|
triangles.iter().for_each(|triangle| {
|
||||||
|
triangle.test_isec(&ray);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_ => { panic!("Unable to render model in mode {:?}", model.mode()) }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue