summaryrefslogtreecommitdiffstats
path: root/libdimension
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension')
-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);
}