summaryrefslogtreecommitdiff
path: root/modules/ray/ray_object_light.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-12-13 07:57:56 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2016-12-13 08:01:22 -0800
commit8340e615d46615894b44b4ffce5dc2dd86cbad40 (patch)
treeca9f82767d360f03e09425f21e35d0188eb52d1c /modules/ray/ray_object_light.h
parent8add1663d9a02db2bc65224cdceb480733a81379 (diff)
ray: introduce a rudimentary ray tracer
My first ray tracer, it only has spheres, planes, and point light sources. No texture mapping, no soft shadows, no global illumination. This is all very basic right now, the camera movement is simple and boring, but sufficient for further development and optimization. I made some effort to support multiple CPUs, it should detect the number of CPUs in the system and use enough pthreads to keep them busy. Jacco Bikker's tutorial on flipcode was the original impetus to do this, and definitely served as a guide early on.
Diffstat (limited to 'modules/ray/ray_object_light.h')
-rw-r--r--modules/ray/ray_object_light.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/ray/ray_object_light.h b/modules/ray/ray_object_light.h
new file mode 100644
index 0000000..73cf917
--- /dev/null
+++ b/modules/ray/ray_object_light.h
@@ -0,0 +1,60 @@
+#ifndef _RAY_OBJECT_LIGHT_H
+#define _RAY_OBJECT_LIGHT_H
+
+#include "ray_light_emitter.h"
+#include "ray_object_light.h"
+#include "ray_object_point.h"
+#include "ray_object_sphere.h"
+#include "ray_object_type.h"
+#include "ray_ray.h"
+#include "ray_scene.h"
+#include "ray_surface.h"
+
+
+typedef struct ray_object_light_t {
+ ray_object_type_t type;
+ float brightness;
+ ray_light_emitter_t emitter;
+} ray_object_light_t;
+
+
+/* TODO: point is really the only one I've implemented... */
+static inline int ray_object_light_intersects_ray(ray_object_light_t *light, ray_ray_t *ray, float *res_distance)
+{
+ switch (light->emitter.type) {
+ case RAY_LIGHT_EMITTER_TYPE_POINT:
+ return ray_object_point_intersects_ray(&light->emitter.point, ray, res_distance);
+
+ case RAY_LIGHT_EMITTER_TYPE_SPHERE:
+ return ray_object_sphere_intersects_ray(&light->emitter.sphere, ray, res_distance);
+ }
+}
+
+
+static inline ray_3f_t ray_object_light_normal(ray_object_light_t *light, ray_3f_t *point)
+{
+ ray_3f_t normal;
+
+ /* TODO */
+ switch (light->emitter.type) {
+ case RAY_LIGHT_EMITTER_TYPE_SPHERE:
+ return normal;
+
+ case RAY_LIGHT_EMITTER_TYPE_POINT:
+ return normal;
+ }
+}
+
+
+static inline ray_surface_t ray_object_light_surface(ray_object_light_t *light, ray_3f_t *point)
+{
+ switch (light->emitter.type) {
+ case RAY_LIGHT_EMITTER_TYPE_SPHERE:
+ return ray_object_sphere_surface(&light->emitter.sphere, point);
+
+ case RAY_LIGHT_EMITTER_TYPE_POINT:
+ return ray_object_point_surface(&light->emitter.point, point);
+ }
+}
+
+#endif
© All Rights Reserved