Skip to content

Commit 3ad7853

Browse files
committed
here begins the rest of my life
1 parent 93b8c35 commit 3ad7853

File tree

6 files changed

+174
-211
lines changed

6 files changed

+174
-211
lines changed

bloom.nb

Lines changed: 0 additions & 166 deletions
This file was deleted.

src/camera.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn camera(
4949
};
5050
}
5151

52-
5352
impl Camera {
5453
pub fn get_ray(&self, rng : &mut Rng, s : f32, t : f32) -> Ray {
5554
let rd = self.lens_radius * rand_in_disk(rng);
@@ -63,3 +62,46 @@ impl Camera {
6362
return ray(&self.origin + offset, dir, time);
6463
}
6564
}
65+
66+
pub struct CameraSetup {
67+
origin : Vec3,
68+
lookat : Vec3,
69+
vup : Vec3,
70+
vfov : f32,
71+
aspect : f32,
72+
aperture : f32,
73+
focus_dist : f32,
74+
time0 : f32,
75+
time1 : f32,
76+
}
77+
78+
pub fn camera_setup(origin : Vec3) -> CameraSetup {
79+
CameraSetup {
80+
origin: origin,
81+
lookat: ZERO3,
82+
vup: ivec3(0, 1, 0),
83+
vfov: 20.0,
84+
aspect: 1.0,
85+
aperture: 0.0,
86+
focus_dist: origin.len(),
87+
time0: 0.0,
88+
time1: 1.0,
89+
}
90+
}
91+
92+
#[allow(dead_code)]
93+
impl CameraSetup {
94+
pub fn look_at(mut self, v : Vec3) -> Self {self.lookat = v; self}
95+
pub fn up(mut self, v : Vec3) -> Self {self.vup = v; self}
96+
pub fn vfov(mut self, f : f32) -> Self {self.vfov = f; self}
97+
pub fn aspect(mut self, (x, y) : (u32, u32)) -> Self {self.aspect = x as f32 / y as f32; self}
98+
pub fn aperture(mut self, f : f32) -> Self {self.aperture = f; self}
99+
pub fn focus_dist(mut self, f : f32) -> Self {self.focus_dist = f; self}
100+
pub fn time(mut self, t0 : f32, t1 : f32) -> Self {self.time0 = t0; self.time1 = t1; self}
101+
102+
pub fn to_camera(self) -> Camera {
103+
camera(self.origin, self.lookat, self.vup,
104+
self.vfov, self.aspect, self.aperture, self.focus_dist,
105+
self.time0, self.time1)
106+
}
107+
}

src/main.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use std::sync::Arc;
2929
use std::thread;
3030
use std::sync::mpsc::{channel, sync_channel, Sender};
3131
use std::io;
32-
use std::io::Write;
32+
use std::io::{Write};
33+
34+
use std::fs;
3335

3436
extern crate image;
3537
extern crate rand;
@@ -38,6 +40,14 @@ extern crate byteorder;
3840
extern crate num;
3941

4042
fn render_overlord(base_rng : &mut Rng, render_task : RenderTask) {
43+
44+
std::mem::drop(fs::OpenOptions::new()
45+
.write(true)
46+
.truncate(true)
47+
.create(true)
48+
.open("foo.txt")
49+
.unwrap());
50+
4151
let render_task = Arc::new(render_task);
4252
let (nx, ny) = render_task.target_size;
4353
let mut main_target = RenderTarget::new(render_task.target_size);
@@ -53,6 +63,7 @@ fn render_overlord(base_rng : &mut Rng, render_task : RenderTask) {
5363
};
5464

5565
let nworkers = num_cpus::get();
66+
// let nworkers = 1;
5667
println!("running with {} threads", nworkers);
5768

5869
let (task_tx, task_rx) = sync_channel::<(usize, RenderTarget)>(0);
@@ -156,6 +167,7 @@ fn render_a_frame(rng : &mut Rng, task : &RenderTask, target : &mut RenderTarget
156167
let r = task.camera.get_ray(rng, u, v);
157168

158169
let col = ray_trace(rng, r, &*task.world);
170+
159171
for i in 0..3 {
160172
target[(x, y)][i] += col[i] as f64;
161173
}
@@ -171,7 +183,7 @@ fn ray_trace(rng : &mut Rng, r0 : Ray, world : &Object) -> Vec3 {
171183
let mut attenuation = vec3(1.0, 1.0, 1.0);
172184
let mut r = r0;
173185
let max_ttl = 50;
174-
for ttl in 0..max_ttl {
186+
for bounce in 0..max_ttl {
175187
match world.hit(rng, &r, (0.001, f32::INFINITY)) {
176188
Some(hit) => {
177189
let emitted = hit.material.emitted(hit.uv, &hit.p);
@@ -207,6 +219,7 @@ fn ray_trace(rng : &mut Rng, r0 : Ray, world : &Object) -> Vec3 {
207219
}
208220
panic!()
209221
}
222+
210223
return accumulator;
211224
}
212225

@@ -219,7 +232,7 @@ fn main() {
219232
println!("let seed = {:?};", seed);
220233
let mut rng : Rng = Rng::from_seed(seed);
221234

222-
let task = the_next_week(&mut rng);
235+
let task = two_spheres(&mut rng);
223236

224237
render_overlord(&mut rng, task);
225238
}

0 commit comments

Comments
 (0)