Random WIP

This commit is contained in:
Bill Thiede 2023-09-21 10:25:23 -07:00
parent 9430a1e7da
commit 42f3daefaa
3 changed files with 66 additions and 22 deletions

View File

@ -4,11 +4,12 @@ use crate::{
cuboid::Cuboid, cuboid::Cuboid,
hitable::Hit, hitable::Hit,
hitable_list::HitableList, hitable_list::HitableList,
material::{Lambertian, Material, Metal}, material::{Dielectric, DiffuseLight, Isotropic, Lambertian, Material, Metal},
renderer::Scene, renderer::Scene,
sphere::Sphere, sphere::Sphere,
texture::{EnvMap, Texture}, texture::{EnvMap, Texture},
}; };
use chrono::IsoWeek;
use serde::Deserialize; use serde::Deserialize;
use std::{collections::HashMap, fs::File, io::BufReader, path::PathBuf, sync::Arc}; use std::{collections::HashMap, fs::File, io::BufReader, path::PathBuf, sync::Arc};
use stl::STL; use stl::STL;
@ -46,6 +47,10 @@ impl TryFrom<Config> for Scene {
for mc in c.materials { for mc in c.materials {
let v: Arc<dyn Material> = match mc.material { let v: Arc<dyn Material> = match mc.material {
Materials::Metal { albedo, fuzzy } => Arc::new(Metal::new(albedo, fuzzy)), Materials::Metal { albedo, fuzzy } => Arc::new(Metal::new(albedo, fuzzy)),
Materials::Dielectric { ref_idx } => Arc::new(Dielectric::new(ref_idx)),
Materials::DiffuseLight { texture } => Arc::new(DiffuseLight::new(texture)),
Materials::Isotropic { texture } => Arc::new(Isotropic::new(texture)),
Materials::Lambertian { texture } => Arc::new(Lambertian::new(texture)),
}; };
if materials.insert(mc.name.clone(), v).is_some() { if materials.insert(mc.name.clone(), v).is_some() {
return Err(ConfigError::DuplicateMaterial(mc.name)); return Err(ConfigError::DuplicateMaterial(mc.name));
@ -173,6 +178,15 @@ struct MaterialConfig {
enum Materials { enum Materials {
#[serde(rename = "metal")] #[serde(rename = "metal")]
Metal { albedo: [f32; 3], fuzzy: f32 }, Metal { albedo: [f32; 3], fuzzy: f32 },
#[serde(rename = "dielectric")]
Dielectric { ref_idx: f32 },
// TODO(wathiede): these all take Textures, for now, only support RGB
#[serde(rename = "diffuse_light")]
DiffuseLight { texture: [f32; 3] },
#[serde(rename = "isotropic")]
Isotropic { texture: [f32; 3] },
#[serde(rename = "lambertian")]
Lambertian { texture: [f32; 3] },
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View File

@ -111,7 +111,12 @@ pub struct Opt {
pub use_accel: bool, pub use_accel: bool,
/// Output directory /// Output directory
#[structopt(parse(from_os_str), default_value = "/tmp/tracer")] #[structopt(
short = "o",
long = "output",
parse(from_os_str),
default_value = "/tmp/tracer"
)]
pub output: PathBuf, pub output: PathBuf,
} }

View File

@ -1,49 +1,74 @@
[scene] [scene]
width = 768 width = 768
height = 768 height = 512
#subsamples = 1000 subsamples = 100
[camera] [camera]
lookfrom = [0.0, 30.0, -100.0] lookfrom = [0.0, 50.0, 100.0]
lookat = [0.0, 0.0, 0.0] lookat = [0.0, 10.0, 0.0]
fov = 45 fov = 45
aperture = 0.0 aperture = 0.0
focus_dist = 10.0 focus_dist = 10.0
time_min = 0.0 time_min = 0.0
time_max = 1.0 time_max = 1.0
[[materials]]
name = "light1"
type = "isotropic"
texture = [20, 10, 10]
[[materials]]
name = "yellow"
type = "isotropic"
texture = [1, 1, 0]
[[materials]]
name = "magenta"
type = "lambertian"
texture = [1, 0, 1]
[[materials]] [[materials]]
name = "green" name = "green"
type = "metal" type = "diffuse_light"
albedo = [0, 1, 0] texture = [0, 1, 0]
fuzzy = 1.5
[[materials]] [[materials]]
name = "blue" name = "metal"
type = "metal" type = "metal"
albedo = [0, 0, 1] albedo = [1, 1, 1]
fuzzy = 1.5 fuzzy = 0
[[materials]] [[materials]]
name = "red" name = "glass"
type = "metal" type = "dielectric"
albedo = [1, 0, 0] ref_idx = 1.5
fuzzy = 1.5
[[hitables]] [[hitables]]
type = "cuboid" type = "sphere"
min = [-10.0, -10.0, -10.0] center = [-30.0, 0.0, 0.0]
max = [10.0, 10.0, 10.0] radius = 10
material_name = "green" material_name = "yellow"
[[hitables]] [[hitables]]
type = "sphere" type = "sphere"
center = [30.0, 0.0, 0.0] center = [30.0, 0.0, 0.0]
radius = 10 radius = 10
material_name = "blue" material_name = "green"
[[hitables]]
type = "sphere"
center = [0.0, -10.0, 0.0]
radius = 10
material_name = "metal"
[[hitables]]
type = "sphere"
center = [0.0, 0.0, -30.0]
radius = 10
material_name = "magenta"
[[hitables]] [[hitables]]
type = "stl" type = "stl"
path = "/net/nasx.h.xinu.tv/x/3dprint/stl/stanford_dragon.stl" path = "/net/nasx.h.xinu.tv/x/3dprint/stl/stanford_dragon.stl"
scale = 200 scale = 200
material_name = "red" material_name = "glass"
#[[hitables]]
#type = "sphere"
#center = [0.0, 50.0, -100.0]
#radius = 10
#material_name = "light1"
[envmap] [envmap]
path = "/home/wathiede/src/xinu.tv/raytracers/rtiow/renderer/images/52681723945_e1d94d3df9_6k.jpg" path = "/home/wathiede/src/xinu.tv/raytracers/rtiow/renderer/images/52681723945_e1d94d3df9_6k.jpg"