style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / render / intern / source / zbuf.c
index 46520001d2dd58632a0da3ec33f6c7fea48fffbc..e3068d122657f4741714549caf8ecf6c39951710 100644 (file)
@@ -101,9 +101,9 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty, float clipcrop)
 
 void zbuf_free_span(ZSpan *zspan)
 {
-       if(zspan) {
-               if(zspan->span1) MEM_freeN(zspan->span1);
-               if(zspan->span2) MEM_freeN(zspan->span2);
+       if (zspan) {
+               if (zspan->span1) MEM_freeN(zspan->span1);
+               if (zspan->span2) MEM_freeN(zspan->span2);
                zspan->span1= zspan->span2= NULL;
        }
 }
@@ -122,7 +122,7 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2)
        float xx1, dx0, xs0;
        int y, my0, my2;
        
-       if(v1[1]<v2[1]) {
+       if (v1[1]<v2[1]) {
                minv= v1; maxv= v2;
        }
        else {
@@ -132,18 +132,18 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2)
        my0= ceil(minv[1]);
        my2= floor(maxv[1]);
        
-       if(my2<0 || my0>= zspan->recty) return;
+       if (my2<0 || my0>= zspan->recty) return;
        
        /* clip top */
-       if(my2>=zspan->recty) my2= zspan->recty-1;
+       if (my2>=zspan->recty) my2= zspan->recty-1;
        /* clip bottom */
-       if(my0<0) my0= 0;
+       if (my0<0) my0= 0;
        
-       if(my0>my2) return;
+       if (my0>my2) return;
        /* if(my0>my2) should still fill in, that way we get spans that skip nicely */
        
        xx1= maxv[1]-minv[1];
-       if(xx1>FLT_EPSILON) {
+       if (xx1>FLT_EPSILON) {
                dx0= (minv[0]-maxv[0])/xx1;
                xs0= dx0*(minv[1]-my2) + minv[0];
        }
@@ -153,11 +153,11 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2)
        }
        
        /* empty span */
