diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-12-01 15:24:25 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-12-01 15:24:25 -0500 |
commit | 0f05fc51962da8a7df269d51649cd8e1b683470c (patch) | |
tree | a8a487397d44e25efc2931733927aab7ce8f4d59 /libdimension | |
parent | 3cff39f02c54eb0f06835e1e0b6a2f6f02d0b5cb (diff) | |
download | dimension-0f05fc51962da8a7df269d51649cd8e1b683470c.tar.xz |
Evaluate specular highlights before reflection.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/raytrace.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/libdimension/raytrace.c b/libdimension/raytrace.c index 3b83618..dd84a26 100644 --- a/libdimension/raytrace.c +++ b/libdimension/raytrace.c @@ -315,6 +315,16 @@ dmnsn_trace_lighting(dmnsn_rtstate *state) dmnsn_color light_color; if (dmnsn_trace_light_ray(state, *light, &light_color)) { if (state->scene->quality & DMNSN_RENDER_FINISH) { + /* Get this light's specular contribution to the object */ + dmnsn_color specular = dmnsn_black; + if (finish->specular) { + specular = finish->specular->specular_fn( + finish->specular, light_color, state->pigment, state->light, + state->intersection->normal, state->viewer + ); + light_color = dmnsn_color_sub(light_color, specular); + } + /* Reflect the light */ const dmnsn_reflection *reflection = state->texture->finish.reflection; if ((state->scene->quality & DMNSN_RENDER_REFLECTION) && reflection) { @@ -325,7 +335,7 @@ dmnsn_trace_lighting(dmnsn_rtstate *state) light_color = dmnsn_color_sub(light_color, reflected); } - /* Get this light's color contribution to the object */ + /* Get this light's diffuse contribution to the object */ dmnsn_color diffuse = dmnsn_black; if (finish->diffuse) { diffuse = finish->diffuse->diffuse_fn( @@ -334,14 +344,6 @@ dmnsn_trace_lighting(dmnsn_rtstate *state) ); } - dmnsn_color specular = dmnsn_black; - if (finish->specular) { - specular = finish->specular->specular_fn( - finish->specular, light_color, state->pigment, state->light, - state->intersection->normal, state->viewer - ); - } - state->diffuse = dmnsn_color_add(diffuse, state->diffuse); state->additional = dmnsn_color_add(specular, state->additional); } else { |