solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit a4d91c684c290ce8361c88e0faf8f3be8e5ff42d
parent d60d114cac6ea8f9af822d22c5955c9bc1a26217
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  2 Mar 2017 14:47:46 +0100

Use the normal of the punched surface in ssol_draw

Use the normal of the parametric surface rather than the geometric
normal of its triangulated approximation.

Diffstat:
Msrc/ssol_c.h | 2+-
Msrc/ssol_draw.c | 21++++++++++++++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/ssol_c.h b/src/ssol_c.h @@ -45,7 +45,7 @@ struct ray_data { }; static const struct ray_data RAY_DATA_NULL = { - NULL, S3D_PRIMITIVE_NULL__, NULL, SSOL_INVALID_SIDE, 0, 0, 0, {0, 0, 0}, 0 + NULL, S3D_PRIMITIVE_NULL__, NULL, SSOL_INVALID_SIDE, 0, 0, 0, {0,0,0}, FLT_MAX }; diff --git a/src/ssol_draw.c b/src/ssol_draw.c @@ -17,7 +17,9 @@ #include "ssol_c.h" #include "ssol_camera.h" #include "ssol_device_c.h" +#include "ssol_object_c.h" #include "ssol_scene_c.h" +#include "ssol_shape_c.h" #include <rsys/double3.h> #include <rsys/math.h> @@ -59,8 +61,25 @@ Li(struct ssol_scene* scn, if(S3D_HIT_NONE(&hit)) { d3_splat(val, 0); } else { + struct ssol_instance* inst; + const struct shaded_shape* sshape; + size_t isshape; float N[3]={0}; - f3_normalize(N, hit.normal); + + /* Retrieve the hit shaded shape */ + inst = *htable_instance_find(&scn->instances_rt, &hit.prim.inst_id); + isshape = *htable_shaded_shape_find + (&inst->object->shaded_shapes_rt, &hit.prim.geom_id); + sshape = darray_shaded_shape_cdata_get + (&inst->object->shaded_shapes) + isshape; + + /* Retrieve and normalized the hit normal */ + switch(sshape->shape->type) { + case SHAPE_MESH: f3_normalize(N, hit.normal); break; + case SHAPE_PUNCHED: f3_normalize(N, f3_set_d3(N, ray_data.N)); break; + default: FATAL("Unreachable code"); break; + } + ASSERT(f3_is_normalized(N)); d3_splat(val, fabs(f3_dot(N, dir))); } }