rtiow: break project into multiple workspaces.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
2541b76ae6
commit
d9d183b1e5
1601
rtiow/Cargo.lock
generated
1601
rtiow/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,36 +1,12 @@
|
|||||||
[package]
|
[workspace]
|
||||||
authors = ["Bill Thiede <rust@xinu.tv>"]
|
|
||||||
edition = "2018"
|
|
||||||
name = "rtiow"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[[bench]]
|
members = [
|
||||||
harness = false
|
"noise_explorer",
|
||||||
name = "spheres"
|
"renderer",
|
||||||
|
"tracer",
|
||||||
[dependencies]
|
]
|
||||||
actix-web = "0.7.8"
|
|
||||||
askama = "0.7.1"
|
|
||||||
chrono = "*"
|
|
||||||
core_affinity = "0.5"
|
|
||||||
cpuprofiler = { version = "0.0.3", optional = true }
|
|
||||||
image = "0.19.0"
|
|
||||||
lazy_static = "1.1.0"
|
|
||||||
log = "0.4.5"
|
|
||||||
num_cpus = "1.8.0"
|
|
||||||
rand = "0.5.5"
|
|
||||||
serde = "1.0.79"
|
|
||||||
serde_derive = "1.0.79"
|
|
||||||
serde_json = "1.0.41"
|
|
||||||
stderrlog = "0.4.1"
|
|
||||||
structopt = "0.2.10"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
criterion = "0.2"
|
|
||||||
|
|
||||||
[profile]
|
[profile]
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = true
|
debug = true
|
||||||
|
|
||||||
[features]
|
|
||||||
profile = ["cpuprofiler"]
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
set -e
|
set -e
|
||||||
export RUSTFLAGS="-D warnings"
|
export RUSTFLAGS="-D warnings"
|
||||||
cargo build
|
cargo build --all
|
||||||
cargo build --features=profile
|
cargo build --all --features=profile
|
||||||
|
|||||||
19
rtiow/noise_explorer/Cargo.toml
Normal file
19
rtiow/noise_explorer/Cargo.toml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "noise_explorer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "0.7.8"
|
||||||
|
askama = "0.7.1"
|
||||||
|
image = "0.19.0"
|
||||||
|
log = "0.4.5"
|
||||||
|
rand = "0.5.5"
|
||||||
|
renderer = { path = "../renderer" }
|
||||||
|
serde = "1.0.79"
|
||||||
|
serde_derive = "1.0.79"
|
||||||
|
stderrlog = "0.4.1"
|
||||||
|
structopt = "0.2.10"
|
||||||
@ -1,18 +1,3 @@
|
|||||||
extern crate actix_web;
|
|
||||||
extern crate askama;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate image;
|
|
||||||
extern crate rand;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate stderrlog;
|
|
||||||
|
|
||||||
extern crate structopt;
|
|
||||||
|
|
||||||
extern crate rtiow;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
@ -26,17 +11,20 @@ use actix_web::Path;
|
|||||||
use actix_web::Query;
|
use actix_web::Query;
|
||||||
use actix_web::Result;
|
use actix_web::Result;
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
use image;
|
||||||
|
use log::info;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use rand::XorShiftRng;
|
use rand::XorShiftRng;
|
||||||
|
use serde_derive::Deserialize;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use rtiow::noise;
|
use renderer::noise;
|
||||||
use rtiow::noise::lode::Lode;
|
use renderer::noise::lode::Lode;
|
||||||
use rtiow::noise::perlin::Perlin;
|
use renderer::noise::perlin::Perlin;
|
||||||
use rtiow::noise::NoiseType;
|
use renderer::noise::NoiseType;
|
||||||
use rtiow::texture::NoiseTexture;
|
use renderer::texture::NoiseTexture;
|
||||||
use rtiow::texture::Texture;
|
use renderer::texture::Texture;
|
||||||
use rtiow::vec3::Vec3;
|
use renderer::vec3::Vec3;
|
||||||
|
|
||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(name = "noise_explorer", about = "CLI for exploring Perlin noise")]
|
#[structopt(name = "noise_explorer", about = "CLI for exploring Perlin noise")]
|
||||||
@ -151,13 +139,15 @@ fn render_noise(noise_params: NoiseParams) -> image::GrayImage {
|
|||||||
.optional
|
.optional
|
||||||
.unwrap_or(OptionalParams { pixel_scale: 1.0 });
|
.unwrap_or(OptionalParams { pixel_scale: 1.0 });
|
||||||
const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
const SEED: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
||||||
let rng: &mut XorShiftRng = &mut SeedableRng::from_seed(SEED);
|
let mut rng: XorShiftRng = SeedableRng::from_seed(SEED);
|
||||||
let mut img = image::GrayImage::new(noise_params.width, noise_params.height);
|
let mut img = image::GrayImage::new(noise_params.width, noise_params.height);
|
||||||
let tex: NoiseTexture<Box<dyn noise::NoiseSource>> = match noise_params.noise_source {
|
let tex: NoiseTexture<Box<dyn noise::NoiseSource>> = match noise_params.noise_source {
|
||||||
NoiseSource::Perlin => {
|
NoiseSource::Perlin => {
|
||||||
NoiseTexture::new(Box::new(Perlin::new(rng)), noise_params.noise_type)
|
NoiseTexture::new(Box::new(Perlin::new(&mut rng)), noise_params.noise_type)
|
||||||
|
}
|
||||||
|
NoiseSource::Lode => {
|
||||||
|
NoiseTexture::new(Box::new(Lode::new(&mut rng)), noise_params.noise_type)
|
||||||
}
|
}
|
||||||
NoiseSource::Lode => NoiseTexture::new(Box::new(Lode::new(rng)), noise_params.noise_type),
|
|
||||||
};
|
};
|
||||||
info!("{:?}", noise_params);
|
info!("{:?}", noise_params);
|
||||||
|
|
||||||
@ -364,7 +354,7 @@ fn build_specimens(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn style(_req: &HttpRequest) -> Result<HttpResponse> {
|
fn style(_req: &HttpRequest) -> Result<HttpResponse> {
|
||||||
let bytes = include_bytes!("../../templates/style.css");
|
let bytes = include_bytes!("../templates/style.css");
|
||||||
Ok(HttpResponse::Ok().content_type("text/css").body(&bytes[..]))
|
Ok(HttpResponse::Ok().content_type("text/css").body(&bytes[..]))
|
||||||
}
|
}
|
||||||
|
|
||||||
30
rtiow/renderer/Cargo.toml
Normal file
30
rtiow/renderer/Cargo.toml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[package]
|
||||||
|
name = "renderer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
[[bench]]
|
||||||
|
harness = false
|
||||||
|
name = "spheres"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
chrono = "*"
|
||||||
|
core_affinity = "0.5"
|
||||||
|
cpuprofiler = { version = "0.0.3", optional = true }
|
||||||
|
image = "0.19.0"
|
||||||
|
lazy_static = "1.1.0"
|
||||||
|
log = "0.4.5"
|
||||||
|
num_cpus = "1.8.0"
|
||||||
|
rand = "0.5.5"
|
||||||
|
serde = "1.0.79"
|
||||||
|
serde_derive = "1.0.79"
|
||||||
|
serde_json = "1.0.41"
|
||||||
|
structopt = "0.2.10"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.2"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
profile = ["cpuprofiler"]
|
||||||
|
Before Width: | Height: | Size: 4.4 MiB After Width: | Height: | Size: 4.4 MiB |
|
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 295 KiB |
@ -2,6 +2,7 @@ use std;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use log::info;
|
||||||
use rand;
|
use rand;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ impl BVHNode {
|
|||||||
} else {
|
} else {
|
||||||
let mut l: Vec<Box<dyn Hit>> = l.into_iter().collect();
|
let mut l: Vec<Box<dyn Hit>> = l.into_iter().collect();
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
match rng.gen_range::<u16>(0, 3) {
|
match rng.gen_range(0, 3) {
|
||||||
0 => l.sort_by(box_x_compare),
|
0 => l.sort_by(box_x_compare),
|
||||||
1 => l.sort_by(box_y_compare),
|
1 => l.sort_by(box_y_compare),
|
||||||
2 => l.sort_by(box_z_compare),
|
2 => l.sort_by(box_z_compare),
|
||||||
@ -1,7 +1,7 @@
|
|||||||
extern crate rand;
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
use self::rand::Rng;
|
use rand;
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::ray::Ray;
|
use crate::ray::Ray;
|
||||||
use crate::vec3::cross;
|
use crate::vec3::cross;
|
||||||
@ -11,12 +11,7 @@ fn random_in_unit_disk() -> Vec3 {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let v = Vec3::new(1., 1., 0.);
|
let v = Vec3::new(1., 1., 0.);
|
||||||
loop {
|
loop {
|
||||||
let p =
|
let p = 2. * Vec3::new(rng.gen_range(0., 1.), rng.gen_range(0., 1.), 0.) - v;
|
||||||
2. * Vec3::new(
|
|
||||||
rng.gen_range::<f32>(0., 1.),
|
|
||||||
rng.gen_range::<f32>(0., 1.),
|
|
||||||
0.,
|
|
||||||
) - v;
|
|
||||||
if p.squared_length() < 1. {
|
if p.squared_length() < 1. {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -77,7 +72,7 @@ impl Camera {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let rd = self.lens_radius * random_in_unit_disk();
|
let rd = self.lens_radius * random_in_unit_disk();
|
||||||
let offset = self.u * rd.x + self.v * rd.y;
|
let offset = self.u * rd.x + self.v * rd.y;
|
||||||
let time = self.time_min + rng.gen_range::<f32>(0., 1.) * (self.time_max - self.time_min);
|
let time = self.time_min + rng.gen_range(0., 1.) * (self.time_max - self.time_min);
|
||||||
Ray::new(
|
Ray::new(
|
||||||
self.origin + offset,
|
self.origin + offset,
|
||||||
self.lower_left_corner + self.horizontal * u + self.vertical * v - self.origin - offset,
|
self.lower_left_corner + self.horizontal * u + self.vertical * v - self.origin - offset,
|
||||||
@ -64,10 +64,11 @@ where
|
|||||||
if hit_distance < distance_inside_boundary {
|
if hit_distance < distance_inside_boundary {
|
||||||
let t = rec1.t + hit_distance / r.direction.length();
|
let t = rec1.t + hit_distance / r.direction.length();
|
||||||
let normal = Vec3::new(
|
let normal = Vec3::new(
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
).unit_vector();
|
)
|
||||||
|
.unit_vector();
|
||||||
return Some(HitRecord {
|
return Some(HitRecord {
|
||||||
t,
|
t,
|
||||||
p: r.point_at_parameter(t),
|
p: r.point_at_parameter(t),
|
||||||
@ -1,5 +1,7 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use crate::aabb::surrounding_box;
|
use crate::aabb::surrounding_box;
|
||||||
use crate::aabb::AABB;
|
use crate::aabb::AABB;
|
||||||
use crate::hitable::Hit;
|
use crate::hitable::Hit;
|
||||||
@ -21,13 +21,3 @@ pub mod sphere;
|
|||||||
pub mod texture;
|
pub mod texture;
|
||||||
pub mod translate;
|
pub mod translate;
|
||||||
pub mod vec3;
|
pub mod vec3;
|
||||||
|
|
||||||
extern crate image;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate num_cpus;
|
|
||||||
extern crate rand;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate structopt;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
extern crate rand;
|
use rand;
|
||||||
use self::rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::hitable::HitRecord;
|
use crate::hitable::HitRecord;
|
||||||
use crate::ray::Ray;
|
use crate::ray::Ray;
|
||||||
@ -15,9 +15,9 @@ fn random_in_unit_sphere() -> Vec3 {
|
|||||||
loop {
|
loop {
|
||||||
let p =
|
let p =
|
||||||
2. * Vec3::new(
|
2. * Vec3::new(
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
rng.gen_range::<f32>(0., 1.),
|
rng.gen_range(0., 1.),
|
||||||
) - v;
|
) - v;
|
||||||
if p.squared_length() < 1. {
|
if p.squared_length() < 1. {
|
||||||
return p;
|
return p;
|
||||||
@ -201,7 +201,7 @@ impl Material for Dielectric {
|
|||||||
let scattered = if let Some(refracted) = refract(r_in.direction, outward_normal, ni_over_nt)
|
let scattered = if let Some(refracted) = refract(r_in.direction, outward_normal, ni_over_nt)
|
||||||
{
|
{
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
if rng.gen_range::<f32>(0., 1.) < schlick(cosine, self.ref_idx) {
|
if rng.gen_range(0., 1.) < schlick(cosine, self.ref_idx) {
|
||||||
Ray::new(rec.p, reflected, r_in.time)
|
Ray::new(rec.p, reflected, r_in.time)
|
||||||
} else {
|
} else {
|
||||||
Ray::new(rec.p, refracted, r_in.time)
|
Ray::new(rec.p, refracted, r_in.time)
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
use log::trace;
|
||||||
/// Implements the concepts from https://lodev.org/cgtutor/randomnoise.html
|
/// Implements the concepts from https://lodev.org/cgtutor/randomnoise.html
|
||||||
use rand;
|
use rand;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ impl Lode {
|
|||||||
for x in 0..NOISE_SIZE {
|
for x in 0..NOISE_SIZE {
|
||||||
for y in 0..NOISE_SIZE {
|
for y in 0..NOISE_SIZE {
|
||||||
for z in 0..NOISE_SIZE {
|
for z in 0..NOISE_SIZE {
|
||||||
noise[x][y][z] = rng.gen_range::<f32>(0., 1.);
|
noise[x][y][z] = rng.gen_range(0., 1.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,8 @@ pub mod perlin;
|
|||||||
|
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
|
||||||
use crate::vec3::Vec3;
|
use crate::vec3::Vec3;
|
||||||
|
|
||||||
pub trait NoiseSource: Send + Sync {
|
pub trait NoiseSource: Send + Sync {
|
||||||
@ -1,5 +1,6 @@
|
|||||||
// There are many math functions in this file, so we allow single letter variable names.
|
// There are many math functions in this file, so we allow single letter variable names.
|
||||||
#![allow(clippy::many_single_char_names)]
|
#![allow(clippy::many_single_char_names)]
|
||||||
|
use log::trace;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::noise::NoiseSource;
|
use crate::noise::NoiseSource;
|
||||||
@ -20,9 +21,9 @@ where
|
|||||||
(0..256)
|
(0..256)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
Vec3::new(
|
Vec3::new(
|
||||||
rng.gen_range::<f32>(-1., 1.),
|
rng.gen_range(-1., 1.),
|
||||||
rng.gen_range::<f32>(-1., 1.),
|
rng.gen_range(-1., 1.),
|
||||||
rng.gen_range::<f32>(-1., 1.),
|
rng.gen_range(-1., 1.),
|
||||||
)
|
)
|
||||||
.unit_vector()
|
.unit_vector()
|
||||||
})
|
})
|
||||||
@ -10,6 +10,7 @@ use chrono::Local;
|
|||||||
use image;
|
use image;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
use crate::renderer::Scene;
|
use crate::renderer::Scene;
|
||||||
use crate::vec3::Vec3;
|
use crate::vec3::Vec3;
|
||||||
@ -14,9 +14,13 @@ use std::thread;
|
|||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
use core_affinity;
|
use core_affinity;
|
||||||
|
use log::info;
|
||||||
|
use log::trace;
|
||||||
use num_cpus;
|
use num_cpus;
|
||||||
use rand;
|
use rand;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
use crate::hitable::Hit;
|
use crate::hitable::Hit;
|
||||||
@ -362,8 +366,8 @@ fn trace_pixel_adaptive(
|
|||||||
|
|
||||||
fn trace_pixel_random(x: usize, y: usize, scene: &Scene) -> (Vec3, usize) {
|
fn trace_pixel_random(x: usize, y: usize, scene: &Scene) -> (Vec3, usize) {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let u = (rng.gen_range::<f32>(0., 1.) + x as f32) / scene.width as f32;
|
let u = (rng.gen_range(0., 1.) + x as f32) / scene.width as f32;
|
||||||
let v = (rng.gen_range::<f32>(0., 1.) + y as f32) / scene.height as f32;
|
let v = (rng.gen_range(0., 1.) + y as f32) / scene.height as f32;
|
||||||
let ray = scene.camera.get_ray(u, v);
|
let ray = scene.camera.get_ray(u, v);
|
||||||
color(
|
color(
|
||||||
ray,
|
ray,
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
use log::trace;
|
||||||
use rand;
|
use rand;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
@ -36,9 +37,9 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
let len = 1000;
|
let len = 1000;
|
||||||
for x in 0..len {
|
for x in 0..len {
|
||||||
for z in 0..len {
|
for z in 0..len {
|
||||||
let r = rng.gen_range::<f32>(0., 1.);
|
let r = rng.gen_range(0., 1.);
|
||||||
let g = rng.gen_range::<f32>(0., 1.);
|
let g = rng.gen_range(0., 1.);
|
||||||
let b = rng.gen_range::<f32>(0., 1.);
|
let b = rng.gen_range(0., 1.);
|
||||||
|
|
||||||
let x_pos = (x - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
|
let x_pos = (x - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
|
||||||
let z_pos = (z - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
|
let z_pos = (z - len / 2) as f32 + rng.gen_range(-0.1, 0.1);
|
||||||
@ -81,7 +81,7 @@ where
|
|||||||
1000.,
|
1000.,
|
||||||
ground_material,
|
ground_material,
|
||||||
))];
|
))];
|
||||||
let mut random = || rng.gen_range::<f32>(0., 1.);
|
let mut random = || rng.gen_range(0., 1.);
|
||||||
|
|
||||||
for a in -11..11 {
|
for a in -11..11 {
|
||||||
for b in -11..11 {
|
for b in -11..11 {
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
use log::trace;
|
||||||
|
|
||||||
use crate::bvh::BVH;
|
use crate::bvh::BVH;
|
||||||
use crate::camera::Camera;
|
use crate::camera::Camera;
|
||||||
use crate::hitable::Hit;
|
use crate::hitable::Hit;
|
||||||
@ -64,7 +64,7 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
let z0 = -1000. + j as f32 * w;
|
let z0 = -1000. + j as f32 * w;
|
||||||
let y0 = 0.;
|
let y0 = 0.;
|
||||||
let x1 = x0 + w;
|
let x1 = x0 + w;
|
||||||
let y1 = 100. * (rng.gen_range::<f32>(0., 1.) + 0.01);
|
let y1 = 100. * (rng.gen_range(0., 1.) + 0.01);
|
||||||
let z1 = z0 + w;
|
let z1 = z0 + w;
|
||||||
boxlist.push(Box::new(Cuboid::new(
|
boxlist.push(Box::new(Cuboid::new(
|
||||||
Vec3::new(x0, y0, z0),
|
Vec3::new(x0, y0, z0),
|
||||||
@ -152,9 +152,9 @@ pub fn new(opt: &Opt) -> Scene {
|
|||||||
for _ in 0..ns {
|
for _ in 0..ns {
|
||||||
boxlist.push(Box::new(Sphere::new(
|
boxlist.push(Box::new(Sphere::new(
|
||||||
[
|
[
|
||||||
165. * rng.gen_range::<f32>(0., 1.),
|
165. * rng.gen_range(0., 1.),
|
||||||
165. * rng.gen_range::<f32>(0., 1.),
|
165. * rng.gen_range(0., 1.),
|
||||||
165. * rng.gen_range::<f32>(0., 1.),
|
165. * rng.gen_range(0., 1.),
|
||||||
],
|
],
|
||||||
10.,
|
10.,
|
||||||
Arc::clone(&white),
|
Arc::clone(&white),
|
||||||
@ -33,7 +33,7 @@ fn hsv_to_rgb(h: f32, s: f32, v: f32) -> Vec3 {
|
|||||||
|
|
||||||
fn generate_palette(num: usize) -> Vec<Vec3> {
|
fn generate_palette(num: usize) -> Vec<Vec3> {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let mut random = || rng.gen_range::<f32>(0.0, 0.1);
|
let mut random = || rng.gen_range(0.0, 0.1);
|
||||||
// use golden ratio
|
// use golden ratio
|
||||||
let golden_ratio_conjugate = 0.618_034;
|
let golden_ratio_conjugate = 0.618_034;
|
||||||
let mut h = random();
|
let mut h = random();
|
||||||
@ -9,6 +9,9 @@ use std::ops::Neg;
|
|||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
|
use serde_derive::Deserialize;
|
||||||
|
use serde_derive::Serialize;
|
||||||
|
|
||||||
#[derive(Default, Debug, Deserialize, Serialize, PartialEq, Copy, Clone)]
|
#[derive(Default, Debug, Deserialize, Serialize, PartialEq, Copy, Clone)]
|
||||||
pub struct Vec3 {
|
pub struct Vec3 {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
@ -1,18 +0,0 @@
|
|||||||
fn main() -> Result<(), std::io::Error> {
|
|
||||||
let nx = 200;
|
|
||||||
let ny = 100;
|
|
||||||
println!("P3\n{} {}\n255", nx, ny);
|
|
||||||
for j in (0..ny).rev() {
|
|
||||||
for i in 0..nx {
|
|
||||||
let r = i as f32 / nx as f32;
|
|
||||||
let g = j as f32 / ny as f32;
|
|
||||||
let b = 0.2;
|
|
||||||
|
|
||||||
let ir = (255.99 * r) as u8;
|
|
||||||
let ig = (255.99 * g) as u8;
|
|
||||||
let ib = (255.99 * b) as u8;
|
|
||||||
println!("{} {} {}", ir, ig, ib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
extern crate rtiow;
|
|
||||||
|
|
||||||
use rtiow::vec3::Vec3;
|
|
||||||
|
|
||||||
fn main() -> Result<(), std::io::Error> {
|
|
||||||
let nx = 200;
|
|
||||||
let ny = 100;
|
|
||||||
println!("P3\n{} {}\n255", nx, ny);
|
|
||||||
for j in (0..ny).rev() {
|
|
||||||
for i in 0..nx {
|
|
||||||
let col = Vec3::new(i as f32 / nx as f32, j as f32 / ny as f32, 0.2);
|
|
||||||
|
|
||||||
let ir = (255.99 * col[0]) as u8;
|
|
||||||
let ig = (255.99 * col[1]) as u8;
|
|
||||||
let ib = (255.99 * col[2]) as u8;
|
|
||||||
println!("{} {} {}", ir, ig, ib);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
13
rtiow/tracer/Cargo.toml
Normal file
13
rtiow/tracer/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[package]
|
||||||
|
name = "tracer"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bill Thiede <git@xinu.tv>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
log = "0.4.5"
|
||||||
|
renderer = { path = "../renderer" }
|
||||||
|
stderrlog = "0.4.1"
|
||||||
|
structopt = "0.2.10"
|
||||||
@ -1,21 +1,14 @@
|
|||||||
#[macro_use]
|
#![warn(unused_extern_crates)]
|
||||||
extern crate log;
|
|
||||||
extern crate chrono;
|
|
||||||
#[cfg(feature = "profile")]
|
|
||||||
extern crate cpuprofiler;
|
|
||||||
extern crate rand;
|
|
||||||
extern crate rtiow;
|
|
||||||
extern crate stderrlog;
|
|
||||||
extern crate structopt;
|
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[cfg(feature = "profile")]
|
#[cfg(feature = "profile")]
|
||||||
use cpuprofiler::PROFILER;
|
use cpuprofiler::PROFILER;
|
||||||
|
use log::info;
|
||||||
|
use stderrlog;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
use rtiow::renderer::render;
|
use renderer::renderer::render;
|
||||||
use rtiow::renderer::Opt;
|
use renderer::renderer::Opt;
|
||||||
|
|
||||||
#[cfg(not(feature = "profile"))]
|
#[cfg(not(feature = "profile"))]
|
||||||
struct MockTimer;
|
struct MockTimer;
|
||||||
@ -1,3 +1,3 @@
|
|||||||
export RUSTFLAGS="-D warnings"
|
export RUSTFLAGS="-D warnings"
|
||||||
cargo watch -x 'build' \
|
cargo watch -x 'build --all' \
|
||||||
-x 'build --features=profile' \
|
-x 'build --all --features=profile'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user