Skip to content

Commit

Permalink
inverse square falloff but I'm cheating
Browse files Browse the repository at this point in the history
  • Loading branch information
float3 committed Apr 2, 2024
1 parent 0abc72b commit 0757472
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
Binary file modified renders/checkered_floor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/cornell_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/mirror_ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified renders/scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 10 additions & 3 deletions src/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ impl Scene {
return Vec3::new([0.0, 0.0, 0.0]);
}
}
// let falloff = 1.0 / (distance_to_light * distance_to_light);
// light.color().scale(falloff)
light.color()
let constant_term = 1.0; // Prevents division by zero at very close distances
let linear_term = 0.1; // Linear falloff factor
let quadratic_term = 0.01; // Quadratic falloff factor (original inverse square law)

let falloff = 1.0
/ (constant_term
+ linear_term * distance_to_light
+ quadratic_term * distance_to_light * distance_to_light);

light.color().scale(falloff)
}

pub fn from_toml(toml: &Value) -> Self {
Expand Down
Binary file modified tests/sample_test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0757472

Please sign in to comment.