summaryrefslogtreecommitdiff
path: root/src/modules/ray/ray_scene.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-08-08 09:42:30 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-08-15 16:46:40 -0700
commitadb76b79d39a185be4659193baff0cb1fe043506 (patch)
treefdc51e2d986e7ef6bd22d0897bdbca10ed51f550 /src/modules/ray/ray_scene.c
parent760112de102f36ba5aaf16d9e949d0bfa3623175 (diff)
ray: misc computational fixups
ray:object intersection coordinates were incorrectly being computed relative to the ray origin using a subtraction instead of addition, a silly mistake with surprisingly acceptable results. Those results were a result of other minor complementary mistakes compensating to produce reasonable looking results. In the course of experimenting with an acceleration data structure it became very apparent that 3d space traversal vectors were not behaving as intended, leading to review and correction of this code.
Diffstat (limited to 'src/modules/ray/ray_scene.c')
-rw-r--r--src/modules/ray/ray_scene.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/modules/ray/ray_scene.c b/src/modules/ray/ray_scene.c
index 2ad7f99..2026f6d 100644
--- a/src/modules/ray/ray_scene.c
+++ b/src/modules/ray/ray_scene.c
@@ -36,13 +36,8 @@ static inline int point_is_shadowed(ray_scene_t *scene, unsigned depth, ray_3f_t
{
ray_ray_t shadow_ray;
- /* negate the light vector so it's pointed at the light rather than from it */
- shadow_ray.direction = ray_3f_negate(light_direction);
-
- /* we must shift the origin slightly (epsilon) towards the light to
- * prevent spurious self-obstruction at the ray:object intersection */
- shadow_ray.origin = ray_3f_mult_scalar(&shadow_ray.direction, 0.00001f);
- shadow_ray.origin = ray_3f_add(&shadow_ray.origin, point);
+ shadow_ray.direction = *light_direction;
+ shadow_ray.origin = *point;
if (ray_is_obstructed(scene, depth + 1, &shadow_ray, distance))
return 1;
@@ -85,13 +80,14 @@ static inline ray_color_t shade_intersection(ray_scene_t *scene, ray_object_t *o
#if 1
float rvec_lvec_dot = ray_3f_dot(&ray->direction, &lvec);
ray_color_t diffuse;
- ray_color_t specular;
diffuse = ray_3f_mult_scalar(&surface.color, lvec_normal_dot);
diffuse = ray_3f_mult_scalar(&diffuse, surface.diffuse);
color = ray_3f_add(&color, &diffuse);
if (rvec_lvec_dot > 0) {
+ ray_color_t specular;
+
/* FIXME: assumes light is a point for its color */
specular = ray_3f_mult_scalar(&scene->lights[i].light.emitter.point.surface.color, approx_powf(rvec_lvec_dot, surface.highlight_exponent));
specular = ray_3f_mult_scalar(&specular, surface.specular);
@@ -178,7 +174,7 @@ static inline ray_color_t trace_ray(ray_scene_t *scene, ray_ray_t *primary_ray)
ray_3f_t rvec;
rvec = ray_3f_mult_scalar(&ray->direction, nearest_distance);
- intersection = ray_3f_sub(&ray->origin, &rvec);
+ intersection = ray_3f_add(&ray->origin, &rvec);
normal = ray_object_normal(nearest_object, &intersection);
more_color = shade_intersection(scene, nearest_object, ray, &intersection, &normal, depth, &reflectivity);
© All Rights Reserved