aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2021-10-28 02:20:45 +0300
committereug-vs <eugene@eug-vs.xyz>2021-10-28 02:20:45 +0300
commit8ed56f554f94dca0ca5ef707eaf8b1cdde3c91e7 (patch)
tree88167d0207f8d9e4afcbf34462b7b172e6260559
parent5ffd25826d8ea286e9176ada64dba3fba65bb55b (diff)
downloadpistol-8ed56f554f94dca0ca5ef707eaf8b1cdde3c91e7.tar.gz
feat: use better softwhadows
-rw-r--r--src/camera.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/camera.rs b/src/camera.rs
index c132e44..054e3b5 100644
--- a/src/camera.rs
+++ b/src/camera.rs
@@ -167,13 +167,14 @@ impl Camera {
}
pub fn light_point(&self, point: Vector) -> f32 {
- let base_light = 0.1;
+ let base_light = 0.01;
return base_light + (1.0 - base_light) * (self.apply_shadow(point) * 0.7 + self.apply_ambient(point) * 0.3)
}
pub fn apply_shadow(&self, point: Vector) -> f32 {
let mut res: f32 = 1.0;
- let mut t = 0.001;
+ let mut ph = 1e20;
+ let mut t = 0.1;
let k = 4.0;
while t < 7.0 {
@@ -181,8 +182,11 @@ impl Camera {
if h < 0.001 {
return 0.00
}
- res = res.min(k * h / t);
+ let y = h * h / (2.0 * ph);
+ let d = (h * h - y * y).sqrt();
+ res = res.min(k * d / (t - y).max(0.0));
t += h;
+ ph = h;
}
return res