This commit is contained in:
Michael Zhang 2023-04-05 02:08:54 -05:00
parent 75d4e6266f
commit 08f9ee167a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
8 changed files with 71 additions and 9 deletions

View file

@ -1,6 +1,6 @@
/target
/assignment-1c
/raytracer1c
/assignment-1*
/raytracer1*
/examples/*.png
*.ppm
*.zip

View file

@ -44,6 +44,7 @@ dependencies = [
"clap",
"contracts",
"derivative",
"either",
"generator",
"itertools",
"nalgebra",

View file

@ -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"

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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::<f64>()
/ intersections.len() as f64;
// let average =
// intersections.iter().map(|s| s.shadow_opacity).sum::<f64>()
// / 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::<f64>();
average * transparency
// debug!(
// "average {average}, transparency {transparency} = {}",
// average * transparency
// );
transparency
}
}
}

View file

@ -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();