#define to store coordinates at VlakRen and not at VlakFace
authorAndre Susano Pinto <andresusanopinto@gmail.com>
Wed, 5 Aug 2009 15:50:57 +0000 (15:50 +0000)
committerAndre Susano Pinto <andresusanopinto@gmail.com>
Wed, 5 Aug 2009 15:50:57 +0000 (15:50 +0000)
adds some additional cost retrieving coords during ray-primitive tests, but reduces some memory usage (4*3floats per face)

source/blender/render/intern/include/rayobject.h
source/blender/render/intern/source/rayobject.c
source/blender/render/intern/source/rayobject_octree.c

index dddeebd50487cac2c809276bb1c8074ec7c714d6..8f0dbed31762c4ad03d37ceaae6e6f3e9a63806c 100644 (file)
@@ -78,9 +78,9 @@ extern "C" {
  */
 
 /* defines where coordinates of rayface primitives are stored */
-#define RE_RAYFACE_COORDS_LOCAL
+//#define RE_RAYFACE_COORDS_LOCAL
 //#define RE_RAYFACE_COORDS_POINTER
-//#define RE_RAYFACE_COORDS_VLAKREN
+#define RE_RAYFACE_COORDS_VLAKREN
  
 typedef struct RayFace
 {
@@ -105,13 +105,13 @@ typedef struct RayFace
 #elif defined(RE_RAYFACE_COORDS_POINTER)
 #      define RE_rayface_isQuad(a) ((a)->v4)
 #elif defined(RE_RAYFACE_COORDS_VLAKREN)
+#      define RE_rayface_isQuad(a) ((((VlakRen*)((a)->face))->v4) != NULL)
 #endif
 
 
 struct RayObject
 {
        struct RayObjectAPI *api;
-       
 };
 
 
index c0c2c36fe13725ecf8e6a880eb643a27d8457e67..7316120e4777a10aa2c202aa4c74492f620727cb 100644 (file)
@@ -163,6 +163,22 @@ static int intersect_rayface(RayFace *face, Isect *is)
 
        RE_RC_COUNT(is->raycounter->faces.test);
 
+#ifdef RE_RAYFACE_COORDS_VLAKREN
+       {
+               VlakRen *vlr = (VlakRen*)face->face;
+               VECCOPY(co1, vlr->v1->co);
+               VECCOPY(co2, vlr->v2->co);
+               if(vlr->v4)
+               {
+                       VECCOPY(co3, vlr->v4->co);
+                       VECCOPY(co4, vlr->v3->co);
+               }
+               else
+               {
+                       VECCOPY(co3, vlr->v3->co);
+               }
+       }
+#else
        VECCOPY(co1, face->v1);
        VECCOPY(co2, face->v2);
        if(RE_rayface_isQuad(face))
@@ -174,6 +190,7 @@ static int intersect_rayface(RayFace *face, Isect *is)
        {
                VECCOPY(co3, face->v3);
        }
+#endif
 
        t00= co3[0]-co1[0];
        t01= co3[1]-co1[1];
@@ -414,10 +431,19 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max)
        if(RayObject_isRayFace(r))
        {
                RayFace *face = (RayFace*) RayObject_align(r);
+               
+#ifdef RE_RAYFACE_COORDS_VLAKREN
+               VlakRen *vlr = (VlakRen*)face->face;
+               DO_MINMAX( vlr->v1->co, min, max );
+               DO_MINMAX( vlr->v2->co, min, max );
+               DO_MINMAX( vlr->v3->co, min, max );
+               if(RE_rayface_isQuad(face)) DO_MINMAX( vlr->v4->co, min, max );
+#else
                DO_MINMAX( face->v1, min, max );
                DO_MINMAX( face->v2, min, max );
                DO_MINMAX( face->v3, min, max );
                if(RE_rayface_isQuad(face)) DO_MINMAX( face->v4, min, max );
+#endif
        }
        else if(RayObject_isRayAPI(r))
        {
index 88ea2bb38ed6d5071864efbe9fb57fcd4a4419e0..da1083a654d149799e41096cb994752e134d0be8 100644 (file)
@@ -489,11 +489,22 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
 
        ocres2= oc->ocres*oc->ocres;
 
+#ifdef RE_RAYFACE_COORDS_VLAKREN
+       {
+               VlakRen *vlr = (VlakRen*)face->face;
+               VECCOPY(co1, vlr->v1->co);
+               VECCOPY(co2, vlr->v2->co);
+               VECCOPY(co3, vlr->v3->co);
+               if(RE_rayface_isQuad(face))
+                       VECCOPY(co4, vlr->v4->co);
+       }
+#else
        VECCOPY(co1, face->v1);
        VECCOPY(co2, face->v2);
        VECCOPY(co3, face->v3);
        if(face->v4)
                VECCOPY(co4, face->v4);
+#endif
 
        for(c=0;c<3;c++) {
                rtf[0][c]= (co1[c]-oc->min[c])*ocfac[c] ;
@@ -502,7 +513,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
                rts[1][c]= (short)rtf[1][c];
                rtf[2][c]= (co3[c]-oc->min[c])*ocfac[c] ;
                rts[2][c]= (short)rtf[2][c];
-               if(face->v4) {
+               if(RE_rayface_isQuad(face)) {
                        rtf[3][c]= (co4[c]-oc->min[c])*ocfac[c] ;
                        rts[3][c]= (short)rtf[3][c];
                }
@@ -512,7 +523,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
                oc1= rts[0][c];
                oc2= rts[1][c];
                oc3= rts[2][c];
-               if(face->v4==NULL) {
+               if(!RE_rayface_isQuad(face)) {
                        ocmin[c]= MIN3(oc1,oc2,oc3);
                        ocmax[c]= MAX3(oc1,oc2,oc3);
                }
@@ -526,7 +537,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
        }
        
        if(ocmin[0]==ocmax[0] && ocmin[1]==ocmax[1] && ocmin[2]==ocmax[2]) {
-               ocwrite(oc, face, (face->v4 != NULL), ocmin[0], ocmin[1], ocmin[2], rtf);
+               ocwrite(oc, face, RE_rayface_isQuad(face), ocmin[0], ocmin[1], ocmin[2], rtf);
        }
        else {
                
@@ -536,7 +547,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
                d2dda(oc, 1,2,0,1,ocface+ocres2,rts,rtf);
                d2dda(oc, 1,2,0,2,ocface,rts,rtf);
                d2dda(oc, 1,2,1,2,ocface+2*ocres2,rts,rtf);
-               if(face->v4==NULL) {
+               if(!RE_rayface_isQuad(face)) {
                        d2dda(oc, 2,0,0,1,ocface+ocres2,rts,rtf);
                        d2dda(oc, 2,0,0,2,ocface,rts,rtf);
                        d2dda(oc, 2,0,1,2,ocface+2*ocres2,rts,rtf);
@@ -565,7 +576,7 @@ static void octree_fill_rayface(Octree *oc, RayFace *face)
                                        for(z=ocmin[2];z<=ocmax[2];z++) {
                                                if(ocface[b+z] && ocface[a+z]) {
                                                        if(face_in_node(NULL, x, y, z, rtf))
-                                                               ocwrite(oc, face, (face->v4 != NULL), x,y,z, rtf);
+                                                               ocwrite(oc, face, RE_rayface_isQuad(face), x,y,z, rtf);
                                                }
                                        }
                                }