diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-05-30 23:24:36 -0600 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-05-30 23:43:03 -0600 |
commit | 141732e737eb7e9a1677fc3b5aa9ebcd66de3aca (patch) | |
tree | 196dabb31b85b92951e48462a425a58328350319 /libdimension/dimension | |
parent | 54585ba35adc6afc46201b746401c5a8a66ab6fa (diff) | |
download | dimension-141732e737eb7e9a1677fc3b5aa9ebcd66de3aca.tar.xz |
Make lights more generic to support directional lights.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/light.h | 35 | ||||
-rw-r--r-- | libdimension/dimension/scene.h | 7 |
2 files changed, 36 insertions, 6 deletions
diff --git a/libdimension/dimension/light.h b/libdimension/dimension/light.h index 03de641..b41a524 100644 --- a/libdimension/dimension/light.h +++ b/libdimension/dimension/light.h @@ -23,27 +23,50 @@ * Lights. */ +#include <stdbool.h> + /* Forward-declar dmnsn_light */ typedef struct dmnsn_light dmnsn_light; /** - * Light callback. + * Light direction callback. + * @param[in] light The light itself. + * @param[in] v The point to illuminate. + * @return The direction of light rays pointing from \p v + */ +typedef dmnsn_line dmnsn_light_direction_fn(const dmnsn_light *light, + dmnsn_vector v); + +/** + * Light illumination callback. * @param[in] light The light itself. * @param[in] v The point to illuminate. * @return The color of the light at \p v. */ -typedef dmnsn_color dmnsn_light_fn(const dmnsn_light *light, dmnsn_vector v); +typedef dmnsn_color dmnsn_light_illumination_fn(const dmnsn_light *light, + dmnsn_vector v); + +/** + * Light shadow callback. + * @param[in] light The light itself. + * @param[in] t The line index of the closest shadow ray intersection. + * @return Whether the point is in shadow. + */ +typedef bool dmnsn_light_shadow_fn(const dmnsn_light *light, double t); /** A light. */ struct dmnsn_light { - dmnsn_vector x0; /**< Origin of light rays. */ - /* Callbacks */ - dmnsn_light_fn *light_fn; /**< Light callback. */ - dmnsn_free_fn *free_fn; /**< Desctructor callback. */ + dmnsn_light_direction_fn *direction_fn; /**< Direction callback. */ + dmnsn_light_illumination_fn *illumination_fn; /**< Illumination callback. */ + dmnsn_light_shadow_fn *shadow_fn; /**< Shadow callback. */ + dmnsn_free_fn *free_fn; /**< Desctructor callback. */ /** Generic pointer for light info. */ void *ptr; + + /** @internal Reference count. */ + dmnsn_refcount refcount; }; /** diff --git a/libdimension/dimension/scene.h b/libdimension/dimension/scene.h index b726a77..bb47ee9 100644 --- a/libdimension/dimension/scene.h +++ b/libdimension/dimension/scene.h @@ -100,6 +100,13 @@ void dmnsn_initialize_scene(dmnsn_scene *scene); void dmnsn_scene_set_canvas(dmnsn_scene *scene, dmnsn_canvas *canvas); /** + * Add a light to a scene. + * @param[in,out] scene The scene to which to add the light. + * @param[in] object The object to light. + */ +void dmnsn_scene_add_light(dmnsn_scene *scene, dmnsn_light *light); + +/** * Set the camera for a scene. * @param[in,out] scene The scene for which to set the canvas. * @param[in] camera The camera to set. |