From b915ba5e970b1dd594e81318828321c5fb8c38f7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 9 Jul 2008 19:15:26 +0000 Subject: [#17298] surface normal direction compensation for objects with negative scale in rendering with radiosity from Roelf De Kock (kiemdoder) Fixes bug [#7969] Mirroring Object Breaks Radiosity Calculations - copied from the tracker. The code in this patch detects whether an object has negative scale (test the OB_NEG_SCALE bit in Object.transflag) and then compensate for the negative scale when the surface normals are calculated for a radiosity render. --- source/blender/radiosity/intern/source/radrender.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/blender/radiosity/intern/source/radrender.c b/source/blender/radiosity/intern/source/radrender.c index e5ef1e9a4a2..68b5fa81f43 100644 --- a/source/blender/radiosity/intern/source/radrender.c +++ b/source/blender/radiosity/intern/source/radrender.c @@ -369,9 +369,18 @@ printf(" Rad elems: %d emittors %d\n", RG.totelem, RG.totpatch); if(vlr->mat->mode & MA_RADIO) { /* during render, vlr->n gets flipped/corrected, we cannot have that */ - if(vlr->v4) CalcNormFloat4(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4->co, rf->norm); - else CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, rf->norm); - + if (obr->ob->transflag & OB_NEG_SCALE){ + /* The object has negative scale that will cause the normals to flip. + To counter this unwanted normal flip, swap vertex 2 and 4 for a quad + or vertex 2 and 3 (see flip_face) for a triangle in the call to CalcNormFloat4 + in order to flip the normals back to the way they were in the original mesh. */ + if(vlr->v4) CalcNormFloat4(vlr->v1->co, vlr->v4->co, vlr->v3->co, vlr->v2->co, rf->norm); + else CalcNormFloat(vlr->v1->co, vlr->v3->co, vlr->v2->co, rf->norm); + }else{ + if(vlr->v4) CalcNormFloat4(vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4->co, rf->norm); + else CalcNormFloat(vlr->v1->co, vlr->v2->co, vlr->v3->co, rf->norm); + } + rf->totrad[0]= vlr->mat->emit*vlr->mat->r; rf->totrad[1]= vlr->mat->emit*vlr->mat->g; rf->totrad[2]= vlr->mat->emit*vlr->mat->b; -- cgit v1.2.3