solstice-solver

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

commit 2f6c35655c5d8de6a2512525694715228f039f94
parent ab82f0f545354343be646009d0ff81ad53af4e16
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 14 Dec 2016 17:37:25 +0100

Fix the shading normal orientation

Ensure that the shading normal of a surface fragment look forward the
incoming direction.

Diffstat:
Msrc/ssol_material.c | 9++++++++-
Msrc/ssol_solver.c | 4++--
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/ssol_material.c b/src/ssol_material.c @@ -304,6 +304,9 @@ surface_fragment_setup char has_texcoord, has_normal; ASSERT(fragment && pos && dir && primitive && uv); + /* Assume that the submitted normal look forward the incoming dir */ + ASSERT(d3_dot(normal, dir) <= 0); + /* Setup the incoming direction */ d3_set(fragment->dir, dir); @@ -349,7 +352,11 @@ surface_fragment_setup } d3_set_f3(fragment->Ns, attr.value); d3_normalize(fragment->Ns, fragment->Ns); - /* FIXME: flip normal if backface??? */ + + /* Ensure that the fetched shading normal look forward the incoming dir */ + if(d3_dot(dir, fragment->Ns) > 0) { + d3_minus(fragment->Ns, fragment->Ns); + } } } diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -119,7 +119,7 @@ point_init pt->side = SSOL_FRONT; } else { pt->side = SSOL_BACK; - d3_minus(pt->N, pt->N); + d3_minus(pt->N, pt->N); /* Force the normal to look forward dir */ } /* Initialise the ray data to avoid self intersection */ @@ -185,7 +185,7 @@ point_update_from_hit pt->side = SSOL_FRONT; } else { pt->side = SSOL_BACK; - d3_minus(pt->N, pt->N); + d3_minus(pt->N, pt->N); /* Force the normal to look forward dir */ } }