diff options
author | Julian T <julian@jtle.dk> | 2021-02-03 17:29:27 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-03 17:29:27 +0100 |
commit | 977b0e4152433b2a68e2b97fe5fe2c0ff6fb20d8 (patch) | |
tree | 9c1eccef2ede2507e7d29a0daf44d56c76036415 /src/main.rs | |
parent | 8296be848319eecd43f94900d4d12414ec189166 (diff) |
Can render a simple sphere, without shading
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 22998dd..05d6617 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,37 @@ -use pathtrace::camera::Camera; -use pathtrace::core::{Vector3f, Vector2f}; - +use pathtrace::camera::{Camera, Film}; +use pathtrace::scene::Scene; +use pathtrace::scene::shapes::Sphere; +use pathtrace::core::{Vector2i, Vector3f}; +use pathtrace::render::{RenderContext, RenderTask}; fn main() { + let res = Vector2i::new_xy(500, 500); let cam = Camera::new( - Vector3f::new(10.0), - Vector3f::new(0.0), - Vector3f::new_xyz(0.0, 1.0, 0.0), - 90.0, Vector2f::new(10.0), + Vector3f::new_xyz(10.0, 0.0, 0.0), + Vector3f::new(0.0), + Vector3f::new_xyz(0.0, 0.1, 0.0), + 90.0, res, + ); + + let mut scn = Scene::new(); + scn.add_shape( + Box::new(Sphere::new(4.0, Vector3f::new(0.0))), ); - let (r, _) = cam.generate_ray(Vector2f::new(5.0)); + let ctx = RenderContext { cam: &cam, scn: &scn }; + + let mut film = Film::new(res); + let tile = film.get_tile(&film.frame); + + let mut task = RenderTask::new(Box::new(tile), 1); + task.render(&ctx); + + film.commit_tile(&task.tile); + + let image = film.finalize_image(); + if let Err(e) = image.save("test.png") { + println!("Failed to save {}", e); + } - println!("r: {}, norm: {}", r.direction, r.direction.norm()); } |