diff options
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/dimension/texture.h | 3 | ||||
-rw-r--r-- | libdimension/raytrace.c | 25 | ||||
-rw-r--r-- | libdimension/solid_pigment.c | 21 | ||||
-rw-r--r-- | libdimension/texture.c | 8 |
4 files changed, 27 insertions, 30 deletions
diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h index c30b368..5586e24 100644 --- a/libdimension/dimension/texture.h +++ b/libdimension/dimension/texture.h @@ -47,6 +47,9 @@ struct dmnsn_pigment { /* Transformation matrix */ dmnsn_matrix trans, trans_inv; + /* Quick color */ + dmnsn_color quick_color; + /* Generic pointer */ void *ptr; }; diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 950b4f2..89908fa 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -224,8 +224,10 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, #define ITEXTURE(state) (state->intersection->texture) #define DTEXTURE(state) (state->scene->default_texture) -#define CAN_CALL(texture, telem, fn) \ - ((texture) && (texture)->telem && (texture)->telem->fn) +#define CAN_ACCESS(texture, telem) \ + ((texture) && (texture)->telem) +#define CAN_CALL(texture, telem, fn) \ + (CAN_ACCESS(texture, telem) && (texture)->telem->fn) /* Determine whether a callback may be called */ #define TEXTURE_HAS_CALLBACK(state, telem, fn) \ @@ -240,6 +242,14 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, ? (*DTEXTURE(state)->telem->fn)(DTEXTURE(state)->telem, __VA_ARGS__) \ : def)); +/* Get a property from a texture element */ +#define TEXTURE_PROPERTY(state, telem, prop, def) \ + (CAN_ACCESS(ITEXTURE(state), telem) \ + ? ITEXTURE(state)->telem->prop \ + : (CAN_ACCESS(DTEXTURE(state), telem) \ + ? DTEXTURE(state)->telem->prop \ + : def)) + #define IOR(state) \ ((state)->intersection->interior \ ? (state)->intersection->interior->ior \ @@ -248,8 +258,11 @@ dmnsn_raytrace_scene_impl(dmnsn_progress *progress, dmnsn_scene *scene, static void dmnsn_raytrace_pigment(dmnsn_raytrace_state *state) { - state->pigment = TEXTURE_CALLBACK(state, pigment, pigment_fn, dmnsn_black, - state->r); + state->pigment = TEXTURE_PROPERTY(state, pigment, quick_color, dmnsn_black); + if (state->scene->quality & DMNSN_RENDER_PIGMENT) { + state->pigment = TEXTURE_CALLBACK(state, pigment, pigment_fn, + state->pigment, state->r); + } state->diffuse = state->pigment; } @@ -453,9 +466,7 @@ dmnsn_raytrace_shoot(dmnsn_raytrace_state *state, dmnsn_line ray) state->additional = dmnsn_black; /* Pigment */ - if (state->scene->quality & DMNSN_RENDER_PIGMENT) { - dmnsn_raytrace_pigment(state); - } + dmnsn_raytrace_pigment(state); /* Finishes and shadows */ if (state->scene->quality & DMNSN_RENDER_LIGHTS) { diff --git a/libdimension/solid_pigment.c b/libdimension/solid_pigment.c index cc8310a..15ea86f 100644 --- a/libdimension/solid_pigment.c +++ b/libdimension/solid_pigment.c @@ -21,30 +21,11 @@ #include "dimension.h" #include <stdlib.h> -/* Solid color pigment callback */ -static dmnsn_color dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, - dmnsn_vector v); - /* Create a solid color */ dmnsn_pigment * dmnsn_new_solid_pigment(dmnsn_color color) { dmnsn_pigment *pigment = dmnsn_new_pigment(); - - dmnsn_color *solid = dmnsn_malloc(sizeof(dmnsn_color)); - *solid = color; - - pigment->pigment_fn = &dmnsn_solid_pigment_fn; - pigment->free_fn = &dmnsn_free; - pigment->ptr = solid; - + pigment->quick_color = color; return pigment; } - -/* Solid color callback */ -static dmnsn_color -dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) -{ - dmnsn_color *color = pigment->ptr; - return *color; -} diff --git a/libdimension/texture.c b/libdimension/texture.c index 9305f46..00b8682 100644 --- a/libdimension/texture.c +++ b/libdimension/texture.c @@ -26,9 +26,11 @@ dmnsn_pigment * dmnsn_new_pigment() { dmnsn_pigment *pigment = dmnsn_malloc(sizeof(dmnsn_pigment)); - pigment->init_fn = NULL; - pigment->free_fn = NULL; - pigment->trans = dmnsn_identity_matrix(); + pigment->pigment_fn = NULL; + pigment->init_fn = NULL; + pigment->free_fn = NULL; + pigment->trans = dmnsn_identity_matrix(); + pigment->quick_color = dmnsn_black; return pigment; } |