summaryrefslogtreecommitdiff
path: root/src/modules/ray/ray_object.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-05-12 15:17:52 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-05-12 18:34:40 -0700
commit73ef51a819138e50b3d0b162d61a9f272fe07d01 (patch)
tree21c76ee677da8cd15b229af4715078dbbc1da796 /src/modules/ray/ray_object.c
parent6ebf0d428b25a8b4a2dee9af7a91c38b1f8ff124 (diff)
ray: add ray_scene_prepare() object precomputing
Just embed a _prepared struct in the object where precomputed stuff can be cached. Gets called once before rendering, which ends up calling the object-specific ray_object_$type_prepare() methods per object.
Diffstat (limited to 'src/modules/ray/ray_object.c')
-rw-r--r--src/modules/ray/ray_object.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/modules/ray/ray_object.c b/src/modules/ray/ray_object.c
index 4c5ccaf..ec3dcd8 100644
--- a/src/modules/ray/ray_object.c
+++ b/src/modules/ray/ray_object.c
@@ -9,6 +9,30 @@
#include "ray_surface.h"
+/* Prepare an object for rendering.
+ * If the object has any pre-calculating to do, this is where it happens.
+ * The pre-calculated stuff is object-resident under a _prepared struct member.
+ */
+void ray_object_prepare(ray_object_t *object)
+{
+ switch (object->type) {
+ case RAY_OBJECT_TYPE_SPHERE:
+ return ray_object_sphere_prepare(&object->sphere);
+
+ case RAY_OBJECT_TYPE_POINT:
+ return ray_object_point_prepare(&object->point);
+
+ case RAY_OBJECT_TYPE_PLANE:
+ return ray_object_plane_prepare(&object->plane);
+
+ case RAY_OBJECT_TYPE_LIGHT:
+ return ray_object_light_prepare(&object->light);
+ default:
+ assert(0);
+ }
+}
+
+
/* Determine if a ray intersects object.
* If the object is intersected, store where along the ray the intersection occurs in res_distance.
*/
© All Rights Reserved