fx: json files
This commit is contained in:
@@ -1,35 +1,35 @@
|
|||||||
{
|
{
|
||||||
|
"filename": "highDef.png",
|
||||||
|
"image_width": 1920,
|
||||||
|
"image_height": 1080,
|
||||||
|
"max_depth": 50,
|
||||||
"camera": {
|
"camera": {
|
||||||
"image_width": 1920,
|
|
||||||
"image_height": 1080,
|
|
||||||
"anti_alias_rate": 23,
|
"anti_alias_rate": 23,
|
||||||
"max_depth": 50,
|
|
||||||
"fov": 20.0,
|
"fov": 20.0,
|
||||||
"look_from": { "x": -10, "y": 5, "z": 10 },
|
"look_from": [-10, 5, 10],
|
||||||
"look_at": { "x": 0.0, "y": 0.0, "z": -1.0 },
|
"look_at": [0.0, 0.0, -1.0],
|
||||||
"vup": { "x": 0.0, "y": 1.0, "z": 0.0 },
|
"vup": [0.0, 1.0, 0.0],
|
||||||
"defocus_blur": false,
|
"defocus_angle": 0,
|
||||||
"defocus_angle": 2,
|
|
||||||
"focus_dist": 15.68
|
"focus_dist": 15.68
|
||||||
},
|
},
|
||||||
"materials": [
|
"materials": [
|
||||||
{ "type": "metal", "albedo": { "x": 0.2, "y": 0.4, "z": 0.8 }, "prob": 1.0, "fuzz": 0.1 },
|
{ "type": "metal", "albedo": [0.2, 0.4, 0.8 ], "prob": 1.0, "fuzz": 0.1},
|
||||||
{ "type": "metal", "albedo": { "x": 0.7, "y": 0.4, "z": 0.2 }, "prob": 1.0, "fuzz": 0.1 },
|
{ "type": "metal", "albedo": [0.7, 0.4, 0.2 ], "prob": 1.0, "fuzz": 0.1},
|
||||||
{ "type": "lambertian", "albedo": { "x": 0.8, "y": 0.8, "z": 0.0 }, "prob": 1.0 },
|
{ "type": "lambertian", "albedo": [0.8, 0.8, 0.0 ], "prob": 1.0},
|
||||||
{ "type": "lambertian", "albedo": { "x": 0.1, "y": 0.2, "z": 0.5 }, "prob": 1.0 },
|
{ "type": "lambertian", "albedo": [0.1, 0.2, 0.5 ], "prob": 1.0},
|
||||||
{ "type": "dielectric", "refraction_index": 1.5},
|
{ "type": "dielectric", "refraction_index": 1.5},
|
||||||
{ "type": "dielectric", "refraction_index": 0.67},
|
{ "type": "dielectric", "refraction_index": 0.67},
|
||||||
{ "type": "metal", "albedo": { "x": 0.8, "y": 0.6, "z": 0.2 }, "prob": 1.0, "fuzz": 1.0 }
|
{ "type": "metal", "albedo": [0.8, 0.6, 0.2 ], "prob": 1.0, "fuzz": 1.0}
|
||||||
|
|
||||||
],
|
],
|
||||||
"objects": [
|
"objects": [
|
||||||
{ "type": "sphere", "center": { "x": 0, "y": 0.7, "z": -0.4 }, "radius": 0.2, "material": 0},
|
{ "type": "sphere", "center": [0, 0.7, -0.4], "radius": 0.2, "material": 0},
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": 0.5, "z": -0.8 }, "radius": 0.1, "material": 1},
|
{ "type": "sphere", "center": [0.0, 0.5, -0.8], "radius": 0.1, "material": 1},
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": -100.5, "z": -1.0 }, "radius": 100.0, "material": 2},
|
{ "type": "sphere", "center": [0.0, -100.5, -1.0], "radius": 100.0, "material": 2},
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": 0.0, "z": -1.2 }, "radius": 0.5, "material": 3},
|
{ "type": "sphere", "center": [0.0, 0.0, -1.2], "radius": 0.5, "material": 3},
|
||||||
{ "type": "sphere", "center": { "x": -1, "y": 0, "z": -1 }, "radius": 0.4, "material": 5},
|
{ "type": "sphere", "center": [-1, 0, -1], "radius": 0.4, "material": 5},
|
||||||
{ "type": "sphere", "center": { "x": 1, "y": 0, "z": -1 }, "radius": 0.5, "material": 6},
|
{ "type": "sphere", "center": [1, 0, -1], "radius": 0.5, "material": 6},
|
||||||
{ "type": "sphere", "center": { "x": 20, "y": 7, "z": -15 }, "radius": 10.5, "material": 0}
|
{ "type": "sphere", "center": [20, 7, -15], "radius": 10.5, "material": 0}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"camera": {
|
|
||||||
"anti_alias_rate": 23,
|
|
||||||
"max_depth": 100,
|
|
||||||
"fov": 40.0,
|
|
||||||
"look_from": { "x": -10, "y": 5, "z": 10 },
|
|
||||||
"look_at": { "x": 0.0, "y": 0.0, "z": -1.0 },
|
|
||||||
"vup": { "x": 0.0, "y": 1.0, "z": 0.0 }
|
|
||||||
},
|
|
||||||
"materials": [
|
|
||||||
{ "type": "metal", "albedo": { "x": 0.2, "y": 0.4, "z": 0.8 }, "prob": 1.0, "fuzz": 0.1 },
|
|
||||||
{ "type": "metal", "albedo": { "x": 0.7, "y": 0.4, "z": 0.2 }, "prob": 1.0, "fuzz": 0.1 },
|
|
||||||
{ "type": "lambertian", "albedo": { "x": 0.8, "y": 0.8, "z": 0.0 }, "prob": 1.0 },
|
|
||||||
{ "type": "lambertian", "albedo": { "x": 0.1, "y": 0.2, "z": 0.5 }, "prob": 1.0 },
|
|
||||||
{ "type": "dielectric", "refraction_index": 1.5},
|
|
||||||
{ "type": "dielectric", "refraction_index": 0.67},
|
|
||||||
{ "type": "metal", "albedo": { "x": 0.8, "y": 0.6, "z": 0.2 }, "prob": 1.0, "fuzz": 1.0 }
|
|
||||||
|
|
||||||
],
|
|
||||||
"objects": [
|
|
||||||
{ "type": "sphere", "center": { "x": 0, "y": 0.7, "z": -0.4 }, "radius": 0.2, "material": 0},
|
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": 0.5, "z": -0.8 }, "radius": 0.1, "material": 1},
|
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": -100.5, "z": -1.0 }, "radius": 100.0, "material": 2},
|
|
||||||
{ "type": "sphere", "center": { "x": 0.0, "y": 0.0, "z": -1.2 }, "radius": 0.5, "material": 3},
|
|
||||||
{ "type": "sphere", "center": { "x": -1, "y": 0, "z": -1 }, "radius": 0.4, "material": 5},
|
|
||||||
{ "type": "sphere", "center": { "x": 1, "y": 0, "z": -1 }, "radius": 0.5, "material": 6},
|
|
||||||
{ "type": "sphere", "center": { "x": 20, "y": 7, "z": -15 }, "radius": 10.5, "material": 0}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
11
src/main.rs
11
src/main.rs
@@ -7,7 +7,7 @@ mod raytracer;
|
|||||||
mod scenes;
|
mod scenes;
|
||||||
mod vec3;
|
mod vec3;
|
||||||
|
|
||||||
use std::fs;
|
use std::{env, fs};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
@@ -27,8 +27,13 @@ fn main() {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
|
|
||||||
// TODO: use cli arg for scenefile
|
// TODO: better cli parsing
|
||||||
let json_file = "./scenes/scene.json";
|
let mut json_file = "./scenes/scene.json";
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
if args.len() > 1 {
|
||||||
|
json_file = &args[1];
|
||||||
|
}
|
||||||
|
|
||||||
let json_str = fs::read_to_string(json_file).expect("Reading specified scene file failed!");
|
let json_str = fs::read_to_string(json_file).expect("Reading specified scene file failed!");
|
||||||
let mut scene: Scene = serde_json::from_str(&json_str).unwrap();
|
let mut scene: Scene = serde_json::from_str(&json_str).unwrap();
|
||||||
render(&mut scene);
|
render(&mut scene);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ pub fn render_chunk(chunk: &mut [u8], scene: &Scene, y: u32) {
|
|||||||
chunk[(i * 3) as usize + 1] = g;
|
chunk[(i * 3) as usize + 1] = g;
|
||||||
chunk[(i * 3) as usize + 2] = b;
|
chunk[(i * 3) as usize + 2] = b;
|
||||||
}
|
}
|
||||||
info!("Line {} finished.", y);
|
info!("Line {}\tfinished.", y);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ray_colour(hittables: &Vec<Arc<dyn Hittable>>, r: &Ray, depth: u32) -> Colour {
|
pub fn ray_colour(hittables: &Vec<Arc<dyn Hittable>>, r: &Ray, depth: u32) -> Colour {
|
||||||
|
|||||||
Reference in New Issue
Block a user