-       if(zspan->maxp1 == NULL) {
+       if (zspan->maxp1 == NULL) {
                span= zspan->span1;
        }
        else {  /* does it complete left span? */
-               if( maxv == zspan->minp1 || minv==zspan->maxp1) {
+               if ( maxv == zspan->minp1 || minv==zspan->maxp1) {
                        span= zspan->span1;
                }
                else {
@@ -165,30 +165,30 @@ static void zbuf_add_to_span(ZSpan *zspan, float *v1, float *v2)
                }
        }
 
-       if(span==zspan->span1) {
+       if (span==zspan->span1) {
 //             printf("left span my0 %d my2 %d\n", my0, my2);
-               if(zspan->minp1==NULL || zspan->minp1[1] > minv[1] ) {
+               if (zspan->minp1==NULL || zspan->minp1[1] > minv[1] ) {
                        zspan->minp1= minv;
                }
-               if(zspan->maxp1==NULL || zspan->maxp1[1] < maxv[1] ) {
+               if (zspan->maxp1==NULL || zspan->maxp1[1] < maxv[1] ) {
                        zspan->maxp1= maxv;
                }
-               if(my0<zspan->miny1) zspan->miny1= my0;
-               if(my2>zspan->maxy1) zspan->maxy1= my2;
+               if (my0<zspan->miny1) zspan->miny1= my0;
+               if (my2>zspan->maxy1) zspan->maxy1= my2;
        }
        else {
 //             printf("right span my0 %d my2 %d\n", my0, my2);
-               if(zspan->minp2==NULL || zspan->minp2[1] > minv[1] ) {
+               if (zspan->minp2==NULL || zspan->minp2[1] > minv[1] ) {
                        zspan->minp2= minv;
                }
-               if(zspan->maxp2==NULL || zspan->maxp2[1] < maxv[1] ) {
+               if (zspan->maxp2==NULL || zspan->maxp2[1] < maxv[1] ) {
                        zspan->maxp2= maxv;
                }
-               if(my0<zspan->miny2) zspan->miny2= my0;
-               if(my2>zspan->maxy2) zspan->maxy2= my2;
+               if (my0<zspan->miny2) zspan->miny2= my0;
+               if (my2>zspan->maxy2) zspan->maxy2= my2;
        }
 
-       for(y=my2; y>=my0; y--, xs0+= dx0) {
+       for (y=my2; y>=my0; y--, xs0+= dx0) {
                /* xs0 is the xcoord! */
                span[y]= xs0;
        }
@@ -204,7 +204,7 @@ void fillrect(int *rect, int x, int y, int val)
 
        len= x*y;
        drect= rect;
-       while(len>0) {
+       while (len>0) {
                len--;
                *drect= val;
                drect++;
@@ -216,24 +216,24 @@ static short cliptestf(float a, float b, float c, float d, float *u1, float *u2)
 {
        float p= a + b, q= c + d, r;
        
-       if(p<0.0f) {
-               if(q<p) return 0;
-               else if(q<0.0f) {
+       if (p<0.0f) {
+               if (q<p) return 0;
+               else if (q<0.0f) {
                        r= q/p;
-                       if(r>*u2) return 0;
-                       else if(r>*u1) *u1=r;
+                       if (r>*u2) return 0;
+                       else if (r>*u1) *u1=r;
                }
        }
        else {
-               if(p>0.0f) {
-                       if(q<0.0f) return 0;
-                       else if(q<p) {
+               if (p>0.0f) {
+                       if (q<0.0f) return 0;
+                       else if (q<p) {
                                r= q/p;
-                               if(r<*u1) return 0;
-                               else if(r<*u2) *u2=r;
+                               if (r<*u1) return 0;
+                               else if (r<*u2) *u2=r;
                        }
                }
-               else if(q<0.0f) return 0;
+               else if (q<0.0f) return 0;
        }
        return 1;
 }
@@ -247,14 +247,14 @@ int testclip(const float v[4])
         * prevents issues with vertices lying exact on borders */
        abs4= fabsf(v[3]) + FLT_EPSILON;
        
-       if( v[0] < -abs4) c+=1;
-       else if( v[0] > abs4) c+=2;
+       if ( v[0] < -abs4) c+=1;
+       else if ( v[0] > abs4) c+=2;
        
-       if( v[1] > abs4) c+=4;
-       else if( v[1] < -abs4) c+=8;
+       if ( v[1] > abs4) c+=4;
+       else if ( v[1] < -abs4) c+=8;
        
-       if(v[2] < -abs4) c+=16;                 /* this used to be " if(v[2]<0) ", see clippz() */
-       else if(v[2]> abs4) c+= 32;
+       if (v[2] < -abs4) c+=16;                        /* this used to be " if(v[2]<0) ", see clippz() */
+       else if (v[2]> abs4) c+= 32;
        
        return c;
 }
@@ -279,9 +279,9 @@ void freepsA(ListBase *lb)
 {
        APixstrMain *psm, *psmnext;
 
-       for(psm= lb->first; psm; psm= psmnext) {
+       for (psm= lb->first; psm; psm= psmnext) {
                psmnext= psm->next;
-               if(psm->ps)
+               if (psm->ps)
                        MEM_freeN(psm->ps);
                MEM_freeN(psm);
        }
@@ -290,7 +290,7 @@ void freepsA(ListBase *lb)
 static APixstr *addpsA(ZSpan *zspan)
 {
        /* make new PS */
-       if(zspan->apsmcounter==0) {
+       if (zspan->apsmcounter==0) {
                zspan->curpstr= addpsmainA(zspan->apsmbase);
                zspan->apsmcounter= 4095;
        }
@@ -317,7 +317,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        /* set spans */
        zbuf_add_to_span(zspan, v1, v2);
        zbuf_add_to_span(zspan, v2, v3);
-       if(v4) {
+       if (v4) {
                zbuf_add_to_span(zspan, v3, v4);
                zbuf_add_to_span(zspan, v4, v1);
        }
@@ -325,12 +325,12 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                zbuf_add_to_span(zspan, v3, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        /* ZBUF DX DY, in floats still */
        x1= v1[0]- v2[0];
@@ -343,7 +343,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
        
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
        
@@ -360,7 +360,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
 
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -369,16 +369,16 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
-               if(sn2>=sn1) {
+               if (sn2>=sn1) {
                        int intzverg;
                        
                        zverg= (double)sn1*zxd + zy0;
@@ -389,23 +389,23 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                        
                        zverg-= zspan->polygon_offset;
                        
-                       while(x>=0) {
+                       while (x>=0) {
                                intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
 
-                               if( intzverg < *rz) {
-                                       if(!zspan->rectmask || intzverg > *rm) {
+                               if ( intzverg < *rz) {
+                                       if (!zspan->rectmask || intzverg > *rm) {
                                                
                                                apn= ap;
-                                               while(apn) {
-                                                       if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; }
-                                                       if(apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
-                                                       if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= intzverg; apn->mask[1]= mask; break; }
-                                                       if(apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
-                                                       if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= intzverg; apn->mask[2]= mask; break; }
-                                                       if(apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
-                                                       if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= intzverg; apn->mask[3]= mask; break; }
-                                                       if(apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
-                                                       if(apn->next==NULL) apn->next= addpsA(zspan);
+                                               while (apn) {
+                                                       if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; }
+                                                       if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
+                                                       if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= intzverg; apn->mask[1]= mask; break; }
+                                                       if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
+                                                       if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= intzverg; apn->mask[2]= mask; break; }
+                                                       if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
+                                                       if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= intzverg; apn->mask[3]= mask; break; }
+                                                       if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
+                                                       if (apn->next==NULL) apn->next= addpsA(zspan);
                                                        apn= apn->next;
                                                }                               
                                        }
@@ -441,10 +441,10 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
        
        mask= zspan->mask;
        
-       if(fabs(dx) > fabs(dy)) {
+       if (fabs(dx) > fabs(dy)) {
 
                /* all lines from left to right */
-               if(vec1[0]<vec2[0]) {
+               if (vec1[0]<vec2[0]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -456,7 +456,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
 
                start= floor(v1[0]);
                end= start+floor(dx);
-               if(end>=zspan->rectx) end= zspan->rectx-1;
+               if (end>=zspan->rectx) end= zspan->rectx-1;
                
                oldy= floor(v1[1]);
                dy/= dx;
@@ -464,40 +464,40 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
                vergz= v1[2];
                vergz-= zspan->polygon_offset;
                dz= (v2[2]-v1[2])/dx;
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
                
                rectz= (int *)(zspan->arectz+zspan->rectx*(oldy) +start);
                rectmask= (int *)(zspan->rectmask+zspan->rectx*(oldy) +start);
                ap= (zspan->apixbuf+ zspan->rectx*(oldy) +start);
 
-               if(dy<0) ofs= -zspan->rectx;
+               if (dy<0) ofs= -zspan->rectx;
                else ofs= zspan->rectx;
                
-               for(x= start; x<=end; x++, rectz++, rectmask++, ap++) {
+               for (x= start; x<=end; x++, rectz++, rectmask++, ap++) {
                        
                        y= floor(v1[1]);
-                       if(y!=oldy) {
+                       if (y!=oldy) {
                                oldy= y;
                                rectz+= ofs;
                                rectmask+= ofs;
                                ap+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && y<zspan->recty) {
-                               if(vergz<*rectz) {
-                                       if(!zspan->rectmask || vergz>*rectmask) {
+                       if (x>=0 && y>=0 && y<zspan->recty) {
+                               if (vergz<*rectz) {
+                                       if (!zspan->rectmask || vergz>*rectmask) {
                                        
                                                apn= ap;
-                                               while(apn) {    /* loop unrolled */
-                                                       if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
-                                                       if(apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
-                                                       if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
-                                                       if(apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
-                                                       if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
-                                                       if(apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
-                                                       if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
-                                                       if(apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
-                                                       if(apn->next==0) apn->next= addpsA(zspan);
+                                               while (apn) {   /* loop unrolled */
+                                                       if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
+                                                       if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
+                                                       if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
+                                                       if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
+                                                       if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
+                                                       if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
+                                                       if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
+                                                       if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
+                                                       if (apn->next==0) apn->next= addpsA(zspan);
                                                        apn= apn->next;
                                                }                               
                                        }
@@ -505,14 +505,14 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
                        }
                        
                        v1[1]+= dy;
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                }
        }
        else {
        
                /* all lines from top to bottom */
-               if(vec1[1]<vec2[1]) {
+               if (vec1[1]<vec2[1]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -525,9 +525,9 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
                start= floor(v1[1]);
                end= start+floor(dy);
                
-               if(start>=zspan->recty || end<0) return;
+               if (start>=zspan->recty || end<0) return;
                
-               if(end>=zspan->recty) end= zspan->recty-1;
+               if (end>=zspan->recty) end= zspan->recty-1;
                
                oldx= floor(v1[0]);
                dx/= dy;
@@ -535,40 +535,40 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
                vergz= v1[2];
                vergz-= zspan->polygon_offset;
                dz= (v2[2]-v1[2])/dy;
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
 
                rectz= (int *)( zspan->arectz+ (start)*zspan->rectx+ oldx );
                rectmask= (int *)( zspan->rectmask+ (start)*zspan->rectx+ oldx );
                ap= (zspan->apixbuf+ zspan->rectx*(start) +oldx);
                                
-               if(dx<0) ofs= -1;
+               if (dx<0) ofs= -1;
                else ofs= 1;
 
-               for(y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) {
+               for (y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) {
                        
                        x= floor(v1[0]);
-                       if(x!=oldx) {
+                       if (x!=oldx) {
                                oldx= x;
                                rectz+= ofs;
                                rectmask+= ofs;
                                ap+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && x<zspan->rectx) {
-                               if(vergz<*rectz) {
-                                       if(!zspan->rectmask || vergz>*rectmask) {
+                       if (x>=0 && y>=0 && x<zspan->rectx) {
+                               if (vergz<*rectz) {
+                                       if (!zspan->rectmask || vergz>*rectmask) {
                                                
                                                apn= ap;
-                                               while(apn) {    /* loop unrolled */
-                                                       if(apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
-                                                       if(apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; }
-                                                       if(apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
-                                                       if(apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; }
-                                                       if(apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
-                                                       if(apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; }
-                                                       if(apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
-                                                       if(apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; }
-                                                       if(apn->next==0) apn->next= addpsA(zspan);
+                                               while (apn) {   /* loop unrolled */
+                                                       if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
+                                                       if (apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; }
+                                                       if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
+                                                       if (apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; }
+                                                       if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
+                                                       if (apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; }
+                                                       if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
+                                                       if (apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; }
+                                                       if (apn->next==0) apn->next= addpsA(zspan);
                                                        apn= apn->next;
                                                }       
                                        }
@@ -576,7 +576,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec
                        }
                        
                        v1[0]+= dx;
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                }
        }
@@ -595,10 +595,10 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
        dx= vec2[0]-vec1[0];
        dy= vec2[1]-vec1[1];
        
-       if(fabs(dx) > fabs(dy)) {
+       if (fabs(dx) > fabs(dy)) {
 
                /* all lines from left to right */
-               if(vec1[0]<vec2[0]) {
+               if (vec1[0]<vec2[0]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -610,27 +610,27 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
 
                start= floor(v1[0]);
                end= start+floor(dx);
-               if(end>=zspan->rectx) end= zspan->rectx-1;
+               if (end>=zspan->rectx) end= zspan->rectx-1;
                
                oldy= floor(v1[1]);
                dy/= dx;
                
                vergz= floor(v1[2]);
                dz= floor((v2[2]-v1[2])/dx);
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
                
                rectz= zspan->rectz + oldy*zspan->rectx+ start;
                rectp= zspan->rectp + oldy*zspan->rectx+ start;
                recto= zspan->recto + oldy*zspan->rectx+ start;
                rectmask= zspan->rectmask + oldy*zspan->rectx+ start;
                
-               if(dy<0) ofs= -zspan->rectx;
+               if (dy<0) ofs= -zspan->rectx;
                else ofs= zspan->rectx;
                
-               for(x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) {
+               for (x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) {
                        
                        y= floor(v1[1]);
-                       if(y!=oldy) {
+                       if (y!=oldy) {
                                oldy= y;
                                rectz+= ofs;
                                rectp+= ofs;
@@ -638,9 +638,9 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
                                rectmask+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && y<zspan->recty) {
-                               if(vergz<*rectz) {
-                                       if(!zspan->rectmask || vergz>*rectmask) {
+                       if (x>=0 && y>=0 && y<zspan->recty) {
+                               if (vergz<*rectz) {
+                                       if (!zspan->rectmask || vergz>*rectmask) {
                                                *recto= obi;
                                                *rectz= vergz;
                                                *rectp= zvlnr;
@@ -650,13 +650,13 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
                        
                        v1[1]+= dy;
                        
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                }
        }
        else {
                /* all lines from top to bottom */
-               if(vec1[1]<vec2[1]) {
+               if (vec1[1]<vec2[1]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -669,27 +669,27 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
                start= floor(v1[1]);
                end= start+floor(dy);
                
-               if(end>=zspan->recty) end= zspan->recty-1;
+               if (end>=zspan->recty) end= zspan->recty-1;
                
                oldx= floor(v1[0]);
                dx/= dy;
                
                vergz= floor(v1[2]);
                dz= floor((v2[2]-v1[2])/dy);
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
                
                rectz= zspan->rectz + start*zspan->rectx+ oldx;
                rectp= zspan->rectp + start*zspan->rectx+ oldx;
                recto= zspan->recto + start*zspan->rectx+ oldx;
                rectmask= zspan->rectmask + start*zspan->rectx+ oldx;
                
-               if(dx<0) ofs= -1;
+               if (dx<0) ofs= -1;
                else ofs= 1;
 
-               for(y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) {
+               for (y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) {
                        
                        x= floor(v1[0]);
-                       if(x!=oldx) {
+                       if (x!=oldx) {
                                oldx= x;
                                rectz+= ofs;
                                rectp+= ofs;
@@ -697,9 +697,9 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
                                rectmask+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && x<zspan->rectx) {
-                               if(vergz<*rectz) {
-                                       if(!zspan->rectmask || vergz>*rectmask) {
+                       if (x>=0 && y>=0 && x<zspan->rectx) {
+                               if (vergz<*rectz) {
+                                       if (!zspan->rectmask || vergz>*rectmask) {
                                                *rectz= vergz;
                                                *rectp= zvlnr;
                                                *recto= obi;
@@ -708,7 +708,7 @@ static void zbufline(ZSpan *zspan, int obi, int zvlnr, float *vec1, float *vec2)
                        }
                        
                        v1[0]+= dx;
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                }
        }
@@ -725,10 +725,10 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo
        dx= vec2[0]-vec1[0];
        dy= vec2[1]-vec1[1];
        
-       if(fabs(dx) > fabs(dy)) {
+       if (fabs(dx) > fabs(dy)) {
                
                /* all lines from left to right */
-               if(vec1[0]<vec2[0]) {
+               if (vec1[0]<vec2[0]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -740,51 +740,51 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo
                
                start= floor(v1[0]);
                end= start+floor(dx);
-               if(end>=zspan->rectx) end= zspan->rectx-1;
+               if (end>=zspan->rectx) end= zspan->rectx-1;
                
                oldy= floor(v1[1]);
                dy/= dx;
                
                vergz= floor(v1[2]);
                dz= floor((v2[2]-v1[2])/dx);
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
                
                rectz= zspan->rectz + oldy*zspan->rectx+ start;
-               if(zspan->rectz1)
+               if (zspan->rectz1)
                        rectz1= zspan->rectz1 + oldy*zspan->rectx+ start;
                
-               if(dy<0) ofs= -zspan->rectx;
+               if (dy<0) ofs= -zspan->rectx;
                else ofs= zspan->rectx;
                
-               for(x= start; x<=end; x++, rectz++) {
+               for (x= start; x<=end; x++, rectz++) {
                        
                        y= floor(v1[1]);
-                       if(y!=oldy) {
+                       if (y!=oldy) {
                                oldy= y;
                                rectz+= ofs;
-                               if(rectz1) rectz1+= ofs;
+                               if (rectz1) rectz1+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && y<zspan->recty) {
-                               if(vergz < *rectz) {
-                                       if(rectz1) *rectz1= *rectz;
+                       if (x>=0 && y>=0 && y<zspan->recty) {
+                               if (vergz < *rectz) {
+                                       if (rectz1) *rectz1= *rectz;
                                        *rectz= vergz;
                                }
-                               else if(rectz1 && vergz < *rectz1)
+                               else if (rectz1 && vergz < *rectz1)
                                        *rectz1= vergz;
                        }
                        
                        v1[1]+= dy;
                        
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                        
-                       if(rectz1) rectz1++;
+                       if (rectz1) rectz1++;
                }
        }
        else {
                /* all lines from top to bottom */
-               if(vec1[1]<vec2[1]) {
+               if (vec1[1]<vec2[1]) {
                        copy_v3_v3(v1, vec1);
                        copy_v3_v3(v2, vec2);
                }
@@ -797,45 +797,45 @@ static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), flo
                start= floor(v1[1]);
                end= start+floor(dy);
                
-               if(end>=zspan->recty) end= zspan->recty-1;
+               if (end>=zspan->recty) end= zspan->recty-1;
                
                oldx= floor(v1[0]);
                dx/= dy;
                
                vergz= floor(v1[2]);
                dz= floor((v2[2]-v1[2])/dy);
-               if(vergz>0x50000000 && dz>0) maxtest= 1;                // prevent overflow
+               if (vergz>0x50000000 && dz>0) maxtest= 1;               // prevent overflow
                
                rectz= zspan->rectz + start*zspan->rectx+ oldx;
-               if(zspan->rectz1)
+               if (zspan->rectz1)
                        rectz1= zspan->rectz1 + start*zspan->rectx+ oldx;
                
-               if(dx<0) ofs= -1;
+               if (dx<0) ofs= -1;
                else ofs= 1;
                
-               for(y= start; y<=end; y++, rectz+=zspan->rectx) {
+               for (y= start; y<=end; y++, rectz+=zspan->rectx) {
                        
                        x= floor(v1[0]);
-                       if(x!=oldx) {
+                       if (x!=oldx) {
                                oldx= x;
                                rectz+= ofs;
-                               if(rectz1) rectz1+= ofs;
+                               if (rectz1) rectz1+= ofs;
                        }
                        
-                       if(x>=0 && y>=0 && x<zspan->rectx) {
-                               if(vergz < *rectz) {
-                                       if(rectz1) *rectz1= *rectz;
+                       if (x>=0 && y>=0 && x<zspan->rectx) {
+                               if (vergz < *rectz) {
+                                       if (rectz1) *rectz1= *rectz;
                                        *rectz= vergz;
                                }
-                               else if(rectz1 && vergz < *rectz1)
+                               else if (rectz1 && vergz < *rectz1)
                                        *rectz1= vergz;
                        }
                        
                        v1[0]+= dx;
-                       if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+                       if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
                        else vergz+= dz;
                        
-                       if(rectz1)
+                       if (rectz1)
                                rectz1+=zspan->rectx;
                }
        }
@@ -854,28 +854,28 @@ static int clipline(float v1[4], float v2[4])     /* return 0: do not draw */
         * filled in with zbufwire correctly when rendering in parts. otherwise
         * you see line endings at edges... */
        
-       if(cliptestf(-dz, -dw, v1[3], v1[2], &u1,&u2)) {
-               if(cliptestf(dz, -dw, v1[3], -v1[2], &u1,&u2)) {
+       if (cliptestf(-dz, -dw, v1[3], v1[2], &u1,&u2)) {
+               if (cliptestf(dz, -dw, v1[3], -v1[2], &u1,&u2)) {
                        
                        dx= v2[0]-v1[0];
                        dz= 1.01f*(v2[3]-v1[3]);
                        v13= 1.01f*v1[3];
                        
-                       if(cliptestf(-dx, -dz, v1[0], v13, &u1,&u2)) {
-                               if(cliptestf(dx, -dz, v13, -v1[0], &u1,&u2)) {
+                       if (cliptestf(-dx, -dz, v1[0], v13, &u1,&u2)) {
+                               if (cliptestf(dx, -dz, v13, -v1[0], &u1,&u2)) {
                                        
                                        dy= v2[1]-v1[1];
                                        
-                                       if(cliptestf(-dy, -dz, v1[1], v13, &u1,&u2)) {
-                                               if(cliptestf(dy, -dz, v13, -v1[1], &u1,&u2)) {
+                                       if (cliptestf(-dy, -dz, v1[1], v13, &u1,&u2)) {
+                                               if (cliptestf(dy, -dz, v13, -v1[1], &u1,&u2)) {
                                                        
-                                                       if(u2<1.0f) {
+                                                       if (u2<1.0f) {
                                                                v2[0]= v1[0]+u2*dx;
                                                                v2[1]= v1[1]+u2*dy;
                                                                v2[2]= v1[2]+u2*dz;
                                                                v2[3]= v1[3]+u2*dw;
                                                        }
-                                                       if(u1>0.0f) {
+                                                       if (u1>0.0f) {
                                                                v1[0]= v1[0]+u1*dx;
                                                                v1[1]= v1[1]+u1*dy;
                                                                v1[2]= v1[2]+u1*dz;
@@ -908,9 +908,9 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h
        int and, or;
 
        /* edgecode: 1= draw */
-       if(ec==0) return;
+       if (ec==0) return;
 
-       if(ho4) {
+       if (ho4) {
                and= (c1 & c2 & c3 & c4);
                or= (c1 | c2 | c3 | c4);
        }
@@ -919,44 +919,44 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h
                or= (c1 | c2 | c3);
        }
        
-       if(or) {        /* not in the middle */
-               if(and) {       /* out completely */
+       if (or) {       /* not in the middle */
+               if (and) {      /* out completely */
                        return;
                }
                else {  /* clipping */
 
-                       if(ec & ME_V1V2) {
+                       if (ec & ME_V1V2) {
                                copy_v4_v4(vez, ho1);
                                copy_v4_v4(vez+4, ho2);
-                               if( clipline(vez, vez+4)) {
+                               if ( clipline(vez, vez+4)) {
                                        hoco_to_zco(zspan, vez, vez);
                                        hoco_to_zco(zspan, vez+4, vez+4);
                                        zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
                                }
                        }
-                       if(ec & ME_V2V3) {
+                       if (ec & ME_V2V3) {
                                copy_v4_v4(vez, ho2);
                                copy_v4_v4(vez+4, ho3);
-                               if( clipline(vez, vez+4)) {
+                               if ( clipline(vez, vez+4)) {
                                        hoco_to_zco(zspan, vez, vez);
                                        hoco_to_zco(zspan, vez+4, vez+4);
                                        zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
                                }
                        }
-                       if(ho4) {
-                               if(ec & ME_V3V4) {
+                       if (ho4) {
+                               if (ec & ME_V3V4) {
                                        copy_v4_v4(vez, ho3);
                                        copy_v4_v4(vez+4, ho4);
-                                       if( clipline(vez, vez+4)) {
+                                       if ( clipline(vez, vez+4)) {
                                                hoco_to_zco(zspan, vez, vez);
                                                hoco_to_zco(zspan, vez+4, vez+4);
                                                zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
                                        }
                                }
-                               if(ec & ME_V4V1) {
+                               if (ec & ME_V4V1) {
                                        copy_v4_v4(vez, ho4);
                                        copy_v4_v4(vez+4, ho1);
-                                       if( clipline(vez, vez+4)) {
+                                       if ( clipline(vez, vez+4)) {
                                                hoco_to_zco(zspan, vez, vez);
                                                hoco_to_zco(zspan, vez+4, vez+4);
                                                zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
@@ -964,10 +964,10 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h
                                }
                        }
                        else {
-                               if(ec & ME_V3V1) {
+                               if (ec & ME_V3V1) {
                                        copy_v4_v4(vez, ho3);
                                        copy_v4_v4(vez+4, ho1);
-                                       if( clipline(vez, vez+4)) {
+                                       if ( clipline(vez, vez+4)) {
                                                hoco_to_zco(zspan, vez, vez);
                                                hoco_to_zco(zspan, vez+4, vez+4);
                                                zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
@@ -982,18 +982,18 @@ void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec, float *ho1, float *h
        hoco_to_zco(zspan, vez, ho1);
        hoco_to_zco(zspan, vez+4, ho2);
        hoco_to_zco(zspan, vez+8, ho3);
-       if(ho4) {
+       if (ho4) {
                hoco_to_zco(zspan, vez+12, ho4);
 
-               if(ec & ME_V3V4)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez+12);
-               if(ec & ME_V4V1)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+12, vez);
+               if (ec & ME_V3V4)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez+12);
+               if (ec & ME_V4V1)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+12, vez);
        }
        else {
-               if(ec & ME_V3V1)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez);
+               if (ec & ME_V3V1)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez);
        }
 
-       if(ec & ME_V1V2)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
-       if(ec & ME_V2V3)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+4, vez+8);
+       if (ec & ME_V1V2)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
+       if (ec & ME_V2V3)  zspan->zbuflinefunc(zspan, obi, zvlnr, vez+4, vez+8);
 
 }
 
@@ -1005,12 +1005,12 @@ void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, const float ho1[4], const
        c1= testclip(ho1);
        c2= testclip(ho2);
 
-       if(c1 | c2) {   /* not in the middle */
-               if(!(c1 & c2)) {        /* not out completely */
+       if (c1 | c2) {  /* not in the middle */
+               if (!(c1 & c2)) {       /* not out completely */
                        copy_v4_v4(f1, ho1);
                        copy_v4_v4(f2, ho2);
 
-                       if(clipline(f1, f2)) {
+                       if (clipline(f1, f2)) {
                                hoco_to_zco(zspan, f1, f1);
                                hoco_to_zco(zspan, f2, f2);
                                zspan->zbuflinefunc(zspan, obi, zvlnr, f1, f2);
@@ -1057,7 +1057,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
        /* set spans */
        zbuf_add_to_span(zspan, v1, v2);
        zbuf_add_to_span(zspan, v2, v3);
-       if(v4) {
+       if (v4) {
                zbuf_add_to_span(zspan, v3, v4);
                zbuf_add_to_span(zspan, v4, v1);
        }
@@ -1065,13 +1065,13 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
                zbuf_add_to_span(zspan, v3, v1);
 
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
 
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
 
 
        /* ZBUF DX DY, in floats still */
@@ -1085,7 +1085,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
 
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
 
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
 
@@ -1102,7 +1102,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
 
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -1111,16 +1111,16 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
                span2= zspan->span1+my2;
        }
 
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
 
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++;
 
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
 
-               if(sn2>=sn1) {
+               if (sn2>=sn1) {
                        int intzverg;
 
                        zverg= (double)sn1*zxd + zy0;
@@ -1130,11 +1130,11 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v
                        rm= rectmaskofs+sn1;
                        x= sn2-sn1;
 
-                       while(x>=0) {
+                       while (x>=0) {
                                intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
 
-                               if( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */
-                                       if(!zspan->rectmask || intzverg > *rm) {
+                               if ( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */
+                                       if (!zspan->rectmask || intzverg > *rm) {
                                                *ro= obi; /* UNIQUE LINE: see comment above (order differs) */
                                                *rz= intzverg;
                                                *rp= zvlnr;
@@ -1179,7 +1179,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        /* set spans */
        zbuf_add_to_span(zspan, v1, v2);
        zbuf_add_to_span(zspan, v2, v3);
-       if(v4) {
+       if (v4) {
                zbuf_add_to_span(zspan, v3, v4);
                zbuf_add_to_span(zspan, v4, v1);
        }
@@ -1187,13 +1187,13 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                zbuf_add_to_span(zspan, v3, v1);
 
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
 
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
 
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
 
 
        /* ZBUF DX DY, in floats still */
@@ -1207,7 +1207,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
 
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
 
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
 
@@ -1224,7 +1224,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
 
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -1233,16 +1233,16 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                span2= zspan->span1+my2;
        }
 
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
 
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++;
 
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
 
-               if(sn2>=sn1) {
+               if (sn2>=sn1) {
                        int intzverg;
 
                        zverg= (double)sn1*zxd + zy0;
@@ -1252,11 +1252,11 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                        rm= rectmaskofs+sn1;
                        x= sn2-sn1;
 
-                       while(x>=0) {
+                       while (x>=0) {
                                intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
 
-                               if(intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */
-                                       if(!zspan->rectmask || intzverg > *rm) {
+                               if (intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */
+                                       if (!zspan->rectmask || intzverg > *rm) {
                                                *rz= intzverg;
                                                *rp= zvlnr;
                                                *ro= obi; /* UNIQUE LINE: see comment above (order differs) */
@@ -1306,7 +1306,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
        /* set spans */
        zbuf_add_to_span(zspan, v1, v2);
        zbuf_add_to_span(zspan, v2, v3);
-       if(v4) {
+       if (v4) {
                zbuf_add_to_span(zspan, v3, v4);
                zbuf_add_to_span(zspan, v4, v1);
        }
@@ -1314,13 +1314,13 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
                zbuf_add_to_span(zspan, v3, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
        
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        
        /* ZBUF DX DY, in floats still */
@@ -1334,7 +1334,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
        
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
        
@@ -1345,12 +1345,12 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
        /* start-offset in rect */
        rectx= zspan->rectx;
        rectzofs= (zspan->rectz+rectx*my2);
-       if(zspan->rectz1)
+       if (zspan->rectz1)
                rectzofs1= (zspan->rectz1+rectx*my2);
        
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -1359,30 +1359,30 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
-               if(sn2>=sn1) {
+               if (sn2>=sn1) {
                        zverg= (double)sn1*zxd + zy0;
                        rz= rectzofs+sn1;
                        rz1= rectzofs1+sn1;
                        x= sn2-sn1;
                        
-                       while(x>=0) {
+                       while (x>=0) {
                                int zvergi= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
 
                                /* option: maintain two depth values, closest and 2nd closest */
-                               if(zvergi < *rz) {
-                                       if(rectzofs1) *rz1= *rz;
+                               if (zvergi < *rz) {
+                                       if (rectzofs1) *rz1= *rz;
                                        *rz= zvergi;
                                }
-                               else if(rectzofs1 && zvergi < *rz1)
+                               else if (rectzofs1 && zvergi < *rz1)
                                        *rz1= zvergi;
 
                                zverg+= zxd;
@@ -1395,7 +1395,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), f
                
                zy0-=zyd;
                rectzofs-= rectx;
-               if(rectzofs1) rectzofs1-= rectx;
+               if (rectzofs1) rectzofs1-= rectx;
        }
 }
 
@@ -1416,13 +1416,13 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2,
        zbuf_add_to_span(zspan, v3, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
        
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        /* ZBUF DX DY, in floats still */
        x1= v1[0]- v2[0];
@@ -1436,7 +1436,7 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2,
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
 
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
        zxd= -(double)x0/(double)z0;
@@ -1467,7 +1467,7 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2,
        
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -1476,20 +1476,20 @@ void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2,
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
                u= (double)sn1*uxd + uy0;
                v= (double)sn1*vxd + vy0;
                z= (double)sn1*zxd + zy0;
                
-               for(x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd)
+               for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd)
                        func(handle, x, y, u, v, z);
                
                uy0 -= uyd;
@@ -1516,13 +1516,13 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
        zbuf_add_to_span(zspan, v3, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
        
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        /* ZBUF DX DY, in floats still */
        x1= v1[0]- v2[0];
@@ -1537,7 +1537,7 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
        
        xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f;   
        uxd= -(double)x0/(double)z0;
@@ -1557,7 +1557,7 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
        
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -1566,19 +1566,19 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
                u= (double)sn1*uxd + uy0;
                v= (double)sn1*vxd + vy0;
                
-               for(x= sn1; x<=sn2; x++, u+=uxd, v+=vxd)
+               for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd)
                        func(handle, x, y, u, v);
                
                uy0 -= uyd;
@@ -1612,7 +1612,7 @@ static void clippyra(float *labda, float *v1, float *v2, int *b2, int *b3, int a
        da= v2[a]-v1[a];
        /* prob; we clip slightly larger, osa renders add 2 pixels on edges, should become variable? */
        /* or better; increase r.winx/y size, but thats quite a complex one. do it later */
-       if(a==2) {
+       if (a==2) {
                dw= (v2[3]-v1[3]);
                v13= v1[3];
        }
@@ -1627,18 +1627,21 @@ static void clippyra(float *labda, float *v1, float *v2, int *b2, int *b3, int a
         * who would have thought that of L&B!
         */
 
-       if(cliptestf(-da, -dw, v13, v1[a], &u1,&u2)) {
-               if(cliptestf(da, -dw, v13, -v1[a], &u1,&u2)) {
+       if (cliptestf(-da, -dw, v13, v1[a], &u1,&u2)) {
+               if (cliptestf(da, -dw, v13, -v1[a], &u1,&u2)) {
                        *b3=1;
-                       if(u2<1.0f) {
+                       if (u2<1.0f) {
                                labda[1]= u2;
                                *b2=1;
                        }
                        else labda[1]=1.0;  /* u2 */
-                       if(u1>0.0f) {
-                               labda[0]= u1;
-                               *b2=1;
-                       } else labda[0]=0.0;
+                       if (u1>0.0f) {
+                               labda[0] = u1;
+                               *b2 = 1;
+                       }
+                       else {
+                               labda[0] = 0.0;
+                       }
                }
        }
 }
@@ -1665,8 +1668,8 @@ static void makevertpyra(float *vez, float *labda, float **trias, float *v1, flo
        l1= labda[0];
        l2= labda[1];
 
-       if(l1!= -1.0f) {
-               if(l1!= 0.0f) {
+       if (l1!= -1.0f) {
+               if (l1!= 0.0f) {
                        adr= vez+4*(*clve);
                        trias[*b1]=adr;
                        (*clve)++;
@@ -1679,8 +1682,8 @@ static void makevertpyra(float *vez, float *labda, float **trias, float *v1, flo
                
                (*b1)++;
        }
-       if(l2!= -1.0f) {
-               if(l2!= 1.0f) {
+       if (l2!= -1.0f) {
+               if (l2!= 1.0f) {
                        adr= vez+4*(*clve);
                        trias[*b1]=adr;
                        (*clve)++;
@@ -1740,11 +1743,11 @@ static void zbuf_project_cache_clear(ZbufProjectCache *cache, int size)
 {
        int i;
 
-       if(size > ZBUF_PROJECT_CACHE_SIZE)
+       if (size > ZBUF_PROJECT_CACHE_SIZE)
                size= ZBUF_PROJECT_CACHE_SIZE;
 
        memset(cache, 0, sizeof(ZbufProjectCache)*size);
-       for(i=0; i<size; i++)
+       for (i=0; i<size; i++)
                cache[i].index= -1;
 }
 
@@ -1752,7 +1755,7 @@ static int zbuf_shadow_project(ZbufProjectCache *cache, int index, float winmat[
 {
        int cindex= index & 255;
 
-       if(cache[cindex].index == index) {
+       if (cache[cindex].index == index) {
                copy_v4_v4(ho, cache[cindex].ho);
                return cache[cindex].clip;
        }
@@ -1782,7 +1785,7 @@ static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][
        float vec[3];
        int cindex= index & 255;
 
-       if(cache[cindex].index == index) {
+       if (cache[cindex].index == index) {
                copy_v4_v4(ho, cache[cindex].ho);
                return cache[cindex].clip;
        }
@@ -1793,10 +1796,10 @@ static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[][
                projectvert(co, winmat, ho);
 
                wco= ho[3];
-               if(ho[0] < bounds[0]*wco) clipflag |= 1;
-               else if(ho[0] > bounds[1]*wco) clipflag |= 2;
-               if(ho[1] > bounds[3]*wco) clipflag |= 4;
-               else if(ho[1] < bounds[2]*wco) clipflag |= 8;
+               if (ho[0] < bounds[0]*wco) clipflag |= 1;
+               else if (ho[0] > bounds[1]*wco) clipflag |= 2;
+               if (ho[1] > bounds[3]*wco) clipflag |= 4;
+               else if (ho[1] < bounds[2]*wco) clipflag |= 8;
 
                copy_v4_v4(cache[cindex].ho, ho);
                cache[cindex].clip= clipflag;
@@ -1816,7 +1819,7 @@ void zbuf_render_project(float winmat[][4], const float co[3], float ho[4])
 
 void zbuf_make_winmat(Render *re, float winmat[][4])
 {
-       if(re->r.mode & R_PANORAMA) {
+       if (re->r.mode & R_PANORAMA) {
                float panomat[4][4]= MAT4_UNITY;
 
                panomat[0][0]= re->panoco;
@@ -1837,10 +1840,11 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3,
        float *vlzp[32][3], labda[3][2];
        float vez[400], *trias[40];
        
-       if(c1 | c2 | c3) {      /* not in middle */
-               if(c1 & c2 & c3) {      /* completely out */
+       if (c1 | c2 | c3) {     /* not in middle */
+               if (c1 & c2 & c3) {     /* completely out */
                        return;
-               } else {        /* clipping */
+               }
+               else {  /* clipping */
                        int arg, v, b, clipflag[3], b1, b2, b3, c4, clve=3, clvlo, clvl=1;
 
                        vez[0]= f1[0]; vez[1]= f1[1]; vez[2]= f1[2]; vez[3]= f1[3];
@@ -1852,24 +1856,24 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3,
                        vlzp[0][2]= vez+8;
 
                        clipflag[0]= ( (c1 & 48) | (c2 & 48) | (c3 & 48) );
-                       if(clipflag[0]==0) {    /* othwerwise it needs to be calculated again, after the first (z) clip */
+                       if (clipflag[0]==0) {   /* othwerwise it needs to be calculated again, after the first (z) clip */
                                clipflag[1]= ( (c1 & 3) | (c2 & 3) | (c3 & 3) );
                                clipflag[2]= ( (c1 & 12) | (c2 & 12) | (c3 & 12) );
                        }
                        else clipflag[1]=clipflag[2]= 0;
                        
-                       for(b=0;b<3;b++) {
+                       for (b=0;b<3;b++) {
                                
-                               if(clipflag[b]) {
+                               if (clipflag[b]) {
                                
                                        clvlo= clvl;
                                        
-                                       for(v=0; v<clvlo; v++) {
+                                       for (v=0; v<clvlo; v++) {
                                        
-                                               if(vlzp[v][0]!=NULL) {  /* face is still there */
+                                               if (vlzp[v][0]!=NULL) { /* face is still there */
                                                        b2= b3 =0;      /* clip flags */
 
-                                                       if(b==0) arg= 2;
+                                                       if (b==0) arg= 2;
                                                        else if (b==1) arg= 0;
                                                        else arg= 1;
                                                        
@@ -1877,27 +1881,29 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3,
                                                        clippyra(labda[1], vlzp[v][1],vlzp[v][2], &b2,&b3, arg, zspan->clipcrop);
                                                        clippyra(labda[2], vlzp[v][2],vlzp[v][0], &b2,&b3, arg, zspan->clipcrop);
 
-                                                       if(b2==0 && b3==1) {
+                                                       if (b2==0 && b3==1) {
                                                                /* completely 'in', but we copy because of last for() loop in this section */;
                                                                vlzp[clvl][0]= vlzp[v][0];
                                                                vlzp[clvl][1]= vlzp[v][1];
                                                                vlzp[clvl][2]= vlzp[v][2];
                                                                vlzp[v][0]= NULL;
                                                                clvl++;
-                                                       } else if(b3==0) {
+                                                       }
+                                                       else if (b3==0) {
                                                                vlzp[v][0]= NULL;
                                                                /* completely 'out' */;
-                                                       } else {
+                                                       }
+                                                       else {
                                                                b1=0;
                                                                makevertpyra(vez, labda[0], trias, vlzp[v][0],vlzp[v][1], &b1,&clve);
                                                                makevertpyra(vez, labda[1], trias, vlzp[v][1],vlzp[v][2], &b1,&clve);
                                                                makevertpyra(vez, labda[2], trias, vlzp[v][2],vlzp[v][0], &b1,&clve);
 
                                                                /* after front clip done: now set clip flags */
-                                                               if(b==0) {
+                                                               if (b==0) {
                                                                        clipflag[1]= clipflag[2]= 0;
                                                                        f1= vez;
-                                                                       for(b3=0; b3<clve; b3++) {
+                                                                       for (b3=0; b3<clve; b3++) {
                                                                                c4= testclip(f1);
                                                                                clipflag[1] |= (c4 & 3);
                                                                                clipflag[2] |= (c4 & 12);
@@ -1906,8 +1912,8 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3,
                                                                }
                                                                
                                                                vlzp[v][0]= NULL;
-                                                               if(b1>2) {
-                                                                       for(b3=3; b3<=b1; b3++) {
+                                                               if (b1>2) {
+                                                                       for (b3=3; b3<=b1; b3++) {
                                                                                vlzp[clvl][0]= trias[0];
                                                                                vlzp[clvl][1]= trias[b3-2];
                                                                                vlzp[clvl][2]= trias[b3-1];
@@ -1921,16 +1927,16 @@ void zbufclip(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3,
                        }
 
                        /* warning, this should never happen! */
-                       if(clve>38 || clvl>31) printf("clip overflow: clve clvl %d %d\n",clve,clvl);
+                       if (clve>38 || clvl>31) printf("clip overflow: clve clvl %d %d\n",clve,clvl);
 
                        /* perspective division */
                        f1=vez;
-                       for(c1=0;c1<clve;c1++) {
+                       for (c1=0;c1<clve;c1++) {
                                hoco_to_zco(zspan, f1, f1);
                                f1+=4;
                        }
-                       for(b=1;b<clvl;b++) {
-                               if(vlzp[b][0]) {
+                       for (b=1;b<clvl;b++) {
+                               if (vlzp[b][0]) {
                                        zspan->zbuffunc(zspan, obi, zvlnr, vlzp[b][0],vlzp[b][1],vlzp[b][2], NULL);
                                }
                        }
@@ -1949,10 +1955,11 @@ void zbufclip4(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3
 {
        float vez[16];
        
-       if(c1 | c2 | c3 | c4) { /* not in middle */
-               if(c1 & c2 & c3 & c4) { /* completely out */
+       if (c1 | c2 | c3 | c4) {        /* not in middle */
+               if (c1 & c2 & c3 & c4) {        /* completely out */
                        return;
-               } else {        /* clipping */
+               }
+               else {  /* clipping */
                        zbufclip(zspan, obi, zvlnr, f1, f2, f3, c1, c2, c3);
                        zbufclip(zspan, obi, zvlnr, f1, f3, f4, c1, c3, c4);
                }
@@ -1970,7 +1977,7 @@ void zbufclip4(ZSpan *zspan, int obi, int zvlnr, float *f1, float *f2, float *f3
 
 /* ************** ZMASK ******************************** */
 
-#define EXTEND_PIXEL(a)        if(temprectp[a]) {z+= rectz[a]; tot++;}
+#define EXTEND_PIXEL(a)        if (temprectp[a]) {z+= rectz[a]; tot++;}
 
 /* changes the zbuffer to be ready for z-masking: applies an extend-filter, and then clears */
 static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg)
@@ -1983,21 +1990,21 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg)
        
        /* extend: if pixel is not filled in, we check surrounding pixels and average z value  */
        
-       for(y=1; y<=ys; y++) {
+       for (y=1; y<=ys; y++) {
                /* setup row indices */
                row1= (y-2)*xs;
                row2= row1 + xs;
                row3= row2 + xs;
-               if(y==1)
+               if (y==1)
                        row1= row2;
-               else if(y==ys)
+               else if (y==ys)
                        row3= row2;
                
                curp= rectp + (y-1)*xs;
                curz= rectz + (y-1)*xs;
                
-               for(x=0; x<xs; x++, curp++, curz++) {
-                       if(curp[0]==0) {
+               for (x=0; x<xs; x++, curp++, curz++) {
+                       if (curp[0]==0) {
                                int tot= 0;
                                float z= 0.0f;
                                
@@ -2006,19 +2013,19 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg)
                                EXTEND_PIXEL(row3);
                                EXTEND_PIXEL(row1 + 1);
                                EXTEND_PIXEL(row3 + 1);
-                               if(x!=xs-1) {
+                               if (x!=xs-1) {
                                        EXTEND_PIXEL(row1 + 2);
                                        EXTEND_PIXEL(row2 + 2);
                                        EXTEND_PIXEL(row3 + 2);
                                }                                       
-                               if(tot) {
+                               if (tot) {
                                        len++;
                                        curz[0]= (int)(z/(float)tot);
                                        curp[0]= -1;    /* env */
                                }
                        }
                        
-                       if(x!=0) {
+                       if (x!=0) {
                                row1++; row2++; row3++;
                        }
                }
@@ -2026,11 +2033,11 @@ static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg)
 
        MEM_freeN(temprectp);
        
-       if(neg); /* z values for negative are already correct */
+       if (neg); /* z values for negative are already correct */
        else {
                /* clear not filled z values */
-               for(len= xs*ys -1; len>=0; len--) {
-                       if(rectp[len]==0) {
+               for (len= xs*ys -1; len>=0; len--) {
+                       if (rectp[len]==0) {
                                rectz[len] = -0x7FFFFFFF;
                                rectp[len]= -1; /* env code */
                        }       
@@ -2065,7 +2072,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
        samples= (R.osa? R.osa: 1);
        samples= MIN2(4, samples-pa->sample);
 
-       for(zsample=0; zsample<samples; zsample++) {
+       for (zsample=0; zsample<samples; zsample++) {
                zspan= &zspans[zsample];
 
                zbuffer_part_bounds(R.winx, R.winy, pa, bounds);
@@ -2075,11 +2082,11 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                zspan->zmulx= ((float)R.winx)/2.0f;
                zspan->zmuly= ((float)R.winy)/2.0f;
                
-               if(R.osa) {
+               if (R.osa) {
                        zspan->zofsx= -pa->disprect.xmin - R.jit[pa->sample+zsample][0];
                        zspan->zofsy= -pa->disprect.ymin - R.jit[pa->sample+zsample][1];
                }
-               else if(R.i.curblur) {
+               else if (R.i.curblur) {
                        zspan->zofsx= -pa->disprect.xmin - R.mblur_jit[R.i.curblur-1][0];
                        zspan->zofsy= -pa->disprect.ymin - R.mblur_jit[R.i.curblur-1][1];
                }
@@ -2092,11 +2099,11 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                zspan->zofsy -= 0.5f;
                
                /* the buffers */
-               if(zsample == samples-1) {
+               if (zsample == samples-1) {
                        zspan->rectp= pa->rectp;
                        zspan->recto= pa->recto;
 
-                       if(neg_zmask)
+                       if (neg_zmask)
                                zspan->rectz= pa->rectmask;
                        else
                                zspan->rectz= pa->rectz;
@@ -2113,17 +2120,17 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
        }
 
        /* in case zmask we fill Z for objects in lay_zmask first, then clear Z, and then do normal zbuffering */
-       if(rl->layflag & SCE_LAY_ZMASK)
+       if (rl->layflag & SCE_LAY_ZMASK)
                zmaskpass= 1;
        
-       for(; zmaskpass >=0; zmaskpass--) {
+       for (; zmaskpass >=0; zmaskpass--) {
                ma= NULL;
 
                /* filling methods */
-               for(zsample=0; zsample<samples; zsample++) {
+               for (zsample=0; zsample<samples; zsample++) {
                        zspan= &zspans[zsample];
 
-                       if(zmaskpass && neg_zmask)
+                       if (zmaskpass && neg_zmask)
                                zspan->zbuffunc= zbuffillGLinv4;
                        else
                                zspan->zbuffunc= zbuffillGL4;
@@ -2131,48 +2138,48 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                }
 
                /* regular zbuffering loop, does all sample buffers */
-               for(i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
+               for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
                        obr= obi->obr;
 
                        /* continue happens in 2 different ways... zmaskpass only does lay_zmask stuff */
-                       if(zmaskpass) {
-                               if((obi->lay & lay_zmask)==0)
+                       if (zmaskpass) {
+                               if ((obi->lay & lay_zmask)==0)
                                        continue;
                        }
-                       else if(!all_z && !(obi->lay & (lay|lay_zmask)))
+                       else if (!all_z && !(obi->lay & (lay|lay_zmask)))
                                continue;
                        
-                       if(obi->flag & R_TRANSFORMED)
+                       if (obi->flag & R_TRANSFORMED)
                                mult_m4_m4m4(obwinmat, winmat, obi->mat);
                        else
                                copy_m4_m4(obwinmat, winmat);
 
-                       if(clip_render_object(obi->obr->boundbox, bounds, obwinmat))
+                       if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
                                continue;
 
                        zbuf_project_cache_clear(cache, obr->totvert);
 
-                       for(v=0; v<obr->totvlak; v++) {
-                               if((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
+                       for (v=0; v<obr->totvlak; v++) {
+                               if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
                                else vlr++;
 
                                /* the cases: visible for render, only z values, zmask, nothing */
-                               if(obi->lay & lay) {
-                                       if(vlr->mat!=ma) {
+                               if (obi->lay & lay) {
+                                       if (vlr->mat!=ma) {
                                                ma= vlr->mat;
                                                nofill= (ma->mode & MA_ONLYCAST) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP));
                                                env= (ma->mode & MA_ENV);
                                                wire= (ma->material_type == MA_TYPE_WIRE);
                                                
-                                               for(zsample=0; zsample<samples; zsample++) {
-                                                       if(ma->mode & MA_ZINV || (zmaskpass && neg_zmask))
+                                               for (zsample=0; zsample<samples; zsample++) {
+                                                       if (ma->mode & MA_ZINV || (zmaskpass && neg_zmask))
                                                                zspans[zsample].zbuffunc= zbuffillGLinv4;
                                                        else
                                                                zspans[zsample].zbuffunc= zbuffillGL4;
                                                }
                                        }
                                }
-                               else if(all_z || (obi->lay & lay_zmask)) {
+                               else if (all_z || (obi->lay & lay_zmask)) {
                                        env= 1;
                                        nofill= 0;
                                        ma= NULL; 
@@ -2182,7 +2189,7 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                                        ma= NULL;       /* otherwise nofill can hang */
                                }
 
-                               if(!(vlr->flag & R_HIDDEN) && nofill==0) {
+                               if (!(vlr->flag & R_HIDDEN) && nofill==0) {
                                        unsigned short partclip;
                                        
                                        v1= vlr->v1;
@@ -2196,39 +2203,39 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
 
                                        /* partclipping doesn't need viewplane clipping */
                                        partclip= c1 & c2 & c3;
-                                       if(v4) {
+                                       if (v4) {
                                                c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
                                                partclip &= c4;
                                        }
 
-                                       if(partclip==0) {
+                                       if (partclip==0) {
                                                
-                                               if(env) zvlnr= -1;
+                                               if (env) zvlnr= -1;
                                                else zvlnr= v+1;
 
                                                c1= testclip(ho1);
                                                c2= testclip(ho2);
                                                c3= testclip(ho3);
-                                               if(v4)
+                                               if (v4)
                                                        c4= testclip(ho4);
 
-                                               for(zsample=0; zsample<samples; zsample++) {
+                                               for (zsample=0; zsample<samples; zsample++) {
                                                        zspan= &zspans[zsample];
 
-                                                       if(wire) {
-                                                               if(v4)
+                                                       if (wire) {
+                                                               if (v4)
                                                                        zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                                                else
                                                                        zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0);
                                                        }
                                                        else {
                                                                /* strands allow to be filled in as quad */
-                                                               if(v4 && (vlr->flag & R_STRAND)) {
+                                                               if (v4 && (vlr->flag & R_STRAND)) {
                                                                        zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                                                }
                                                                else {
                                                                        zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
-                                                                       if(v4)
+                                                                       if (v4)
                                                                                zbufclip(zspan, i, (env)? zvlnr: zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
                                                                }
                                                        }
@@ -2239,13 +2246,13 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                }
                
                /* clear all z to close value, so it works as mask for next passes (ztra+strand) */
-               if(zmaskpass) {
-                       for(zsample=0; zsample<samples; zsample++) {
+               if (zmaskpass) {
+                       for (zsample=0; zsample<samples; zsample++) {
                                zspan= &zspans[zsample];
 
-                               if(neg_zmask) {
+                               if (neg_zmask) {
                                        zspan->rectmask= zspan->rectz;
-                                       if(zsample == samples-1)
+                                       if (zsample == samples-1)
                                                zspan->rectz= pa->rectz;
                                        else
                                                zspan->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
@@ -2259,17 +2266,17 @@ void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart*,
                }
        }
 
-       for(zsample=0; zsample<samples; zsample++) {
+       for (zsample=0; zsample<samples; zsample++) {
                zspan= &zspans[zsample];
 
-               if(fillfunc)
+               if (fillfunc)
                        fillfunc(pa, zspan, pa->sample+zsample, data);
 
-               if(zsample != samples-1) {
+               if (zsample != samples-1) {
                        MEM_freeN(zspan->rectz);
                        MEM_freeN(zspan->rectp);
                        MEM_freeN(zspan->recto);
-                       if(zspan->rectmask)
+                       if (zspan->rectmask)
                                MEM_freeN(zspan->rectmask);
                }
 
@@ -2292,7 +2299,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
        float obwinmat[4][4], ho1[4], ho2[4], ho3[4], ho4[4];
        int a, b, c, i, c1, c2, c3, c4, ok=1, lay= -1;
 
-       if(lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay;
+       if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay;
 
        /* 1.0f for clipping in clippyra()... bad stuff actually */
        zbuf_alloc_span(&zspan, size, size, 1.0f);
@@ -2305,7 +2312,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
        /* the buffers */
        zspan.rectz= rectz;
        fillrect(rectz, size, size, 0x7FFFFFFE);
-       if(lar->buftype==LA_SHADBUF_HALFWAY) {
+       if (lar->buftype==LA_SHADBUF_HALFWAY) {
                zspan.rectz1= MEM_mallocN(size*size*sizeof(int), "seconday z buffer");
                fillrect(zspan.rectz1, size, size, 0x7FFFFFFE);
        }
@@ -2314,44 +2321,44 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
        zspan.zbuflinefunc= zbufline_onlyZ;
        zspan.zbuffunc= zbuffillGL_onlyZ;
 
-       for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
+       for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
                obr= obi->obr;
 
-               if(obr->ob==re->excludeob)
+               if (obr->ob==re->excludeob)
                        continue;
-               else if(!(obi->lay & lay))
+               else if (!(obi->lay & lay))
                        continue;
 
-               if(obi->flag & R_TRANSFORMED)
+               if (obi->flag & R_TRANSFORMED)
                        mult_m4_m4m4(obwinmat, winmat, obi->mat);
                else
                        copy_m4_m4(obwinmat, winmat);
 
-               if(clip_render_object(obi->obr->boundbox, NULL, obwinmat))
+               if (clip_render_object(obi->obr->boundbox, NULL, obwinmat))
                        continue;
 
                zbuf_project_cache_clear(cache, obr->totvert);
 
                /* faces */
-               for(a=0; a<obr->totvlak; a++) {
+               for (a=0; a<obr->totvlak; a++) {
 
-                       if((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
+                       if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
                        else vlr++;
 
                        /* note, these conditions are copied in shadowbuf_autoclip() */
-                       if(vlr->mat!= ma) {
+                       if (vlr->mat!= ma) {
                                ma= vlr->mat;
                                ok= 1;
-                               if((ma->mode & MA_SHADBUF)==0) ok= 0;
+                               if ((ma->mode & MA_SHADBUF)==0) ok= 0;
                        }
 
-                       if(ok && (obi->lay & lay) && !(vlr->flag & R_HIDDEN)) {
+                       if (ok && (obi->lay & lay) && !(vlr->flag & R_HIDDEN)) {
                                c1= zbuf_shadow_project(cache, vlr->v1->index, obwinmat, vlr->v1->co, ho1);
                                c2= zbuf_shadow_project(cache, vlr->v2->index, obwinmat, vlr->v2->co, ho2);
                                c3= zbuf_shadow_project(cache, vlr->v3->index, obwinmat, vlr->v3->co, ho3);
 
-                               if((ma->material_type == MA_TYPE_WIRE) || (vlr->flag & R_STRAND)) {
-                                       if(vlr->v4) {
+                               if ((ma->material_type == MA_TYPE_WIRE) || (vlr->flag & R_STRAND)) {
+                                       if (vlr->v4) {
                                                c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4);
                                                zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                        }
@@ -2359,7 +2366,7 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
                                                zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0);
                                }
                                else {
-                                       if(vlr->v4) {
+                                       if (vlr->v4) {
                                                c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4);
                                                zbufclip4(&zspan, 0, 0, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                        }
@@ -2368,20 +2375,20 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
                                }
                        }
 
-                       if((a & 255)==255 && re->test_break(re->tbh)) 
+                       if ((a & 255)==255 && re->test_break(re->tbh)) 
                                break;
                }
 
                /* strands */
-               if(obr->strandbuf) {
+               if (obr->strandbuf) {
                        /* for each bounding box containing a number of strands */
                        sbound= obr->strandbuf->bound;
-                       for(c=0; c<obr->strandbuf->totbound; c++, sbound++) {
-                               if(clip_render_object(sbound->boundbox, NULL, obwinmat))
+                       for (c=0; c<obr->strandbuf->totbound; c++, sbound++) {
+                               if (clip_render_object(sbound->boundbox, NULL, obwinmat))
                                        continue;
 
                                /* for each strand in this bounding box */
-                               for(a=sbound->start; a<sbound->end; a++) {
+                               for (a=sbound->start; a<sbound->end; a++) {
                                        strand= RE_findOrAddStrand(obr, a);
 
                                        sseg.obi= obi;
@@ -2392,16 +2399,16 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
                                        svert= strand->vert;
 
                                        /* note, these conditions are copied in shadowbuf_autoclip() */
-                                       if(sseg.buffer->ma!= ma) {
+                                       if (sseg.buffer->ma!= ma) {
                                                ma= sseg.buffer->ma;
                                                ok= 1;
-                                               if((ma->mode & MA_SHADBUF)==0) ok= 0;
+                                               if ((ma->mode & MA_SHADBUF)==0) ok= 0;
                                        }
 
-                                       if(ok && (sseg.buffer->lay & lay)) {
+                                       if (ok && (sseg.buffer->lay & lay)) {
                                                zbuf_project_cache_clear(cache, strand->totvert);
 
-                                               for(b=0; b<strand->totvert-1; b++, svert++) {
+                                               for (b=0; b<strand->totvert-1; b++, svert++) {
                                                        sseg.v[0]= (b > 0)? (svert-1): svert;
                                                        sseg.v[1]= svert;
                                                        sseg.v[2]= svert+1;
@@ -2412,24 +2419,24 @@ void zbuffer_shadow(Render *re, float winmat[][4], LampRen *lar, int *rectz, int
                                                        c3= zbuf_shadow_project(cache, sseg.v[2]-strand->vert, obwinmat, sseg.v[2]->co, ho3);
                                                        c4= zbuf_shadow_project(cache, sseg.v[3]-strand->vert, obwinmat, sseg.v[3]->co, ho4);
 
-                                                       if(!(c1 & c2 & c3 & c4))
+                                                       if (!(c1 & c2 & c3 & c4))
                                                                render_strand_segment(re, winmat, NULL, &zspan, 1, &sseg);
                                                }
                                        }
 
-                                       if((a & 255)==255 && re->test_break(re->tbh)) 
+                                       if ((a & 255)==255 && re->test_break(re->tbh)) 
                                                break;
                                }
                        }
                }
 
-               if(re->test_break(re->tbh)) 
+               if (re->test_break(re->tbh)) 
                        break;
        }
        
        /* merge buffers */
-       if(lar->buftype==LA_SHADBUF_HALFWAY) {
-               for(a=size*size -1; a>=0; a--)
+       if (lar->buftype==LA_SHADBUF_HALFWAY) {
+               for (a=size*size -1; a>=0; a--)
                        rectz[a]= (rectz[a]>>1) + (zspan.rectz1[a]>>1);
                
                MEM_freeN(zspan.rectz1);
@@ -2449,7 +2456,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        /* set spans */
        zbuf_add_to_span(zspan, v1, v2);
        zbuf_add_to_span(zspan, v2, v3);
-       if(v4) {
+       if (v4) {
                zbuf_add_to_span(zspan, v3, v4);
                zbuf_add_to_span(zspan, v4, v1);
        }
@@ -2457,12 +2464,12 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                zbuf_add_to_span(zspan, v3, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
        
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        /* ZBUF DX DY, in floats still */
        x1= v1[0]- v2[0];
@@ -2476,7 +2483,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
        
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
        zxd= -(double)x0/(double)z0;
@@ -2485,7 +2492,7 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
        
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -2494,17 +2501,17 @@ static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr, float *v1, float *v2,
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
                z= (double)sn1*zxd + zy0;
                
-               for(x= sn1; x<=sn2; x++, z+=zxd)
+               for (x= sn1; x<=sn2; x++, z+=zxd)
                        zspan->sss_func(zspan->sss_handle, obi, zvlnr, x, y, z);
                
                zy0 -= zyd;
@@ -2544,41 +2551,41 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo
        zspan.zbuffunc= zbuffill_sss;
 
        /* fill front and back zbuffer */
-       if(pa->rectz) {
+       if (pa->rectz) {
                fillrect(pa->recto, pa->rectx, pa->recty, 0); 
                fillrect(pa->rectp, pa->rectx, pa->recty, 0); 
                fillrect(pa->rectz, pa->rectx, pa->recty, 0x7FFFFFFF);
        }
-       if(pa->rectbackz) {
+       if (pa->rectbackz) {
                fillrect(pa->rectbacko, pa->rectx, pa->recty, 0); 
                fillrect(pa->rectbackp, pa->rectx, pa->recty, 0); 
                fillrect(pa->rectbackz, pa->rectx, pa->recty, -0x7FFFFFFF);
        }
 
-       for(i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
+       for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
                obr= obi->obr;
 
-               if(!(obi->lay & lay))
+               if (!(obi->lay & lay))
                        continue;
 
-               if(obi->flag & R_TRANSFORMED)
+               if (obi->flag & R_TRANSFORMED)
                        mult_m4_m4m4(obwinmat, winmat, obi->mat);
                else
                        copy_m4_m4(obwinmat, winmat);
 
-               if(clip_render_object(obi->obr->boundbox, bounds, obwinmat))
+               if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
                        continue;
 
                zbuf_project_cache_clear(cache, obr->totvert);
 
-               for(v=0; v<obr->totvlak; v++) {
-                       if((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
+               for (v=0; v<obr->totvlak; v++) {
+                       if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
                        else vlr++;
                        
-                       if(material_in_material(vlr->mat, sss_ma)) {
+                       if (material_in_material(vlr->mat, sss_ma)) {
                                /* three cases, visible for render, only z values and nothing */
-                               if(obi->lay & lay) {
-                                       if(vlr->mat!=ma) {
+                               if (obi->lay & lay) {
+                                       if (vlr->mat!=ma) {
                                                ma= vlr->mat;
                                                nofill= ma->mode & MA_ONLYCAST;
                                                env= (ma->mode & MA_ENV);
@@ -2590,7 +2597,7 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo
                                        ma= NULL;       /* otherwise nofill can hang */
                                }
                                
-                               if(nofill==0 && wire==0 && env==0) {
+                               if (nofill==0 && wire==0 && env==0) {
                                        unsigned short partclip;
                                        
                                        v1= vlr->v1;
@@ -2604,19 +2611,19 @@ void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(vo
 
                                        /* partclipping doesn't need viewplane clipping */
                                        partclip= c1 & c2 & c3;
-                                       if(v4) {
+                                       if (v4) {
                                                c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
                                                partclip &= c4;
                                        }
 
-                                       if(partclip==0) {
+                                       if (partclip==0) {
                                                c1= testclip(ho1);
                                                c2= testclip(ho2);
                                                c3= testclip(ho3);
 
                                                zvlnr= v+1;
                                                zbufclip(&zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
-                                               if(v4) {
+                                               if (v4) {
                                                        c4= testclip(ho4);
                                                        zbufclip(&zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
                                                }
@@ -2658,13 +2665,13 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float
        zbuf_add_to_span(zspan, v4, v1);
        
        /* clipped */
-       if(zspan->minp2==NULL || zspan->maxp2==NULL) return;
+       if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
        
-       if(zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
-       if(zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
+       if (zspan->miny1 < zspan->miny2) my0= zspan->miny2; else my0= zspan->miny1;
+       if (zspan->maxy1 > zspan->maxy2) my2= zspan->maxy2; else my2= zspan->maxy1;
        
        //      printf("my %d %d\n", my0, my2);
-       if(my2<my0) return;
+       if (my2<my0) return;
        
        /* ZBUF DX DY, in floats still */
        x1= v1[0]- v2[0];
@@ -2677,7 +2684,7 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float
        y0= z1*x2-x1*z2;
        z0= x1*y2-y1*x2;
        
-       if(z0==0.0f) return;
+       if (z0==0.0f) return;
        
        xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
        
@@ -2692,7 +2699,7 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float
        
        /* correct span */
        sn1= (my0 + my2)/2;
-       if(zspan->span1[sn1] < zspan->span2[sn1]) {
+       if (zspan->span1[sn1] < zspan->span2[sn1]) {
                span1= zspan->span1+my2;
                span2= zspan->span2+my2;
        }
@@ -2701,23 +2708,23 @@ static void zbuf_fill_in_rgba(ZSpan *zspan, DrawBufPixel *col, float *v1, float
                span2= zspan->span1+my2;
        }
        
-       for(y=my2; y>=my0; y--, span1--, span2--) {
+       for (y=my2; y>=my0; y--, span1--, span2--) {
                
                sn1= floor(*span1);
                sn2= floor(*span2);
                sn1++; 
                
-               if(sn2>=rectx) sn2= rectx-1;
-               if(sn1<0) sn1= 0;
+               if (sn2>=rectx) sn2= rectx-1;
+               if (sn1<0) sn1= 0;
                
-               if(sn2>=sn1) {
+               if (sn2>=sn1) {
                        zverg= (double)sn1*zxd + zy0;
                        rz= rectzofs+sn1;
                        rp= rectpofs+sn1;
                        x= sn2-sn1;
                        
-                       while(x>=0) {
-                               if( zverg < *rz) {
+                       while (x>=0) {
+                               if ( zverg < *rz) {
                                        *rz= zverg;
                                        *rp= *col;
                                }
@@ -2743,14 +2750,14 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove)
        int a, x, y, step;
        
        /* 1: tag pixels to be candidate for AA */
-       for(y=2; y<ysize; y++) {
+       for (y=2; y<ysize; y++) {
                /* setup rows */
                row1= rectmove + (y-2)*xsize;
                row2= row1 + xsize;
                row3= row2 + xsize;
-               for(x=2; x<xsize; x++, row1++, row2++, row3++) {
-                       if(row2[1]) {
-                               if(row2[0]==0 || row2[2]==0 || row1[1]==0 || row3[1]==0)
+               for (x=2; x<xsize; x++, row1++, row2++, row3++) {
+                       if (row2[1]) {
+                               if (row2[0]==0 || row2[2]==0 || row1[1]==0 || row3[1]==0)
                                        row2[1]= 128;
                        }
                }
@@ -2758,22 +2765,22 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove)
        
        /* 2: evaluate horizontal scanlines and calculate alphas */
        row1= rectmove;
-       for(y=0; y<ysize; y++) {
+       for (y=0; y<ysize; y++) {
                row1++;
-               for(x=1; x<xsize; x++, row1++) {
-                       if(row1[0]==128 && row1[1]==128) {
+               for (x=1; x<xsize; x++, row1++) {
+                       if (row1[0]==128 && row1[1]==128) {
                                /* find previous color and next color and amount of steps to blend */
                                prev= row1[-1];
                                step= 1;
-                               while(x+step<xsize && row1[step]==128)
+                               while (x+step<xsize && row1[step]==128)
                                        step++;
                                
-                               if(x+step!=xsize) {
+                               if (x+step!=xsize) {
                                        /* now we can blend values */
                                        next= row1[step];
 
                                        /* note, prev value can be next value, but we do this loop to clear 128 then */
-                                       for(a=0; a<step; a++) {
+                                       for (a=0; a<step; a++) {
                                                int fac, mfac;
                                                
                                                fac= ((a+1)<<8)/(step+1);
@@ -2788,22 +2795,22 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove)
        
        /* 3: evaluate vertical scanlines and calculate alphas */
        /*    use for reading a copy of the original tagged buffer */
-       for(x=0; x<xsize; x++) {
+       for (x=0; x<xsize; x++) {
                row1= rectmove + x+xsize;
                
-               for(y=1; y<ysize; y++, row1+=xsize) {
-                       if(row1[0]==128 && row1[xsize]==128) {
+               for (y=1; y<ysize; y++, row1+=xsize) {
+                       if (row1[0]==128 && row1[xsize]==128) {
                                /* find previous color and next color and amount of steps to blend */
                                prev= row1[-xsize];
                                step= 1;
-                               while(y+step<ysize && row1[step*xsize]==128)
+                               while (y+step<ysize && row1[step*xsize]==128)
                                        step++;
                                
-                               if(y+step!=ysize) {
+                               if (y+step!=ysize) {
                                        /* now we can blend values */
                                        next= row1[step*xsize];
                                        /* note, prev value can be next value, but we do this loop to clear 128 then */
-                                       for(a=0; a<step; a++) {
+                                       for (a=0; a<step; a++) {
                                                int fac, mfac;
                                                
                                                fac= ((a+1)<<8)/(step+1);
@@ -2817,14 +2824,14 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove)
        }
        
        /* last: pixels with 0 we fill in zbuffer, with 1 we skip for mask */
-       for(y=2; y<ysize; y++) {
+       for (y=2; y<ysize; y++) {
                /* setup rows */
                row1= rectmove + (y-2)*xsize;
                row2= row1 + xsize;
                row3= row2 + xsize;
-               for(x=2; x<xsize; x++, row1++, row2++, row3++) {
-                       if(row2[1]==0) {
-                               if(row2[0]>1 || row2[2]>1 || row1[1]>1 || row3[1]>1)
+               for (x=2; x<xsize; x++, row1++, row2++, row3++) {
+                       if (row2[1]==0) {
+                               if (row2[0]>1 || row2[2]>1 || row1[1]>1 || row3[1]>1)
                                        row2[1]= 1;
                        }
                }
@@ -2895,16 +2902,16 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        
        /* debug... check if PASS_VECTOR_MAX still is in buffers */
        dvec1= vecbufrect;
-       for(x= 4*xsize*ysize; x>0; x--, dvec1++) {
-               if(dvec1[0]==PASS_VECTOR_MAX) {
+       for (x= 4*xsize*ysize; x>0; x--, dvec1++) {
+               if (dvec1[0]==PASS_VECTOR_MAX) {
                        dvec1[0]= 0.0f;
                        tsktsk= 1;
                }
        }
-       if(tsktsk) printf("Found uninitialized speed in vector buffer... fixed.\n");
+       if (tsktsk) printf("Found uninitialized speed in vector buffer... fixed.\n");
        
        /* min speed? then copy speedbuffer to recalculate speed vectors */
-       if(nbd->minspeed) {
+       if (nbd->minspeed) {
                float minspeed= (float)nbd->minspeed;
                float minspeedsq= minspeed*minspeed;
                
@@ -2912,14 +2919,14 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
                
                dvec1= vecbufrect;
                dvec2= minvecbufrect;
-               for(x= 2*xsize*ysize; x>0; x--, dvec1+=2, dvec2+=2) {
-                       if(dvec1[0]==0.0f && dvec1[1]==0.0f) {
+               for (x= 2*xsize*ysize; x>0; x--, dvec1+=2, dvec2+=2) {
+                       if (dvec1[0]==0.0f && dvec1[1]==0.0f) {
                                dvec2[0]= dvec1[0];
                                dvec2[1]= dvec1[1];
                        }
                        else {
                                float speedsq= dvec1[0]*dvec1[0] + dvec1[1]*dvec1[1];
-                               if(speedsq <= minspeedsq) {
+                               if (speedsq <= minspeedsq) {
                                        dvec2[0]= 0.0f;
                                        dvec2[1]= 0.0f;
                                }
@@ -2936,70 +2943,70 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        /* make vertex buffer with averaged speed and zvalues */
        rectvz= MEM_mapallocN(4*sizeof(float)*(xsize+1)*(ysize+1), "vertices");
        dvz= rectvz;
-       for(y=0; y<=ysize; y++) {
+       for (y=0; y<=ysize; y++) {
                
-               if(y==0)
+               if (y==0)
                        dvec1= vecbufrect + 4*y*xsize;
                else
                        dvec1= vecbufrect + 4*(y-1)*xsize;
                
-               if(y==ysize)
+               if (y==ysize)
                        dvec2= vecbufrect + 4*(y-1)*xsize;
                else
                        dvec2= vecbufrect + 4*y*xsize;
                
-               for(x=0; x<=xsize; x++) {
+               for (x=0; x<=xsize; x++) {
                        
                        /* two vectors, so a step loop */
-                       for(step=0; step<2; step++, dvec1+=2, dvec2+=2, dvz+=2) {
+                       for (step=0; step<2; step++, dvec1+=2, dvec2+=2, dvz+=2) {
                                /* average on minimal speed */
                                int div= 0;
                                
-                               if(x!=0) {
-                                       if(dvec1[-4]!=0.0f || dvec1[-3]!=0.0f) {
+                               if (x!=0) {
+                                       if (dvec1[-4]!=0.0f || dvec1[-3]!=0.0f) {
                                                dvz[0]= dvec1[-4];
                                                dvz[1]= dvec1[-3];
                                                div++;
                                        }
-                                       if(dvec2[-4]!=0.0f || dvec2[-3]!=0.0f) {
-                                               if(div==0) {
+                                       if (dvec2[-4]!=0.0f || dvec2[-3]!=0.0f) {
+                                               if (div==0) {
                                                        dvz[0]= dvec2[-4];
                                                        dvz[1]= dvec2[-3];
                                                        div++;
                                                }
-                                               else if( (ABS(dvec2[-4]) + ABS(dvec2[-3]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
+                                               else if ( (ABS(dvec2[-4]) + ABS(dvec2[-3]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
                                                        dvz[0]= dvec2[-4];
                                                        dvz[1]= dvec2[-3];
                                                }
                                        }
                                }
 
-                               if(x!=xsize) {
-                                       if(dvec1[0]!=0.0f || dvec1[1]!=0.0f) {
-                                               if(div==0) {
+                               if (x!=xsize) {
+                                       if (dvec1[0]!=0.0f || dvec1[1]!=0.0f) {
+                                               if (div==0) {
                                                        dvz[0]= dvec1[0];
                                                        dvz[1]= dvec1[1];
                                                        div++;
                                                }
-                                               else if( (ABS(dvec1[0]) + ABS(dvec1[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
+                                               else if ( (ABS(dvec1[0]) + ABS(dvec1[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
                                                        dvz[0]= dvec1[0];
                                                        dvz[1]= dvec1[1];
                                                }
                                        }
-                                       if(dvec2[0]!=0.0f || dvec2[1]!=0.0f) {
-                                               if(div==0) {
+                                       if (dvec2[0]!=0.0f || dvec2[1]!=0.0f) {
+                                               if (div==0) {
                                                        dvz[0]= dvec2[0];
                                                        dvz[1]= dvec2[1];
                                                }
-                                               else if( (ABS(dvec2[0]) + ABS(dvec2[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
+                                               else if ( (ABS(dvec2[0]) + ABS(dvec2[1]))< (ABS(dvz[0]) + ABS(dvz[1])) ) {
                                                        dvz[0]= dvec2[0];
                                                        dvz[1]= dvec2[1];
                                                }
                                        }
                                }
-                               if(maxspeed) {
+                               if (maxspeed) {
                                        float speedsq= dvz[0]*dvz[0] + dvz[1]*dvz[1];
-                                       if(speedsq > maxspeedsq) {
+                                       if (speedsq > maxspeedsq) {
                                                speedsq= (float)maxspeed/sqrt(speedsq);
                                                dvz[0]*= speedsq;
                                                dvz[1]*= speedsq;
@@ -3012,7 +3019,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        /* set border speeds to keep border speeds on border */
        dz1= rectvz;
        dz2= rectvz+4*(ysize)*(xsize+1);
-       for(x=0; x<=xsize; x++, dz1+=4, dz2+=4) {
+       for (x=0; x<=xsize; x++, dz1+=4, dz2+=4) {
                dz1[1]= 0.0f;
                dz2[1]= 0.0f;
                dz1[3]= 0.0f;
@@ -3020,7 +3027,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        }
        dz1= rectvz;
        dz2= rectvz+4*(xsize);
-       for(y=0; y<=ysize; y++, dz1+=4*(xsize+1), dz2+=4*(xsize+1)) {
+       for (y=0; y<=ysize; y++, dz1+=4*(xsize+1), dz2+=4*(xsize+1)) {
                dz1[0]= 0.0f;
                dz2[0]= 0.0f;
                dz1[2]= 0.0f;
@@ -3030,15 +3037,15 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        /* tag moving pixels, only these faces we draw */
        dm= rectmove;
        dvec1= vecbufrect;
-       for(x=xsize*ysize; x>0; x--, dm++, dvec1+=4) {
-               if((dvec1[0]!=0.0f || dvec1[1]!=0.0f || dvec1[2]!=0.0f || dvec1[3]!=0.0f))
+       for (x=xsize*ysize; x>0; x--, dm++, dvec1+=4) {
+               if ((dvec1[0]!=0.0f || dvec1[1]!=0.0f || dvec1[2]!=0.0f || dvec1[3]!=0.0f))
                        *dm= 255;
        }
        
        antialias_tagbuf(xsize, ysize, rectmove);
        
        /* has to become static, the init-jit calls a random-seed, screwing up texture noise node */
-       if(firsttime) {
+       if (firsttime) {
                firsttime= 0;
                BLI_initjit(jit[0], 256);
        }
@@ -3047,26 +3054,26 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
 
        /* accumulate */
        samples/= 2;
-       for(step= 1; step<=samples; step++) {
+       for (step= 1; step<=samples; step++) {
                float speedfac= 0.5f*nbd->fac*(float)step/(float)(samples+1);
                int side;
                
-               for(side=0; side<2; side++) {
+               for (side=0; side<2; side++) {
                        float blendfac, ipodata[4];
                        
                        /* clear zbuf, if we draw future we fill in not moving pixels */
-                       if(0)
-                               for(x= xsize*ysize-1; x>=0; x--) rectz[x]= 10e16;
+                       if (0)
+                               for (x= xsize*ysize-1; x>=0; x--) rectz[x]= 10e16;
                        else 
-                               for(x= xsize*ysize-1; x>=0; x--) {
-                                       if(rectmove[x]==0)
+                               for (x= xsize*ysize-1; x>=0; x--) {
+                                       if (rectmove[x]==0)
                                                rectz[x]= zbufrect[x];
                                        else
                                                rectz[x]= 10e16;
                                }
                        
                        /* clear drawing buffer */
-                       for(x= xsize*ysize-1; x>=0; x--) rectdraw[x].colpoin= NULL;
+                       for (x= xsize*ysize-1; x>=0; x--) rectdraw[x].colpoin= NULL;
                        
                        dimg= imgrect;
                        dm= rectmove;
@@ -3074,8 +3081,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
                        dz1= rectvz;
                        dz2= rectvz + 4*(xsize + 1);
                        
-                       if(side) {
-                               if(nbd->curved==0) {
+                       if (side) {
+                               if (nbd->curved==0) {
                                        dz1+= 2;
                                        dz2+= 2;
                                }
@@ -3084,15 +3091,15 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
                        
                        set_quad_bezier_ipo(0.5f + 0.5f*speedfac, ipodata);
                        
-                       for(fy= -0.5f+jit[step & 255][0], y=0; y<ysize; y++, fy+=1.0f) {
-                               for(fx= -0.5f+jit[step & 255][1], x=0; x<xsize; x++, fx+=1.0f, dimg+=4, dz1+=4, dz2+=4, dm++, dz++) {
-                                       if(*dm>1) {
+                       for (fy= -0.5f+jit[step & 255][0], y=0; y<ysize; y++, fy+=1.0f) {
+                               for (fx= -0.5f+jit[step & 255][1], x=0; x<xsize; x++, fx+=1.0f, dimg+=4, dz1+=4, dz2+=4, dm++, dz++) {
+                                       if (*dm>1) {
                                                float jfx = fx + 0.5f;
                                                float jfy = fy + 0.5f;
                                                DrawBufPixel col;
                                                
                                                /* make vertices */
-                                               if(nbd->curved) {       /* curved */
+                                               if (nbd->curved) {      /* curved */
                                                        quad_bezier_2d(v1, dz1, dz1+2, ipodata);
                                                        v1[0]+= jfx; v1[1]+= jfy; v1[2]= *dz;
 
@@ -3111,8 +3118,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
                                                        v3[0]= speedfac*dz2[4]+jfx+1.0f;                v3[1]= speedfac*dz2[5]+jfy+1.0f;                v3[2]= *dz;
                                                        v4[0]= speedfac*dz2[0]+jfx;                     v4[1]= speedfac*dz2[1]+jfy+1.0f;                v4[2]= *dz;
                                                }
-                                               if(*dm==255) col.alpha= 1.0f;
-                                               else if(*dm<2) col.alpha= 0.0f;
+                                               if (*dm==255) col.alpha= 1.0f;
+                                               else if (*dm<2) col.alpha= 0.0f;
                                                else col.alpha= ((float)*dm)/255.0f;
                                                col.colpoin= dimg;
 
@@ -3137,8 +3144,8 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
                        /* accum */
                        rw= rectweight;
                        rm= rectmax;
-                       for(dr= rectdraw, dz2=newrect, x= xsize*ysize-1; x>=0; x--, dr++, dz2+=4, rw++, rm++) {
-                               if(dr->colpoin) {
+                       for (dr= rectdraw, dz2=newrect, x= xsize*ysize-1; x>=0; x--, dr++, dz2+=4, rw++, rm++) {
+                               if (dr->colpoin) {
                                        float bfac= dr->alpha*blendfac;
                                        
                                        dz2[0] += bfac*dr->colpoin[0];
@@ -3158,7 +3165,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        rm= rectmax;
        ro= imgrect;
        dm= rectmove;
-       for(dz2=newrect, x= xsize*ysize-1; x>=0; x--, dz2+=4, ro+=4, rw++, rm++, dm++) {
+       for (dz2=newrect, x= xsize*ysize-1; x>=0; x--, dz2+=4, ro+=4, rw++, rm++, dm++) {
                float mfac = *rm;
                float fac = (*rw == 0.0f)? 0.0f: mfac/(*rw);
                float nfac = 1.0f - mfac;
@@ -3175,7 +3182,7 @@ void RE_zbuf_accumulate_vecblur(NodeBlurData *nbd, int xsize, int ysize, float *
        MEM_freeN(rectvz);
        MEM_freeN(rectweight);
        MEM_freeN(rectmax);
-       if(minvecbufrect) MEM_freeN(vecbufrect);  /* rects were swapped! */
+       if (minvecbufrect) MEM_freeN(vecbufrect);  /* rects were swapped! */
        zbuf_free_span(&zspan);
 }
 
@@ -3191,18 +3198,18 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample)
        int x, y, *rza, *rma;
        intptr_t *rd;
        
-       if(R.osa==0) {
-               if(!pa->rectz)
+       if (R.osa==0) {
+               if (!pa->rectz)
                        fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE);
                else
                        memcpy(arectz, pa->rectz, sizeof(int)*pa->rectx*pa->recty);
 
-               if(rectmask && pa->rectmask)
+               if (rectmask && pa->rectmask)
                        memcpy(rectmask, pa->rectmask, sizeof(int)*pa->rectx*pa->recty);
 
                return;
        }
-       else if(!pa->rectdaps) {
+       else if (!pa->rectdaps) {
                fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE);
                return;
        }
@@ -3213,17 +3220,17 @@ static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample)
 
        sample= (1<<sample);
        
-       for(y=0; y<pa->recty; y++) {
-               for(x=0; x<pa->rectx; x++) {
+       for (y=0; y<pa->recty; y++) {
+               for (x=0; x<pa->rectx; x++) {
                        
                        *rza= 0x7FFFFFFF;
-                       if(rectmask) *rma= 0x7FFFFFFF;
-                       if(*rd) {       
+                       if (rectmask) *rma= 0x7FFFFFFF;
+                       if (*rd) {      
                                /* when there's a sky pixstruct, fill in sky-Z, otherwise solid Z */
-                               for(ps= (PixStr *)(*rd); ps; ps= ps->next) {
-                                       if(sample & ps->mask) {
+                               for (ps= (PixStr *)(*rd); ps; ps= ps->next) {
+                                       if (sample & ps->mask) {
                                                *rza= ps->z;
-                                               if(rectmask) *rma= ps->maskz;
+                                               if (rectmask) *rma= ps->maskz;
                                                break;
                                        }
                                }
@@ -3257,7 +3264,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
 
        zbuffer_part_bounds(winx, winy, pa, bounds);
 
-       for(zsample=0; zsample<samples; zsample++) {
+       for (zsample=0; zsample<samples; zsample++) {
                zspan= &zspans[zsample];
 
                zbuf_alloc_span(zspan, pa->rectx, pa->recty, re->clipcrop);
@@ -3271,7 +3278,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
                zspan->apixbuf= APixbuf;
                zspan->apsmbase= apsmbase;
                
-               if(negzmask)
+               if (negzmask)
                        zspan->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectmask");
 
                /* filling methods */
@@ -3281,7 +3288,7 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
                copyto_abufz(pa, zspan->arectz, zspan->rectmask, zsample);      /* init zbuffer */
                zspan->mask= 1<<zsample;
 
-               if(jit) {
+               if (jit) {
                        zspan->zofsx= -pa->disprect.xmin - jit[zsample][0];
                        zspan->zofsy= -pa->disprect.ymin - jit[zsample][1];
                }
@@ -3298,37 +3305,37 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
        /* we use this to test if nothing was filled in */
        zvlnr= 0;
                
-       for(i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
+       for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
                obr= obi->obr;
 
-               if(!(obi->lay & lay))
+               if (!(obi->lay & lay))
                        continue;
 
-               if(obi->flag & R_TRANSFORMED)
+               if (obi->flag & R_TRANSFORMED)
                        mult_m4_m4m4(obwinmat, winmat, obi->mat);
                else
                        copy_m4_m4(obwinmat, winmat);
 
-               if(clip_render_object(obi->obr->boundbox, bounds, obwinmat))
+               if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
                        continue;
 
                zbuf_project_cache_clear(cache, obr->totvert);
 
-               for(v=0; v<obr->totvlak; v++) {
-                       if((v & 255)==0)
+               for (v=0; v<obr->totvlak; v++) {
+                       if ((v & 255)==0)
                                vlr= obr->vlaknodes[v>>8].vlak;
                        else vlr++;
                        
-                       if(vlr->mat!=ma) {
+                       if (vlr->mat!=ma) {
                                ma= vlr->mat;
-                               if(shadow)
+                               if (shadow)
                                        dofill= (ma->mode & MA_SHADBUF);
                                else
                                        dofill= (((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) && !(ma->mode & MA_ONLYCAST));
                        }
                        
-                       if(dofill) {
-                               if(!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) {
+                       if (dofill) {
+                               if (!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) {
                                        unsigned short partclip;
                                        
                                        v1= vlr->v1;
@@ -3342,14 +3349,14 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
 
                                        /* partclipping doesn't need viewplane clipping */
                                        partclip= c1 & c2 & c3;
-                                       if(v4) {
+                                       if (v4) {
                                                c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
                                                partclip &= c4;
                                        }
 
-                                       if(partclip==0) {
+                                       if (partclip==0) {
                                                /* a little advantage for transp rendering (a z offset) */
-                                               if(!shadow && ma->zoffs != 0.0f) {
+                                               if (!shadow && ma->zoffs != 0.0f) {
                                                        mul= 0x7FFFFFFF;
                                                        zval= mul*(1.0f+ho1[2]/ho1[3]);
 
@@ -3368,45 +3375,45 @@ static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *
                                                c1= testclip(ho1);
                                                c2= testclip(ho2);
                                                c3= testclip(ho3);
-                                               if(v4)
+                                               if (v4)
                                                        c4= testclip(ho4);
 
-                                               for(zsample=0; zsample<samples; zsample++) {
+                                               for (zsample=0; zsample<samples; zsample++) {
                                                        zspan= &zspans[zsample];
                                                        zspan->polygon_offset= polygon_offset;
                                
-                                                       if(ma->material_type == MA_TYPE_WIRE) {
-                                                               if(v4)
+                                                       if (ma->material_type == MA_TYPE_WIRE) {
+                                                               if (v4)
                                                                        zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                                                else
                                                                        zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, 0, c1, c2, c3, 0);
                                                        }
                                                        else {
-                                                               if(v4 && (vlr->flag & R_STRAND)) {
+                                                               if (v4 && (vlr->flag & R_STRAND)) {
                                                                        zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
                                                                }
                                                                else {
                                                                        zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
-                                                                       if(v4)
+                                                                       if (v4)
                                                                                zbufclip(zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
                                                                }
                                                        }
                                                }
                                        }
-                                       if((v & 255)==255) 
-                                               if(re->test_break(re->tbh)) 
+                                       if ((v & 255)==255) 
+                                               if (re->test_break(re->tbh)) 
                                                        break; 
                                }
                        }
                }
 
-               if(re->test_break(re->tbh)) break;
+               if (re->test_break(re->tbh)) break;
        }
        
-       for(zsample=0; zsample<samples; zsample++) {
+       for (zsample=0; zsample<samples; zsample++) {
                zspan= &zspans[zsample];
                MEM_freeN(zspan->arectz);
-               if(zspan->rectmask)
+               if (zspan->rectmask)
                        MEM_freeN(zspan->rectmask);
                zbuf_free_span(zspan);
        }
@@ -3422,18 +3429,18 @@ static int zbuffer_abuf_render(RenderPart *pa, APixstr *APixbuf, APixstrand *APi
        samples= (R.osa)? R.osa: 1;
        negzmask= ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK));
 
-       if(R.osa)
+       if (R.osa)
                jit= R.jit;
-       else if(R.i.curblur)
+       else if (R.i.curblur)
                jit= &R.mblur_jit[R.i.curblur-1];
        else
                jit= NULL;
        
        zbuf_make_winmat(&R, winmat);
 
-       if(rl->layflag & SCE_LAY_ZTRA)
+       if (rl->layflag & SCE_LAY_ZTRA)
                doztra+= zbuffer_abuf(&R, pa, APixbuf, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0);
-       if((rl->layflag & SCE_LAY_STRAND) && APixbufstrand)
+       if ((rl->layflag & SCE_LAY_STRAND) && APixbufstrand)
                doztra+= zbuffer_strands_abuf(&R, pa, APixbufstrand, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0, sscache);
 
        return doztra;
@@ -3444,7 +3451,7 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[][4], APixstr *A
        RenderPart pa;
        int lay= -1;
 
-       if(lar->mode & LA_LAYER) lay= lar->lay;
+       if (lar->mode & LA_LAYER) lay= lar->lay;
 
        memset(&pa, 0, sizeof(RenderPart));
        pa.rectx= size;
@@ -3455,7 +3462,7 @@ void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[][4], APixstr *A
        pa.disprect.ymax = size;
 
        zbuffer_abuf(re, &pa, APixbuf, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1);
-       if(APixbufstrand)
+       if (APixbufstrand)
                zbuffer_strands_abuf(re, &pa, APixbufstrand, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1, NULL);
 }
 
@@ -3467,27 +3474,27 @@ void add_transp_speed(RenderLayer *rl, int offset, float *speed, float alpha, in
 {
        RenderPass *rpass;
        
-       for(rpass= rl->passes.first; rpass; rpass= rpass->next) {
-               if(rpass->passtype==SCE_PASS_VECTOR) {
+       for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
+               if (rpass->passtype==SCE_PASS_VECTOR) {
                        float *fp= rpass->rect + 4*offset;
                        
-                       if(speed==NULL) {
+                       if (speed==NULL) {
                                /* clear */
-                               if(fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f;
-                               if(fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f;
-                               if(fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f;
-                               if(fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f;
+                               if (fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f;
+                               if (fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f;
+                               if (fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f;
+                               if (fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f;
                        }
-                       else if(rdrect==NULL || rdrect[offset]==0 || alpha>0.95f) {
+                       else if (rdrect==NULL || rdrect[offset]==0 || alpha>0.95f) {
                                copy_v4_v4(fp, speed);
                        }
                        else {
                                /* add minimum speed in pixel */
-                               if( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
+                               if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
                                        fp[0]= speed[0];
                                        fp[1]= speed[1];
                                }
-                               if( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
+                               if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
                                        fp[2]= speed[2];
                                        fp[3]= speed[3];
                                }
@@ -3501,8 +3508,8 @@ static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob)
 {
        RenderPass *rpass;
        
-       for(rpass= rl->passes.first; rpass; rpass= rpass->next) {
-               if(rpass->passtype == SCE_PASS_INDEXOB||rpass->passtype == SCE_PASS_INDEXMA) {
+       for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
+               if (rpass->passtype == SCE_PASS_INDEXOB||rpass->passtype == SCE_PASS_INDEXMA) {
                        float *fp= rpass->rect + offset;
                        *fp= (float)ob->index;
                        break;
@@ -3518,7 +3525,7 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr)
        float weight= 1.0f/((float)R.osa);
        int delta= sizeof(ShadeResult)/4;
        
-       for(rpass= rl->passes.first; rpass; rpass= rpass->next) {
+       for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
                float *col= NULL;
                int pixsize= 3;
                
@@ -3573,16 +3580,16 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr)
                                        int samp;
                                        
                                        /* add minimum speed in pixel */
-                                       for(samp= 1; samp<R.osa; samp++, shr_t++) {
+                                       for (samp= 1; samp<R.osa; samp++, shr_t++) {
                                                
-                                               if(shr_t->combined[3] > 0.0f) {
+                                               if (shr_t->combined[3] > 0.0f) {
                                                        float *speed= shr_t->winspeed;
                                                        
-                                                       if( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
+                                                       if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
                                                                fp[0]= speed[0];
                                                                fp[1]= speed[1];
                                                        }
-                                                       if( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
+                                                       if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
                                                                fp[2]= speed[2];
                                                                fp[3]= speed[3];
                                                        }
@@ -3591,23 +3598,23 @@ void merge_transp_passes(RenderLayer *rl, ShadeResult *shr)
                                }
                                break;
                }
-               if(col) {
+               if (col) {
                        float *fp= col+delta;
                        int samp;
                        
-                       for(samp= 1; samp<R.osa; samp++, fp+=delta) {
+                       for (samp= 1; samp<R.osa; samp++, fp+=delta) {
                                col[0]+= fp[0];
-                               if(pixsize>1) {
+                               if (pixsize>1) {
                                        col[1]+= fp[1];
                                        col[2]+= fp[2];
-                                       if(pixsize==4) col[3]+= fp[3];
+                                       if (pixsize==4) col[3]+= fp[3];
                                }
                        }
                        col[0]*= weight;
-                       if(pixsize>1) {
+                       if (pixsize>1) {
                                col[1]*= weight;
                                col[2]*= weight;
-                               if(pixsize==4) col[3]*= weight;
+                               if (pixsize==4) col[3]*= weight;
                        }
                }
        }
@@ -3618,14 +3625,14 @@ void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alph
 {
        RenderPass *rpass;
        
-       for(rpass= rl->passes.first; rpass; rpass= rpass->next) {
+       for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
                float *fp, *col= NULL;
                int pixsize= 3;
                
                switch(rpass->passtype) {
                        case SCE_PASS_Z:
                                fp= rpass->rect + offset;
-                               if(shr->z < *fp)
+                               if (shr->z < *fp)
                                        *fp= shr->z;
                                break;
                        case SCE_PASS_RGBA:
@@ -3667,11 +3674,11 @@ void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alph
                                pixsize= 1;
                                break;
                }
-               if(col) {
+               if (col) {
 
                        fp= rpass->rect + pixsize*offset;
                        fp[0]= col[0] + (1.0f-alpha)*fp[0];
-                       if(pixsize==3) {
+                       if (pixsize==3) {
                                fp[1]= col[1] + (1.0f-alpha)*fp[1];
                                fp[2]= col[2] + (1.0f-alpha)*fp[2];
                        }
@@ -3692,8 +3699,8 @@ static int vergzvlak(const void *a1, const void *a2)
 {
        const ZTranspRow *r1 = a1, *r2 = a2;
 
-       if(r1->z < r2->z) return 1;
-       else if(r1->z > r2->z) return -1;
+       if (r1->z < r2->z) return 1;
+       else if (r1->z > r2->z) return -1;
        return 0;
 }
 
@@ -3732,10 +3739,10 @@ static void unref_strand_samples(StrandShadeCache *cache, ZTranspRow *row, int t
        /* remove references to samples that are not being rendered, but we still
         * need to remove them so that the reference count of strand vertex shade
         * samples correctly drops to zero */
-       while(totface > 0) {
+       while (totface > 0) {
                totface--;
 
-               if(row[totface].segment != -1) {
+               if (row[totface].segment != -1) {
                        obi= R.objectinstance + row[totface].obi;
                        obr= obi->obr;
                        strand= RE_findOrAddStrand(obr, row[totface].p-1);
@@ -3757,18 +3764,18 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int
        shade_input_set_triangle(shi, obi, facenr, 1);
                
        /* officially should always be true... we have no sky info */
-       if(shi->vlr) {
+       if (shi->vlr) {
                
                /* full osa is only set for OSA renders */
-               if(shi->vlr->flag & R_FULL_OSA) {
+               if (shi->vlr->flag & R_FULL_OSA) {
                        short shi_inc= 0, samp;
                        
-                       for(samp=0; samp<R.osa; samp++) {
-                               if(curmask & (1<<samp)) {
+                       for (samp=0; samp<R.osa; samp++) {
+                               if (curmask & (1<<samp)) {
                                        xs= (float)x + R.jit[samp][0] + 0.5f;   /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */
                                        ys= (float)y + R.jit[samp][1] + 0.5f;
                                        
-                                       if(shi_inc) {
+                                       if (shi_inc) {
                                                shade_input_copy_triangle(shi+1, shi);
                                                shi++;
                                        }
@@ -3776,7 +3783,7 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int
                                        shi->samplenr= R.shadowsamplenr[shi->thread]++;
                                        shade_input_set_viewco(shi, x, y, xs, ys, (float)z);
                                        shade_input_set_uv(shi);
-                                       if(shi_inc==0)
+                                       if (shi_inc==0)
                                                shade_input_set_normals(shi);
                                        else /* XXX shi->flippednor messes up otherwise */
                                                shade_input_set_vertex_normals(shi);
@@ -3786,7 +3793,7 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int
                        }
                }
                else {
-                       if(R.osa) {
+                       if (R.osa) {
                                short b= R.samples->centmask[curmask];
                                xs= (float)x + R.samples->centLut[b & 15] + 0.5f;
                                ys= (float)y + R.samples->centLut[b>>4] + 0.5f;
@@ -3809,14 +3816,14 @@ static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int
 
 static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, int y, ZTranspRow *row, int addpassflag)
 {
-       if(row->segment != -1) {
+       if (row->segment != -1) {
                shade_strand_samples(cache, ssamp, x, y, row, addpassflag);
                return 1;
        }
 
        shade_tra_samples_fill(ssamp, x, y, row->z, row->obi, row->p, row->mask);
        
-       if(ssamp->tot) {
+       if (ssamp->tot) {
                ShadeInput *shi= ssamp->shi;
                ShadeResult *shr= ssamp->shr;
                int samp;
@@ -3825,19 +3832,19 @@ static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x,
                shade_samples_do_AO(ssamp);
                
                /* if shade (all shadepinputs have same passflag) */
-               if(shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) {
-                       for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) {
+               if (shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) {
+                       for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) {
                                shade_input_set_shade_texco(shi);
                                shade_input_do_shade(shi, shr);
                                
                                /* include lamphalos for ztra, since halo layer was added already */
-                               if(R.flag & R_LAMPHALO)
-                                       if(shi->layflag & SCE_LAY_HALO)
+                               if (R.flag & R_LAMPHALO)
+                                       if (shi->layflag & SCE_LAY_HALO)
                                                renderspothalo(shi, shr->combined, shr->combined[3]);
                        }
                }
-               else if(shi->passflag & SCE_PASS_Z) {
-                       for(samp=0; samp<ssamp->tot; samp++, shi++, shr++)
+               else if (shi->passflag & SCE_PASS_Z) {
+                       for (samp=0; samp<ssamp->tot; samp++, shi++, shr++)
                                shr->z= -shi->co[2];
                }
 
@@ -3857,66 +3864,66 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf
 {
        int a, sample, osa = (R.osa? R.osa: 1), retval = osa;
        
-       for(a=0; a < osa; a++, samp_shr++) {
+       for (a=0; a < osa; a++, samp_shr++) {
                ShadeInput *shi= ssamp->shi;
                ShadeResult *shr= ssamp->shr;
                
-               for(sample=0; sample<ssamp->tot; sample++, shi++, shr++) {
+               for (sample=0; sample<ssamp->tot; sample++, shi++, shr++) {
                
-                       if(shi->mask & (1<<a)) {
+                       if (shi->mask & (1<<a)) {
                                float fac= (1.0f - samp_shr->combined[3])*shr->combined[3];
                                
                                addAlphaUnderFloat(samp_shr->combined, shr->combined);
                                
                                samp_shr->z= MIN2(samp_shr->z, shr->z);
 
-                               if(addpassflag & SCE_PASS_VECTOR) {
+                               if (addpassflag & SCE_PASS_VECTOR) {
                                        copy_v4_v4(samp_shr->winspeed, shr->winspeed);
                                }
                                /* optim... */
-                               if(addpassflag & ~(SCE_PASS_VECTOR)) {
+                               if (addpassflag & ~(SCE_PASS_VECTOR)) {
                                        
-                                       if(addpassflag & SCE_PASS_RGBA)
+                                       if (addpassflag & SCE_PASS_RGBA)
                                                addAlphaUnderFloat(samp_shr->col, shr->col);
                                        
-                                       if(addpassflag & SCE_PASS_NORMAL)
+                                       if (addpassflag & SCE_PASS_NORMAL)
                                                addvecmul(samp_shr->nor, shr->nor, fac);
 
-                                       if(addpassflag & SCE_PASS_EMIT)
+                                       if (addpassflag & SCE_PASS_EMIT)
                                                addvecmul(samp_shr->emit, shr->emit, fac);
 
-                                       if(addpassflag & SCE_PASS_DIFFUSE)
+                                       if (addpassflag & SCE_PASS_DIFFUSE)
                                                addvecmul(samp_shr->diff, shr->diff, fac);
                                        
-                                       if(addpassflag & SCE_PASS_SPEC)
+                                       if (addpassflag & SCE_PASS_SPEC)
                                                addvecmul(samp_shr->spec, shr->spec, fac);
 
-                                       if(addpassflag & SCE_PASS_SHADOW)
+                                       if (addpassflag & SCE_PASS_SHADOW)
                                                addvecmul(samp_shr->shad, shr->shad, fac);
 
-                                       if(addpassflag & SCE_PASS_AO)
+                                       if (addpassflag & SCE_PASS_AO)
                                                addvecmul(samp_shr->ao, shr->ao, fac);
 
-                                       if(addpassflag & SCE_PASS_ENVIRONMENT)
+                                       if (addpassflag & SCE_PASS_ENVIRONMENT)
                                                addvecmul(samp_shr->env, shr->env, fac);
 
-                                       if(addpassflag & SCE_PASS_INDIRECT)
+                                       if (addpassflag & SCE_PASS_INDIRECT)
                                                addvecmul(samp_shr->indirect, shr->indirect, fac);
 
-                                       if(addpassflag & SCE_PASS_REFLECT)
+                                       if (addpassflag & SCE_PASS_REFLECT)
                                                addvecmul(samp_shr->refl, shr->refl, fac);
                                        
-                                       if(addpassflag & SCE_PASS_REFRACT)
+                                       if (addpassflag & SCE_PASS_REFRACT)
                                                addvecmul(samp_shr->refr, shr->refr, fac);
                                        
-                                       if(addpassflag & SCE_PASS_MIST)
+                                       if (addpassflag & SCE_PASS_MIST)
                                                samp_shr->mist= samp_shr->mist+fac*shr->mist;
 
                                }
                        }
                }
                
-               if(samp_shr->combined[3]>0.999f) retval--;
+               if (samp_shr->combined[3]>0.999f) retval--;
        }
        return retval;
 }
@@ -3929,11 +3936,11 @@ static void reset_sky_speedvectors(RenderPart *pa, RenderLayer *rl, float *rectf
        int a;
        
        fp= RE_RenderLayerGetPass(rl, SCE_PASS_VECTOR);
-       if(fp==NULL) return;
+       if (fp==NULL) return;
        col= rectf+3;
        
-       for(a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) {
-               if(col[a]==0.0f) {
+       for (a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) {
+               if (col[a]==0.0f) {
                        fp[a]= PASS_VECTOR_MAX;
                        fp[a+1]= PASS_VECTOR_MAX;
                        fp[a+2]= PASS_VECTOR_MAX;
@@ -3966,17 +3973,17 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        unsigned short *ztramask= NULL, filled;
 
        /* looks nicer for calling code */
-       if(R.test_break(R.tbh))
+       if (R.test_break(R.tbh))
                return NULL;
        
-       if(R.osa>16) { /* MAX_OSA */
+       if (R.osa>16) { /* MAX_OSA */
                printf("zbuffer_transp_shade: osa too large\n");
                G.afbreek= 1;
                return NULL;
        }
        
        APixbuf= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
-       if(R.totstrand && (rl->layflag & SCE_LAY_STRAND)) {
+       if (R.totstrand && (rl->layflag & SCE_LAY_STRAND)) {
                APixbufstrand= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstrand), "APixbufstrand");
                sscache= strand_shade_cache_create();
        }
@@ -3985,7 +3992,7 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        shade_sample_initialize(&ssamp, pa, rl);
        addpassflag= rl->passflag & ~(SCE_PASS_COMBINED);
        
-       if(R.osa)
+       if (R.osa)
                sampalpha= 1.0f/(float)R.osa;
        else
                sampalpha= 1.0f;
@@ -3993,12 +4000,12 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        /* fill the Apixbuf */
        doztra= zbuffer_abuf_render(pa, APixbuf, APixbufstrand, &apsmbase, rl, sscache);
 
-       if(doztra == 0) {
+       if (doztra == 0) {
                /* nothing filled in */
                MEM_freeN(APixbuf);
-               if(APixbufstrand)
+               if (APixbufstrand)
                        MEM_freeN(APixbufstrand);
-               if(sscache)
+               if (sscache)
                        strand_shade_cache_free(sscache);
                freepsA(&apsmbase);
                return NULL;
@@ -4012,20 +4019,20 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        totfullsample= get_sample_layers(pa, rl, rlpp);
        
        /* irregular shadowb buffer creation */
-       if(R.r.mode & R_SHADOW)
+       if (R.r.mode & R_SHADOW)
                ISB_create(pa, APixbuf);
 
        /* masks, to have correct alpha combine */
-       if(R.osa && (rl->layflag & SCE_LAY_SOLID) && pa->fullresult.first==NULL)
+       if (R.osa && (rl->layflag & SCE_LAY_SOLID) && pa->fullresult.first==NULL)
                ztramask= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "ztramask");
 
        /* zero alpha pixels get speed vector max again */
-       if(addpassflag & SCE_PASS_VECTOR)
-               if(rl->layflag & SCE_LAY_SOLID)
+       if (addpassflag & SCE_PASS_VECTOR)
+               if (rl->layflag & SCE_LAY_SOLID)
                        reset_sky_speedvectors(pa, rl, rl->acolrect?rl->acolrect:rl->rectf);    /* if acolrect is set we use it */
 
        /* filtered render, for now we assume only 1 filter size */
-       if(pa->crop) {
+       if (pa->crop) {
                crop= 1;
                offs= pa->rectx + 1;
                passrect+= 4*offs;
@@ -4039,35 +4046,35 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        rr->renlay= rl;
                                
        /* render the tile */
-       for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
+       for (y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
                pass= passrect;
                ap= aprect;
                apstrand= aprectstrand;
                od= offs;
                
-               if(R.test_break(R.tbh))
+               if (R.test_break(R.tbh))
                        break;
                
-               for(x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) {
+               for (x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) {
                        
-                       if(ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) {
-                               if(addpassflag & SCE_PASS_VECTOR) 
+                       if (ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) {
+                               if (addpassflag & SCE_PASS_VECTOR) 
                                        add_transp_speed(rl, od, NULL, 0.0f, rdrect);
                        }
                        else {
                                /* sort in z */
                                totface= 0;
                                apn= ap;
-                               while(apn) {
-                                       for(a=0; a<4; a++) {
-                                               if(apn->p[a]) {
+                               while (apn) {
+                                       for (a=0; a<4; a++) {
+                                               if (apn->p[a]) {
                                                        zrow[totface].obi= apn->obi[a];
                                                        zrow[totface].z= apn->z[a];
                                                        zrow[totface].p= apn->p[a];
                                                        zrow[totface].mask= apn->mask[a];
                                                        zrow[totface].segment= -1;
                                                        totface++;
-                                                       if(totface>=MAX_ZROW) totface= MAX_ZROW-1;
+                                                       if (totface>=MAX_ZROW) totface= MAX_ZROW-1;
                                                }
                                                else break;
                                        }
@@ -4075,19 +4082,19 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                }
 
                                apnstrand= (APixbufstrand)? apstrand: NULL;
-                               while(apnstrand) {
-                                       for(a=0; a<4; a++) {
-                                               if(apnstrand->p[a]) {
+                               while (apnstrand) {
+                                       for (a=0; a<4; a++) {
+                                               if (apnstrand->p[a]) {
                                                        zrow[totface].obi= apnstrand->obi[a];
                                                        zrow[totface].z= apnstrand->z[a];
                                                        zrow[totface].p= apnstrand->p[a];
                                                        zrow[totface].mask= apnstrand->mask[a];
                                                        zrow[totface].segment= apnstrand->seg[a];
 
-                                                       if(R.osa) {
+                                                       if (R.osa) {
                                                                totsample= 0;
-                                                               for(b=0; b<R.osa; b++)
-                                                                       if(zrow[totface].mask & (1<<b))
+                                                               for (b=0; b<R.osa; b++)
+                                                                       if (zrow[totface].mask & (1<<b))
                                                                                totsample++;
                                                        }
                                                        else
@@ -4096,43 +4103,43 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                                        zrow[totface].u= apnstrand->u[a]/totsample;
                                                        zrow[totface].v= apnstrand->v[a]/totsample;
                                                        totface++;
-                                                       if(totface>=MAX_ZROW) totface= MAX_ZROW-1;
+                                                       if (totface>=MAX_ZROW) totface= MAX_ZROW-1;
                                                }
                                        }
                                        apnstrand= apnstrand->next;
                                }
 
-                               if(totface==2) {
-                                       if(zrow[0].z < zrow[1].z) {
+                               if (totface==2) {
+                                       if (zrow[0].z < zrow[1].z) {
                                                SWAP(ZTranspRow, zrow[0], zrow[1]);
                                        }
                                        
                                }
-                               else if(totface>2) {
+                               else if (totface>2) {
                                        qsort(zrow, totface, sizeof(ZTranspRow), vergzvlak);
                                }
                                
                                /* front face does index pass for transparent, no AA or filters, but yes FSA */
-                               if(addpassflag & SCE_PASS_INDEXOB) {
+                               if (addpassflag & SCE_PASS_INDEXOB) {
                                        ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr;
-                                       if(obr->ob) {
-                                               for(a= 0; a<totfullsample; a++)
+                                       if (obr->ob) {
+                                               for (a= 0; a<totfullsample; a++)
                                                        add_transp_obindex(rlpp[a], od, obr->ob);
                                        }
                                }
-                               if(addpassflag & SCE_PASS_INDEXMA) {
+                               if (addpassflag & SCE_PASS_INDEXMA) {
                                        ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr;
-                                       if(obr->ob) {
-                                               for(a= 0; a<totfullsample; a++)
+                                       if (obr->ob) {
+                                               for (a= 0; a<totfullsample; a++)
                                                        add_transp_obindex(rlpp[a], od, obr->ob);
                                        }
                                }
 
                                /* for each mask-sample we alpha-under colors. then in end it's added using filter */
                                memset(samp_shr, 0, sizeof(ShadeResult)*osa);
-                               for(a=0; a<osa; a++) {
+                               for (a=0; a<osa; a++) {
                                        samp_shr[a].z= 10e10f;
-                                       if(addpassflag & SCE_PASS_VECTOR) {
+                                       if (addpassflag & SCE_PASS_VECTOR) {
                                                samp_shr[a].winspeed[0]= PASS_VECTOR_MAX;
                                                samp_shr[a].winspeed[1]= PASS_VECTOR_MAX;
                                                samp_shr[a].winspeed[2]= PASS_VECTOR_MAX;
@@ -4140,16 +4147,16 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                        }
                                }
 
-                               if(R.osa==0) {
-                                       while(totface>0) {
+                               if (R.osa==0) {
+                                       while (totface>0) {
                                                totface--;
                                                
-                                               if(shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
+                                               if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
                                                        filled= addtosamp_shr(samp_shr, &ssamp, addpassflag);
                                                        addAlphaUnderFloat(pass, ssamp.shr[0].combined);
                                                        
-                                                       if(filled == 0) {
-                                                               if(sscache)
+                                                       if (filled == 0) {
+                                                               if (sscache)
                                                                        unref_strand_samples(sscache, zrow, totface);
                                                                break;
                                                        }
@@ -4157,25 +4164,25 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                        }
 
                                        alpha= samp_shr->combined[3];
-                                       if(alpha!=0.0f) {
+                                       if (alpha!=0.0f) {
                                                add_transp_passes(rl, od, samp_shr, alpha);
-                                               if(addpassflag & SCE_PASS_VECTOR)
+                                               if (addpassflag & SCE_PASS_VECTOR)
                                                        add_transp_speed(rl, od, samp_shr->winspeed, alpha, rdrect);
                                        }
                                }
                                else {
                                        short *sp= (short *)(ztramask+od);
                                        
-                                       while(totface>0) {
+                                       while (totface>0) {
                                                totface--;
                                                
-                                               if(shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
+                                               if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
                                                        filled= addtosamp_shr(samp_shr, &ssamp, addpassflag);
                                                        
-                                                       if(ztramask)
+                                                       if (ztramask)
                                                                *sp |= zrow[totface].mask;
-                                                       if(filled==0) {
-                                                               if(sscache)
+                                                       if (filled==0) {
+                                                               if (sscache)
                                                                        unref_strand_samples(sscache, zrow, totface);
                                                                break;
                                                        }
@@ -4183,16 +4190,16 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                        }
                                        
                                        /* multisample buffers or filtered mask filling? */
-                                       if(pa->fullresult.first) {
-                                               for(a=0; a<R.osa; a++) {
+                                       if (pa->fullresult.first) {
+                                               for (a=0; a<R.osa; a++) {
                                                        alpha= samp_shr[a].combined[3];
-                                                       if(alpha!=0.0f) {
+                                                       if (alpha!=0.0f) {
                                                                RenderLayer *rl= ssamp.rlpp[a];
                                                                
                                                                addAlphaOverFloat(rl->rectf + 4*od, samp_shr[a].combined);
                                
                                                                add_transp_passes(rl, od, &samp_shr[a], alpha);
-                                                               if(addpassflag & SCE_PASS_VECTOR)
+                                                               if (addpassflag & SCE_PASS_VECTOR)
                                                                        add_transp_speed(rl, od, samp_shr[a].winspeed, alpha, rdrect);
                                                        }
                                                }
@@ -4201,19 +4208,19 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
                                                alpha= 0.0f;
 
                                                /* note; cannot use pass[3] for alpha due to filtermask */
-                                               for(a=0; a<R.osa; a++) {
+                                               for (a=0; a<R.osa; a++) {
                                                        add_filt_fmask(1<<a, samp_shr[a].combined, pass, rr->rectx);
                                                        alpha+= samp_shr[a].combined[3];
                                                }
                                                
-                                               if(addpassflag) {
+                                               if (addpassflag) {
                                                        alpha*= sampalpha;
                                                        
                                                        /* merge all in one, and then add */
                                                        merge_transp_passes(rl, samp_shr);
                                                        add_transp_passes(rl, od, samp_shr, alpha);
 
-                                                       if(addpassflag & SCE_PASS_VECTOR)
+                                                       if (addpassflag & SCE_PASS_VECTOR)
                                                                add_transp_speed(rl, od, samp_shr[0].winspeed, alpha, rdrect);
                                                }
                                        }
@@ -4231,13 +4238,13 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas
        rr->renlay= NULL;
 
        MEM_freeN(APixbuf);
-       if(APixbufstrand)
+       if (APixbufstrand)
                MEM_freeN(APixbufstrand);
-       if(sscache)
+       if (sscache)
                strand_shade_cache_free(sscache);
        freepsA(&apsmbase);     
 
-       if(R.r.mode & R_SHADOW)
+       if (R.r.mode & R_SHADOW)
                ISB_free(pa);
 
        return ztramask;