Finalize
This commit is contained in:
parent
75d4e6266f
commit
08f9ee167a
8 changed files with 71 additions and 9 deletions
4
assignment-1d/.gitignore
vendored
4
assignment-1d/.gitignore
vendored
|
@ -1,6 +1,6 @@
|
||||||
/target
|
/target
|
||||||
/assignment-1c
|
/assignment-1*
|
||||||
/raytracer1c
|
/raytracer1*
|
||||||
/examples/*.png
|
/examples/*.png
|
||||||
*.ppm
|
*.ppm
|
||||||
*.zip
|
*.zip
|
||||||
|
|
1
assignment-1d/Cargo.lock
generated
1
assignment-1d/Cargo.lock
generated
|
@ -44,6 +44,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"contracts",
|
"contracts",
|
||||||
"derivative",
|
"derivative",
|
||||||
|
"either",
|
||||||
"generator",
|
"generator",
|
||||||
"itertools",
|
"itertools",
|
||||||
"nalgebra",
|
"nalgebra",
|
||||||
|
|
|
@ -14,6 +14,9 @@ inherits = "release"
|
||||||
strip = true
|
strip = true
|
||||||
lto = true
|
lto = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
release-handin = ["tracing/release_max_level_info"]
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "raytracer1d"
|
name = "raytracer1d"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
@ -24,6 +27,7 @@ base64 = "0.21.0"
|
||||||
clap = { version = "4.1.4", features = ["cargo", "derive"] }
|
clap = { version = "4.1.4", features = ["cargo", "derive"] }
|
||||||
contracts = "0.6.3"
|
contracts = "0.6.3"
|
||||||
derivative = "2.2.0"
|
derivative = "2.2.0"
|
||||||
|
either = "1.8.1"
|
||||||
generator = "0.7.2"
|
generator = "0.7.2"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
nalgebra = "0.32.1"
|
nalgebra = "0.32.1"
|
||||||
|
|
|
@ -35,7 +35,7 @@ $(BINARY): $(SOURCES)
|
||||||
-w /usr/src/myapp \
|
-w /usr/src/myapp \
|
||||||
-e CARGO_TARGET_DIR=/usr/src/myapp/target/docker \
|
-e CARGO_TARGET_DIR=/usr/src/myapp/target/docker \
|
||||||
rust \
|
rust \
|
||||||
cargo build --profile release-handin
|
cargo build --profile release-handin --features release-handin
|
||||||
mv target/docker/release-handin/raytracer1d $@
|
mv target/docker/release-handin/raytracer1d $@
|
||||||
|
|
||||||
$(HANDIN): $(BINARY) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM)
|
$(HANDIN): $(BINARY) Makefile Cargo.toml Cargo.lock README.md $(EXAMPLES_PNG) $(EXAMPLES_PPM)
|
||||||
|
|
18
assignment-1d/examples/sample-1-but-only-transparent.txt
Normal file
18
assignment-1d/examples/sample-1-but-only-transparent.txt
Normal 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
|
29
assignment-1d/examples/surface-reflect.txt
Normal file
29
assignment-1d/examples/surface-reflect.txt
Normal 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
|
|
@ -172,7 +172,7 @@ impl Scene {
|
||||||
);
|
);
|
||||||
|
|
||||||
// This is the result of the Phong illumination equation.
|
// 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
|
// This part is all the transparency + reflection stuff
|
||||||
fresnel_coefficient * specular_reflection_component
|
fresnel_coefficient * specular_reflection_component
|
||||||
+ (1.0 - fresnel_coefficient)
|
+ (1.0 - fresnel_coefficient)
|
||||||
|
@ -301,17 +301,21 @@ impl Scene {
|
||||||
match intersections.is_empty() {
|
match intersections.is_empty() {
|
||||||
true => 1.0,
|
true => 1.0,
|
||||||
false => {
|
false => {
|
||||||
let average =
|
// let average =
|
||||||
intersections.iter().map(|s| s.shadow_opacity).sum::<f64>()
|
// intersections.iter().map(|s| s.shadow_opacity).sum::<f64>()
|
||||||
/ intersections.len() as f64;
|
// / intersections.len() as f64;
|
||||||
|
|
||||||
// S * (1 - a_0) * (1 - a_1) * (...)
|
// (1 - a_0) * (1 - a_1) * (...)
|
||||||
let transparency = intersections
|
let transparency = intersections
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| 1.0 - s.transparent_coefficient)
|
.map(|s| 1.0 - s.transparent_coefficient)
|
||||||
.product::<f64>();
|
.product::<f64>();
|
||||||
|
|
||||||
average * transparency
|
// debug!(
|
||||||
|
// "average {average}, transparency {transparency} = {}",
|
||||||
|
// average * transparency
|
||||||
|
// );
|
||||||
|
transparency
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,12 @@ impl Scene {
|
||||||
let mut texture_idx = None;
|
let mut texture_idx = None;
|
||||||
|
|
||||||
for line in contents.lines() {
|
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
|
// Split lines into words. `parts' is an iterator, which is consumed upon
|
||||||
// iterating, rather than collected into a Vec
|
// iterating, rather than collected into a Vec
|
||||||
let mut parts = line.split_whitespace();
|
let mut parts = line.split_whitespace();
|
||||||
|
|
Loading…
Reference in a new issue