diff options
-rw-r--r-- | libdimension/cube.c | 12 | ||||
-rw-r--r-- | libdimension/diffuse.c | 2 | ||||
-rw-r--r-- | libdimension/raytrace.c | 3 | ||||
-rw-r--r-- | libdimension/reflective.c | 2 | ||||
-rw-r--r-- | libdimension/sphere.c | 4 |
5 files changed, 10 insertions, 13 deletions
diff --git a/libdimension/cube.c b/libdimension/cube.c index 9815eb6..9588f24 100644 --- a/libdimension/cube.c +++ b/libdimension/cube.c @@ -64,7 +64,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(-copysign(1.0, line.n.x), 0.0, 0.0); + normal = dmnsn_new_vector(-1.0, 0.0, 0.0); } /* x = 1.0 */ @@ -74,7 +74,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(-copysign(1.0, line.n.x), 0.0, 0.0); + normal = dmnsn_new_vector(1.0, 0.0, 0.0); } } @@ -86,7 +86,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(0.0, -copysign(1.0, line.n.y), 0.0); + normal = dmnsn_new_vector(0.0, -1.0, 0.0); } /* y = 1.0 */ @@ -96,7 +96,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(0.0, -copysign(1.0, line.n.y), 0.0); + normal = dmnsn_new_vector(0.0, 1.0, 0.0); } } @@ -108,7 +108,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(0.0, 0.0, -copysign(1.0, line.n.z)); + normal = dmnsn_new_vector(0.0, 0.0, -1.0); } /* z = 1.0 */ @@ -118,7 +118,7 @@ dmnsn_cube_intersection_fn(const dmnsn_object *cube, dmnsn_line line) && t_temp >= 0.0 && (t < 0.0 || t_temp < t)) { t = t_temp; - normal = dmnsn_new_vector(0.0, 0.0, -copysign(1.0, line.n.z)); + normal = dmnsn_new_vector(0.0, 0.0, 1.0); } } diff --git a/libdimension/diffuse.c b/libdimension/diffuse.c index 75d4c52..910e23f 100644 --- a/libdimension/diffuse.c +++ b/libdimension/diffuse.c @@ -32,7 +32,7 @@ dmnsn_diffuse_finish_fn(const dmnsn_finish *finish, dmnsn_vector ray, dmnsn_vector normal) { double *diffuse = finish->ptr; - double diffuse_factor = (*diffuse)*dmnsn_vector_dot(ray, normal); + double diffuse_factor = fabs((*diffuse)*dmnsn_vector_dot(ray, normal)); dmnsn_color ret = dmnsn_color_mul(diffuse_factor, dmnsn_color_illuminate(light, color)); ret.filter = 0.0; diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 3fa873c..826cc58 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -323,7 +323,8 @@ dmnsn_raytrace_light_ray(const dmnsn_raytrace_state *state, shadow_ray = dmnsn_line_add_epsilon(shadow_ray); /* Check if we're casting a shadow on ourself */ - if (dmnsn_vector_dot(shadow_ray.n, state->intersection->normal) < 0.0) + if (dmnsn_vector_dot(shadow_ray.n, state->intersection->normal) + * dmnsn_vector_dot(state->viewer, state->intersection->normal) < 0.0) return dmnsn_black; dmnsn_color color = (*light->light_fn)(light, state->r); diff --git a/libdimension/reflective.c b/libdimension/reflective.c index 9667072..726bf8d 100644 --- a/libdimension/reflective.c +++ b/libdimension/reflective.c @@ -37,7 +37,7 @@ dmnsn_reflective_finish_fn(const dmnsn_finish *finish, dmnsn_vector ray, dmnsn_vector normal) { dmnsn_reflection_params *params = finish->ptr; - double reflection = pow(dmnsn_vector_dot(ray, normal), params->falloff); + double reflection = pow(fabs(dmnsn_vector_dot(ray, normal)), params->falloff); return dmnsn_color_illuminate( dmnsn_color_gradient(params->min, params->max, reflection), diff --git a/libdimension/sphere.c b/libdimension/sphere.c index d994248..f30c964 100644 --- a/libdimension/sphere.c +++ b/libdimension/sphere.c @@ -74,10 +74,6 @@ dmnsn_sphere_intersection_fn(const dmnsn_object *sphere, dmnsn_line line) intersection->normal = dmnsn_line_point(line, t); intersection->texture = sphere->texture; intersection->interior = sphere->interior; - - /* Flip the normal if we're inside the sphere */ - if (dmnsn_vector_dot(line.n, intersection->normal) > 0.0) - intersection->normal = dmnsn_vector_negate(intersection->normal); } } |