summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-01-08 17:26:33 -0500
committerTavian Barnes <tavianator@gmail.com>2010-01-09 15:54:35 -0500
commit426482f9848db956095943e9f0983db0d6ab1a0d (patch)
tree90e4cdc0bde959931697e7364347ac855f5ded1b
parent09387c1cb66f26f1a25e7ddee776642d8236cb82 (diff)
downloaddimension-426482f9848db956095943e9f0983db0d6ab1a0d.tar.xz
Clamp negative values in phong shading.
-rw-r--r--libdimension/phong.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libdimension/phong.c b/libdimension/phong.c
index 815885f..637ff52 100644
--- a/libdimension/phong.c
+++ b/libdimension/phong.c
@@ -40,7 +40,12 @@ dmnsn_phong_finish_fn(const dmnsn_finish *finish,
dmnsn_vector proj = dmnsn_vector_mul(2*dmnsn_vector_dot(ray, normal), normal);
dmnsn_vector reflected = dmnsn_vector_sub(proj, ray);
- double specular_factor = pow(dmnsn_vector_dot(reflected, viewer), exp);
+ double specular_factor = dmnsn_vector_dot(reflected, viewer);
+ if (specular_factor < 0.0) {
+ return dmnsn_black;
+ }
+
+ specular_factor = pow(specular_factor, exp);
return dmnsn_color_mul(specular*specular_factor, light);
}