Add more scenes
This commit is contained in:
parent
7d38e87f6a
commit
b11e7a7a78
8 changed files with 116 additions and 20 deletions
|
|
@ -7,7 +7,7 @@ use ray_tracing_core::{
|
||||||
scene::Scene,
|
scene::Scene,
|
||||||
};
|
};
|
||||||
use ray_tracing_renderer::path_tracer_importance::PathTracerImportance;
|
use ray_tracing_renderer::path_tracer_importance::PathTracerImportance;
|
||||||
use ray_tracing_scene::examples::basic_cornel;
|
use ray_tracing_scene::examples::basic_cornell;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
|
@ -45,7 +45,7 @@ fn render_image<
|
||||||
|
|
||||||
fn main() -> ImageResult<()> {
|
fn main() -> ImageResult<()> {
|
||||||
// let s = BasicScene::new();
|
// let s = BasicScene::new();
|
||||||
let s = basic_cornel();
|
let s = basic_cornell();
|
||||||
|
|
||||||
let c = BasicCamera::new(
|
let c = BasicCamera::new(
|
||||||
400,
|
400,
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,10 @@ where
|
||||||
let r = camera.forward(x, y, rng);
|
let r = camera.forward(x, y, rng);
|
||||||
|
|
||||||
if let Some(i) = scene.intersect(r, 0.0, Float::INFINITY) {
|
if let Some(i) = scene.intersect(r, 0.0, Float::INFINITY) {
|
||||||
Color::gray(1.0 / i.t())
|
// Color::gray(1.0 / i.t())
|
||||||
// let c = 0.5 * (i.normal() + Dir3::new(1.0, 1.0, 1.0));
|
let c = 0.5 * (i.normal() + Dir3::new(1.0, 1.0, 1.0));
|
||||||
// let c = i.normal();
|
// let c = i.normal();
|
||||||
// Color::new(c.x(), c.y(), c.z())
|
Color::new(c.x(), c.y(), c.z())
|
||||||
} else {
|
} else {
|
||||||
Color::black()
|
Color::black()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,5 +23,5 @@ Ka 20 20 20
|
||||||
Kd 1 1 1
|
Kd 1 1 1
|
||||||
Ks 0 0 0
|
Ks 0 0 0
|
||||||
|
|
||||||
newmtl glass
|
newmtl mirror
|
||||||
type glass
|
type glass
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ v 343.0 548.0 227.0
|
||||||
v 343.0 548.0 332.0
|
v 343.0 548.0 332.0
|
||||||
v 213.0 548.0 332.0
|
v 213.0 548.0 332.0
|
||||||
v 213.0 548.0 227.0
|
v 213.0 548.0 227.0
|
||||||
#f -4 -3 -2 -1
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
o ceiling
|
o ceiling
|
||||||
usemtl white
|
usemtl white
|
||||||
|
|
@ -72,7 +72,7 @@ v 556.0 548.8 0.0
|
||||||
f -4 -3 -2 -1
|
f -4 -3 -2 -1
|
||||||
|
|
||||||
o short_block
|
o short_block
|
||||||
usemtl glass
|
usemtl mirror
|
||||||
|
|
||||||
v 130.0 165.0 65.0
|
v 130.0 165.0 65.0
|
||||||
v 82.0 165.0 225.0
|
v 82.0 165.0 225.0
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,11 @@
|
||||||
|
use crate::{
|
||||||
|
parse_obj::ObjData,
|
||||||
|
triangle_bvh::{BVHMaterial, Triangle, TriangleBVH},
|
||||||
|
};
|
||||||
use ray_tracing_core::{light::AreaLight, prelude::*};
|
use ray_tracing_core::{light::AreaLight, prelude::*};
|
||||||
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
use ray_tracing_material::{diffuse::DiffuseMaterial, mirror::Mirror};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::Debug;
|
||||||
use crate::triangle_bvh::{BVHMaterial, Triangle, TriangleBVH};
|
|
||||||
|
|
||||||
pub struct ExampleScene<R: Rng> {
|
pub struct ExampleScene<R: Rng> {
|
||||||
pub scene: TriangleBVH<R>,
|
pub scene: TriangleBVH<R>,
|
||||||
|
|
@ -12,18 +15,47 @@ pub struct ExampleScene<R: Rng> {
|
||||||
pub horizontal_fov: Float,
|
pub horizontal_fov: Float,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn example_scenes<R: Rng>() -> HashMap<&'static str, fn() -> ExampleScene<R>> {
|
pub fn example_scenes<R: Rng + Debug>() -> HashMap<&'static str, fn() -> ExampleScene<R>> {
|
||||||
let mut map: HashMap<&str, fn() -> ExampleScene<R>> = HashMap::new();
|
let mut map: HashMap<&str, fn() -> ExampleScene<R>> = HashMap::new();
|
||||||
map.insert("basic_cornel", basic_cornel::<R>);
|
map.insert("basic_cornel", basic_cornell::<R>);
|
||||||
// map.insert("cornel2", cornel2::<R>);
|
map.insert("cornel2", cornell2::<R>);
|
||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cornel2<R: Rng>() -> ExampleScene<R> {
|
pub fn cornell2<R: Rng + Debug>() -> ExampleScene<R> {
|
||||||
todo!()
|
let obj = ObjData::new("ray-tracing-scene/obj/cornell_box.obj").unwrap();
|
||||||
|
|
||||||
|
let triangles = obj
|
||||||
|
.triangle_faces()
|
||||||
|
.map(|t| Triangle::new(t.v, t.mat.unwrap()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let materials = obj
|
||||||
|
.materials()
|
||||||
|
.iter()
|
||||||
|
.map(|m| match m.name.as_str() {
|
||||||
|
"white" => BVHMaterial::new_material(DiffuseMaterial::new(Color::white())),
|
||||||
|
"light" => BVHMaterial::new_light(AreaLight::new(Color::white() * 100.0)),
|
||||||
|
"blue" => BVHMaterial::new_material(DiffuseMaterial::new(Color::new(0.0, 0.0, 1.0))),
|
||||||
|
"red" => BVHMaterial::new_material(DiffuseMaterial::new(Color::new(1.0, 0.0, 0.0))),
|
||||||
|
"green" => BVHMaterial::new_material(DiffuseMaterial::new(Color::new(0.0, 1.0, 0.0))),
|
||||||
|
"mirror" => BVHMaterial::new_material(Mirror::new(Color::white())),
|
||||||
|
_ => unreachable!(),
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let scene = dbg!(TriangleBVH::new(obj.vertices, triangles, materials));
|
||||||
|
|
||||||
|
ExampleScene {
|
||||||
|
scene,
|
||||||
|
camera_pos: Pos3::new(275.0, 275.0, -800.0),
|
||||||
|
camera_dir: Dir3::new(0.0, 0.0, 1.0),
|
||||||
|
camera_up: Dir3::up(),
|
||||||
|
horizontal_fov: 90.0_f32.to_radians(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn basic_cornel<R: Rng>() -> ExampleScene<R> {
|
pub fn basic_cornell<R: Rng>() -> ExampleScene<R> {
|
||||||
let side_length = 1.5;
|
let side_length = 1.5;
|
||||||
let light_size = 0.5;
|
let light_size = 0.5;
|
||||||
let light_offset = 0.01;
|
let light_offset = 0.01;
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ pub struct ObjData {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ObjMaterial {
|
pub struct ObjMaterial {
|
||||||
name: String,
|
pub name: String,
|
||||||
map: HashMap<String, String>,
|
pub map: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -34,6 +34,13 @@ pub struct Face {
|
||||||
pub mat: Option<u32>,
|
pub mat: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct TriangleFace {
|
||||||
|
pub v: [u32; 3],
|
||||||
|
pub t: Option<[u32; 3]>,
|
||||||
|
pub n: Option<[u32; 3]>,
|
||||||
|
pub mat: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RelativeFace {
|
pub struct RelativeFace {
|
||||||
pub v: Vec<i32>,
|
pub v: Vec<i32>,
|
||||||
|
|
@ -400,4 +407,27 @@ impl ObjData {
|
||||||
materials,
|
materials,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vertices(&self) -> &Vec<Pos3> {
|
||||||
|
&self.vertices
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn faces(&self) -> &Vec<Face> {
|
||||||
|
&self.faces
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn triangle_faces(&self) -> impl Iterator<Item = TriangleFace> + '_ {
|
||||||
|
self.faces.iter().flat_map(|f| {
|
||||||
|
(1..f.v.len() - 1).map(|i| TriangleFace {
|
||||||
|
v: [f.v[0], f.v[i], f.v[i + 1]],
|
||||||
|
t: f.t.as_ref().map(|t| [t[0], t[i], t[i + 1]]),
|
||||||
|
n: f.n.as_ref().map(|n| [n[0], n[i], n[i + 1]]),
|
||||||
|
mat: f.mat,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn materials(&self) -> &Vec<ObjMaterial> {
|
||||||
|
&self.materials
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,39 @@ pub struct BVHMaterial<R: Rng> {
|
||||||
pub light: Option<Box<dyn Light<R>>>,
|
pub light: Option<Box<dyn Light<R>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<R: Rng> BVHMaterial<R> {
|
||||||
|
pub fn new_material<M: Material<R> + 'static>(material: M) -> Self {
|
||||||
|
Self {
|
||||||
|
material: Some(Box::new(material)),
|
||||||
|
light: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_light<L: Light<R> + 'static>(light: L) -> Self {
|
||||||
|
Self {
|
||||||
|
material: None,
|
||||||
|
light: Some(Box::new(light)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_material_light<M: Material<R> + 'static, L: Light<R> + 'static>(
|
||||||
|
material: M,
|
||||||
|
light: L,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
material: Some(Box::new(material)),
|
||||||
|
light: Some(Box::new(light)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_empty() -> Self {
|
||||||
|
Self {
|
||||||
|
material: None,
|
||||||
|
light: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum Node {
|
enum Node {
|
||||||
Inner {
|
Inner {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ use ray_tracing_renderer::{
|
||||||
depth_renderer::DepthRenderer, path_tracer::PathTracer,
|
depth_renderer::DepthRenderer, path_tracer::PathTracer,
|
||||||
path_tracer_importance::PathTracerImportance,
|
path_tracer_importance::PathTracerImportance,
|
||||||
};
|
};
|
||||||
use ray_tracing_scene::{examples::basic_cornel, triangle_bvh::TriangleBVH};
|
use ray_tracing_scene::examples::cornell2;
|
||||||
|
use ray_tracing_scene::triangle_bvh::TriangleBVH;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use tev_client::{PacketCreateImage, PacketUpdateImage, TevClient, TevError};
|
use tev_client::{PacketCreateImage, PacketUpdateImage, TevClient, TevError};
|
||||||
|
|
@ -69,7 +70,7 @@ fn render_image<
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_scene() -> (TriangleBVH<SmallRng>, BasicCamera) {
|
fn get_scene() -> (TriangleBVH<SmallRng>, BasicCamera) {
|
||||||
let s = basic_cornel();
|
let s = cornell2();
|
||||||
|
|
||||||
let c = BasicCamera::new(
|
let c = BasicCamera::new(
|
||||||
400,
|
400,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue