From 121846b0e35607bf8b48d5ce304a65e2657be455 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 13 Sep 2017 13:55:22 -0700 Subject: ray: cleanup ray_camera_frame_t fragments Previously every fb_fragment_t (and thus thread) was constructing its own ray_camera_frame_t view into the scene, duplicating some work. Instead introduce ray_camera_fragment_t to encapsulate the truly per-fragment state and make ray_scene_render_fragment() operate on just this stuff with a reference to a shared ray_camera_frame_t prepared once per-frame. Some minor ray_camera.c cleanups sneak in as well (prefer multiply instead of divide, whitespace cleanups...) --- src/modules/ray/ray_camera.h | 59 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 26 deletions(-) (limited to 'src/modules/ray/ray_camera.h') diff --git a/src/modules/ray/ray_camera.h b/src/modules/ray/ray_camera.h index 191d614..889beb9 100644 --- a/src/modules/ray/ray_camera.h +++ b/src/modules/ray/ray_camera.h @@ -21,55 +21,62 @@ typedef struct ray_camera_t { typedef struct ray_camera_frame_t { ray_camera_t *camera; /* the camera supplied to frame_begin() */ - fb_fragment_t *fragment; /* the fragment supplied to frame_begin() */ - ray_ray_t *ray; /* the ray supplied to frame_begin(), which gets updated as we step through the frame. */ ray_3f_t nw, ne, sw, se; /* directions pointing through the corners of the frame fragment */ - ray_3f_t cur_w, cur_e; /* current row's west and east ends */ - float x_alpha, y_alpha; /* interpolation position along the x and y axis */ float x_delta, y_delta; /* interpolation step delta along the x and y axis */ - unsigned x, y; /* integral position within frame fragment */ } ray_camera_frame_t; -void ray_camera_frame_begin(ray_camera_t *camera, fb_fragment_t *fragment, ray_ray_t *ray, ray_camera_frame_t *frame); +typedef struct ray_camera_fragment_t { + ray_camera_frame_t *frame; /* the frame supplied to fragment_begin() */ + fb_fragment_t *fb_fragment; /* the fragment supplied to fragment_begin() */ + ray_ray_t *ray; /* the ray supplied to frame_begin(), which gets updated as we step through the frame. */ + ray_3f_t cur_w, cur_e; /* current row's west and east ends */ + float x_alpha, y_alpha; /* interpolation position along the x and y axis */ + unsigned x, y; /* integral position within frame fragment */ +} ray_camera_fragment_t; -/* Step the ray through the frame on the x axis, returns 1 when rays remain on this axis, 0 at the end. */ -/* When 1 is returned, frame->ray is left pointing through the new coordinate. */ -static inline int ray_camera_frame_x_step(ray_camera_frame_t *frame) + +void ray_camera_frame_prepare(ray_camera_t *camera, ray_camera_frame_t *res_frame); +void ray_camera_fragment_begin(ray_camera_frame_t *frame, fb_fragment_t *fb_fragment, ray_ray_t *res_ray, ray_camera_fragment_t *res_fragment); + + +/* Step the ray through the fragment on the x axis, returns 1 when rays remain on this axis, 0 at the end. */ +/* When 1 is returned, fragment->ray is left pointing through the new coordinate. */ +static inline int ray_camera_fragment_x_step(ray_camera_fragment_t *fragment) { - frame->x++; + fragment->x++; - if (frame->x >= frame->fragment->width) { - frame->x = 0; - frame->x_alpha = frame->x_delta * (float)frame->fragment->x; + if (fragment->x >= fragment->fb_fragment->width) { + fragment->x = 0; + fragment->x_alpha = fragment->frame->x_delta * (float)fragment->fb_fragment->x; return 0; } - frame->x_alpha += frame->x_delta; - frame->ray->direction = ray_3f_nlerp(&frame->cur_w, &frame->cur_e, frame->x_alpha); + fragment->x_alpha += fragment->frame->x_delta; + fragment->ray->direction = ray_3f_nlerp(&fragment->cur_w, &fragment->cur_e, fragment->x_alpha); return 1; } -/* Step the ray through the frame on the y axis, returns 1 when rays remain on this axis, 0 at the end. */ -/* When 1 is returned, frame->ray is left pointing through the new coordinate. */ -static inline int ray_camera_frame_y_step(ray_camera_frame_t *frame) +/* Step the ray through the fragment on the y axis, returns 1 when rays remain on this axis, 0 at the end. */ +/* When 1 is returned, fragment->ray is left pointing through the new coordinate. */ +static inline int ray_camera_fragment_y_step(ray_camera_fragment_t *fragment) { - frame->y++; + fragment->y++; - if (frame->y >= frame->fragment->height) { - frame->y = 0; - frame->y_alpha = frame->y_delta * (float)frame->fragment->y; + if (fragment->y >= fragment->fb_fragment->height) { + fragment->y = 0; + fragment->y_alpha = fragment->frame->y_delta * (float)fragment->fb_fragment->y; return 0; } - frame->y_alpha += frame->y_delta; - frame->cur_w = ray_3f_lerp(&frame->nw, &frame->sw, frame->y_alpha); - frame->cur_e = ray_3f_lerp(&frame->ne, &frame->se, frame->y_alpha); - frame->ray->direction = ray_3f_nlerp(&frame->cur_w, &frame->cur_e, frame->x_alpha); + fragment->y_alpha += fragment->frame->y_delta; + fragment->cur_w = ray_3f_lerp(&fragment->frame->nw, &fragment->frame->sw, fragment->y_alpha); + fragment->cur_e = ray_3f_lerp(&fragment->frame->ne, &fragment->frame->se, fragment->y_alpha); + fragment->ray->direction = ray_3f_nlerp(&fragment->cur_w, &fragment->cur_e, fragment->x_alpha); return 1; } -- cgit v1.2.1