[#17298] surface normal direction compensation for objects with negative scale in...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jul 2008 19:15:26 +0000 (19:15 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 9 Jul 2008 19:15:26 +0000 (19:15 +0000)
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

index e5ef1e9a4a2e869dea53e54832c5374852aaeb95..68b5fa81f43c4347065a23a52770b92c8ebeb464 100644 (file)
@@ -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;