diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-01-08 17:26:33 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-01-09 15:54:35 -0500 |
commit | 426482f9848db956095943e9f0983db0d6ab1a0d (patch) | |
tree | 90e4cdc0bde959931697e7364347ac855f5ded1b | |
parent | 09387c1cb66f26f1a25e7ddee776642d8236cb82 (diff) | |
download | dimension-426482f9848db956095943e9f0983db0d6ab1a0d.tar.xz |
Clamp negative values in phong shading.
-rw-r--r-- | libdimension/phong.c | 7 |
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); } |