From 08f9ee167a62148e301bfcbf1f8445624256b2c9 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 5 Apr 2023 02:08:54 -0500 Subject: [PATCH] Finalize --- assignment-1d/.gitignore | 4 +-- assignment-1d/Cargo.lock | 1 + assignment-1d/Cargo.toml | 4 +++ assignment-1d/Makefile | 2 +- .../sample-1-but-only-transparent.txt | 18 ++++++++++++ assignment-1d/examples/surface-reflect.txt | 29 +++++++++++++++++++ assignment-1d/src/scene/illumination.rs | 16 ++++++---- assignment-1d/src/scene/input_file/mod.rs | 6 ++++ 8 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 assignment-1d/examples/sample-1-but-only-transparent.txt create mode 100644 assignment-1d/examples/surface-reflect.txt diff --git a/assignment-1d/.gitignore b/assignment-1d/.gitignore index 59b392f..5a7d825 100644 --- a/assignment-1d/.gitignore +++ b/assignment-1d/.gitignore @@ -1,6 +1,6 @@ /target -/assignment-1c -/raytracer1c +/assignment-1* +/raytracer1* /examples/*.png *.ppm *.zip diff --git a/assignment-1d/Cargo.lock b/assignment-1d/Cargo.lock index 5b92be1..ff642ec 100644 --- a/assignment-1d/Cargo.lock +++ b/assignment-1d/Cargo.lock @@ -44,6 +44,7 @@ dependencies = [ "clap", "contracts", "derivative", + "either", "generator", "itertools", "nalgebra", diff --git a/assignment-1d/Cargo.toml b/assignment-1d/Cargo.toml index 79a6fc3..2c218b4 100644 --- a/assignment-1d/Cargo.toml +++ b/assignment-1d/Cargo.toml @@ -14,6 +14,9 @@ inherits = "release" strip = true lto = true +[features] +release-handin = ["tracing/release_max_level_info"] + [[bin]] name = "raytracer1d" path = "src/main.rs" @@ -24,6 +27,7 @@ base64 = "0.21.0" clap = { version = "4.1.4", features = ["cargo", "derive"] } contracts = "0.6.3" derivative = "2.2.0" +either = "1.8.1" generator = "0.7.2" itertools = "0.10.5" nalgebra = "0.32.1" diff --git a/assignment-1d/Makefile b/assignment-1d/Makefile index 38331d7..7e0361f 100644 --- a/assignment-1d/Makefile +++ b/assignment-1d/Makefile @@ -35,7 +35,7 @@ $(BINARY): $(SOURCES) -w /usr/src/myapp \ -e CARGO_TARGET_DIR=/usr/src/myapp/target/docker \ rust \ - cargo build --profile release-handin + cargo build --profile release-handin --features release-handin mv target/docker/release-handin/raytracer1d $@ $(HANDIN): $(BINARY) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM) diff --git a/assignment-1d/examples/sample-1-but-only-transparent.txt b/assignment-1d/examples/sample-1-but-only-transparent.txt new file mode 100644 index 000000000..057dbab --- /dev/null +++ b/assignment-1d/examples/sample-1-but-only-transparent.txt @@ -0,0 +1,18 @@ +eye 0 5 0 +viewdir 0 0 1 +updir 0 1 0 +hfov 45 +imsize 128 128 +bkgcolor 0.5 0.7 0.9 1 +light 0 -1 0 0 1 1 1 +mtlcolor 1 1 1 1 1 1 0.2 0.4 0.6 60 0.2 1.5 +sphere 0 6 15 3 + +mtlcolor 1 1 1 1 1 1 0.2 0.8 0 20 1 0 +v 10 0 5 +v -10 0 5 +v -10 0 25 +v 10 0 25 + +f 1 2 3 +f 1 3 4 diff --git a/assignment-1d/examples/surface-reflect.txt b/assignment-1d/examples/surface-reflect.txt new file mode 100644 index 000000000..94ae0e3 --- /dev/null +++ b/assignment-1d/examples/surface-reflect.txt @@ -0,0 +1,29 @@ +imsize 1366 768 +eye 0 5 -2 +viewdir 0 -0.2 1 +hfov 60 +updir 0 1 0 +bkgcolor 0.4 0.5 0.6 +depthcueing 0.5 0.5 0.5 1 0.4 60 0 +light 0 -1 0 0 1 1 1 + +mtlcolor 1 0.6 0.6 1 1 1 0.2 0.4 0.6 60 0.9 2 +sphere -1.5 4 15 1 + +mtlcolor 0.6 0.6 1 1 1 1 0.2 0.4 0.6 60 0.9 2 +sphere 0 -1 12 2 + +mtlcolor 0.6 1 0.6 1 1 1 0.2 0.4 0.6 60 1 2 +sphere 6 8 20 3 + +mtlcolor 1 1 0.6 1 1 1 0.2 0.4 0.6 60 0.9 2 +sphere -6 -8 20 4 + +mtlcolor 0.7 0.6 0.8 0.5 0.5 0.5 0.2 0.8 0.1 20 0.5 1.5 +v 10 0 5 +v -10 0 5 +v -10 0 25 +v 10 0 25 + +f 1 2 3 +f 1 3 4 diff --git a/assignment-1d/src/scene/illumination.rs b/assignment-1d/src/scene/illumination.rs index 0b5e7c8..13e4b11 100644 --- a/assignment-1d/src/scene/illumination.rs +++ b/assignment-1d/src/scene/illumination.rs @@ -172,7 +172,7 @@ impl Scene { ); // This is the result of the Phong illumination equation. - let color = ambient_component + diffuse_and_specular + { + let color = (ambient_component + diffuse_and_specular) + { // This part is all the transparency + reflection stuff fresnel_coefficient * specular_reflection_component + (1.0 - fresnel_coefficient) @@ -301,17 +301,21 @@ impl Scene { match intersections.is_empty() { true => 1.0, false => { - let average = - intersections.iter().map(|s| s.shadow_opacity).sum::() - / intersections.len() as f64; + // let average = + // intersections.iter().map(|s| s.shadow_opacity).sum::() + // / intersections.len() as f64; - // S * (1 - a_0) * (1 - a_1) * (...) + // (1 - a_0) * (1 - a_1) * (...) let transparency = intersections .iter() .map(|s| 1.0 - s.transparent_coefficient) .product::(); - average * transparency + // debug!( + // "average {average}, transparency {transparency} = {}", + // average * transparency + // ); + transparency } } } diff --git a/assignment-1d/src/scene/input_file/mod.rs b/assignment-1d/src/scene/input_file/mod.rs index a6c98cc..744b4f2 100644 --- a/assignment-1d/src/scene/input_file/mod.rs +++ b/assignment-1d/src/scene/input_file/mod.rs @@ -44,6 +44,12 @@ impl Scene { let mut texture_idx = None; for line in contents.lines() { + // Comments :) + let line = line.trim(); + if line.starts_with("#") { + continue; + } + // Split lines into words. `parts' is an iterator, which is consumed upon // iterating, rather than collected into a Vec let mut parts = line.split_whitespace();