summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlibdimension-python/tests/color.py3
-rw-r--r--libdimension-python/wrapper.pxd2
-rw-r--r--libdimension-python/wrapper.pyx4
-rw-r--r--libdimension/dimension/color.h10
-rw-r--r--libdimension/raytrace.c27
5 files changed, 15 insertions, 31 deletions
diff --git a/libdimension-python/tests/color.py b/libdimension-python/tests/color.py
index 88e0b42..47ac975 100755
--- a/libdimension-python/tests/color.py
+++ b/libdimension-python/tests/color.py
@@ -48,8 +48,5 @@ assert Orange == Color(1, 0.5, 0), Orange
assert Yellow == Color(1, 1, 0), Yellow
assert Cyan == Color(0, 1, 1), Cyan
-assert White, bool(White)
-assert not Black, not Black
-
assert Red + Blue == Magenta, Red + Blue
assert 0.5*White == Color(0.5, 0.5, 0.5), 0.5*White
diff --git a/libdimension-python/wrapper.pxd b/libdimension-python/wrapper.pxd
index 2526022..920f6f2 100644
--- a/libdimension-python/wrapper.pxd
+++ b/libdimension-python/wrapper.pxd
@@ -162,8 +162,6 @@ cdef extern from "../libdimension/dimension.h":
dmnsn_color dmnsn_color_add(dmnsn_color color1, dmnsn_color color2)
dmnsn_color dmnsn_color_mul(double n, dmnsn_color color)
- bint dmnsn_color_is_black(dmnsn_color color)
-
dmnsn_color dmnsn_black
dmnsn_color dmnsn_white
dmnsn_color dmnsn_clear
diff --git a/libdimension-python/wrapper.pyx b/libdimension-python/wrapper.pyx
index 5f2b755..5431e75 100644
--- a/libdimension-python/wrapper.pyx
+++ b/libdimension-python/wrapper.pyx
@@ -458,10 +458,6 @@ cdef class Color:
def __get__(self):
return self._sRGB.filter
- def __nonzero__(self):
- """Return whether a color is not black."""
- return not dmnsn_color_is_black(self._c)
-
def __add__(lhs, rhs):
return _sRGBColor(dmnsn_color_add(Color(lhs)._sRGB, Color(rhs)._sRGB))
def __mul__(lhs, rhs):
diff --git a/libdimension/dimension/color.h b/libdimension/dimension/color.h
index 9664d22..8470957 100644
--- a/libdimension/dimension/color.h
+++ b/libdimension/dimension/color.h
@@ -71,16 +71,6 @@ dmnsn_new_color5(double R, double G, double B, double trans, double filter)
return ret;
}
-/** Is this color black? */
-DMNSN_INLINE bool
-dmnsn_color_is_black(dmnsn_color color)
-{
- return fabs(color.R) < dmnsn_epsilon
- && fabs(color.G) < dmnsn_epsilon
- && fabs(color.B) < dmnsn_epsilon
- && fabs(color.trans) < dmnsn_epsilon;
-}
-
/** Saturate the color components to [0.0, 1.0]. */
DMNSN_INLINE dmnsn_color
dmnsn_color_saturate(dmnsn_color color)
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c
index 4056f07..3b83618 100644
--- a/libdimension/raytrace.c
+++ b/libdimension/raytrace.c
@@ -229,8 +229,9 @@ dmnsn_trace_pigment(dmnsn_rtstate *state)
}
/** Get the color of a light ray at an intersection point. */
-static dmnsn_color
-dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light)
+static bool
+dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light,
+ dmnsn_color *color)
{
/** @todo: Start at the light source */
dmnsn_line shadow_ray = dmnsn_new_line(
@@ -244,21 +245,23 @@ dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light)
/* Check if we're casting a shadow on ourself */
if (dmnsn_vector_dot(shadow_ray.n, state->intersection->normal)
* dmnsn_vector_dot(state->viewer, state->intersection->normal) < 0.0)
- return dmnsn_black;
+ {
+ return false;
+ }
- dmnsn_color color = light->illumination_fn(light, state->r);
+ *color = light->illumination_fn(light, state->r);
/* Test for shadow ray intersections */
unsigned int reclevel = state->reclevel;
while (reclevel-- > 0
- && dmnsn_color_intensity(color) >= state->scene->adc_bailout)
+ && dmnsn_color_intensity(*color) >= state->scene->adc_bailout)
{
dmnsn_intersection shadow_caster;
bool shadow_was_cast = dmnsn_prtree_intersection(state->prtree, shadow_ray,
&shadow_caster, false);
if (!shadow_was_cast || !light->shadow_fn(light, shadow_caster.t)) {
- return color;
+ return true;
}
/* Handle transparency */
@@ -273,14 +276,14 @@ dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light)
shadow_state.texture->finish.reflection;
if ((state->scene->quality & DMNSN_RENDER_REFLECTION) && reflection) {
dmnsn_color reflected = reflection->reflection_fn(
- reflection, color, shadow_state.pigment, shadow_state.reflected,
+ reflection, *color, shadow_state.pigment, shadow_state.reflected,
shadow_state.intersection->normal
);
- color = dmnsn_color_sub(color, reflected);
+ *color = dmnsn_color_sub(*color, reflected);
}
/* Filter the light */
- color = dmnsn_filter_light(color, shadow_state.pigment);
+ *color = dmnsn_filter_light(*color, shadow_state.pigment);
shadow_ray.x0 = dmnsn_line_point(shadow_ray, shadow_caster.t);
shadow_ray.n = light->direction_fn(light, shadow_ray.x0);
shadow_ray = dmnsn_line_add_epsilon(shadow_ray);
@@ -291,7 +294,7 @@ dmnsn_trace_light_ray(dmnsn_rtstate *state, const dmnsn_light *light)
break;
}
- return dmnsn_black;
+ return false;
}
/** Handle light, shadow, and shading. */
@@ -309,8 +312,8 @@ dmnsn_trace_lighting(dmnsn_rtstate *state)
/* Iterate over each light */
DMNSN_ARRAY_FOREACH (dmnsn_light **, light, state->scene->lights) {
- dmnsn_color light_color = dmnsn_trace_light_ray(state, *light);
- if (!dmnsn_color_is_black(light_color)) {
+ dmnsn_color light_color;
+ if (dmnsn_trace_light_ray(state, *light, &light_color)) {
if (state->scene->quality & DMNSN_RENDER_FINISH) {
/* Reflect the light */
const dmnsn_reflection *reflection = state->texture->finish.reflection;