Reverted incorrect merge (missing files)
[blender.git] / source / blender / radiosity / intern / source / radfactors.c
index 5e2812138e2ace2612e057978cf69051276933ca..b87473dd8116de567b35ab30375140676e1e7eaf 100644 (file)
@@ -1,14 +1,11 @@
 /* ***************************************
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,7 +23,7 @@
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
 
 
 
 #include "BKE_global.h"
 #include "BKE_main.h"
 
-#include "BIF_screen.h"
-
 #include "radio.h"
-#include "render.h"       /* for `RE_zbufferall_radio and RE_zbufferall_radio */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "RE_render_ext.h"       /* for `RE_zbufferall_radio and RE_zbufferall_radio */
 
 /* locals */
-void rad_setmatrices(RadView *vw);
-void clearsubflagelem(RNode *rn);
-void setsubflagelem(RNode *rn);
+static void rad_setmatrices(RadView *vw);
+static void clearsubflagelem(RNode *rn);
+static void setsubflagelem(RNode *rn);
 
 RadView hemitop, hemiside;
 
@@ -86,20 +77,20 @@ float calcStokefactor(RPatch *shoot, RPatch *rp, RNode *rn, float *area)
                VecSubf(vec[2], shoot->cent, rn->v3);
                VecSubf(vec[3], shoot->cent, rn->v4);
 
-               Normalise(vec[0]);
-               Normalise(vec[1]);
-               Normalise(vec[2]);
-               Normalise(vec[3]);
+               Normalize(vec[0]);
+               Normalize(vec[1]);
+               Normalize(vec[2]);
+               Normalize(vec[3]);
 
                /* cross product */
                Crossf(cross[0], vec[0], vec[1]);
                Crossf(cross[1], vec[1], vec[2]);
                Crossf(cross[2], vec[2], vec[3]);
                Crossf(cross[3], vec[3], vec[0]);
-               Normalise(cross[0]);
-               Normalise(cross[1]);
-               Normalise(cross[2]);
-               Normalise(cross[3]);
+               Normalize(cross[0]);
+               Normalize(cross[1]);
+               Normalize(cross[2]);
+               Normalize(cross[3]);
 
                /* angles */
                rad[0]= vec[0][0]*vec[1][0]+ vec[0][1]*vec[1][1]+ vec[0][2]*vec[1][2];
@@ -130,17 +121,17 @@ float calcStokefactor(RPatch *shoot, RPatch *rp, RNode *rn, float *area)
                VecSubf(vec[1], shoot->cent, rn->v2);
                VecSubf(vec[2], shoot->cent, rn->v3);
 
-               Normalise(vec[0]);
-               Normalise(vec[1]);
-               Normalise(vec[2]);
+               Normalize(vec[0]);
+               Normalize(vec[1]);
+               Normalize(vec[2]);
 
                /* cross product */
                Crossf(cross[0], vec[0], vec[1]);
                Crossf(cross[1], vec[1], vec[2]);
                Crossf(cross[2], vec[2], vec[0]);
-               Normalise(cross[0]);
-               Normalise(cross[1]);
-               Normalise(cross[2]);
+               Normalize(cross[0]);
+               Normalize(cross[1]);
+               Normalize(cross[2]);
 
                /* angles */
                rad[0]= vec[0][0]*vec[1][0]+ vec[0][1]*vec[1][1]+ vec[0][2]*vec[1][2];
@@ -261,7 +252,7 @@ void rad_make_hocos(RadView *vw)
        /* } */
 }
 
-void rad_setmatrices(RadView *vw)          /* for hemi's */
+static void rad_setmatrices(RadView *vw)           /* for hemi's */
 {
        float up1[3], len, twist;
 
@@ -290,7 +281,7 @@ void hemizbuf(RadView *vw)
        int a, b, inda, hres;
 
        rad_setmatrices(vw);
-       RE_zbufferall_radio(vw, RG.elem, RG.totelem);
+       RE_zbufferall_radio(vw, RG.elem, RG.totelem, RG.re);    /* Render for when we got renderfaces */
 
        /* count factors */
        if(vw->recty==vw->rectx) factors= RG.topfactors;
@@ -312,20 +303,23 @@ int makeformfactors(RPatch *shoot)
 {
        RNode **re;
        float len, vec[3], up[3], side[3], tar[5][3], *fp;
-       int a, overfl;
+       int a=0, overfl;
 
        if(RG.totelem==0) return 0;
-
+       
        memset(RG.formfactors, 0, 4*RG.totelem);
 
        /* set up hemiview */
        /* first: random upvector */
        do {
+               a++;
                vec[0]= (float)BLI_drand();
                vec[1]= (float)BLI_drand();
                vec[2]= (float)BLI_drand();
                Crossf(up, shoot->norm, vec);
-               len= Normalise(up);
+               len= Normalize(up);
+               /* this safety for input normals that are zero or illegal sized */
+               if(a>3) return 0;
        } while(len==0.0 || len>1.0);
 
        VECCOPY(hemitop.up, up);
@@ -372,16 +366,6 @@ int makeformfactors(RPatch *shoot)
        }
        
        if(overfl) {
-               /*
-               drawOverflowElem();
-               while(get_mbut()&L_MOUSE==0) {
-                       if(get_mbut()&M_MOUSE) {
-                               viewmove();
-                               drawpatch_ext(shoot,0xFF77FF);
-                               drawOverflowElem();
-                       }
-               }
-               */
                if(shoot->first->down1) {
                        splitpatch(shoot);
                        return 0;
@@ -531,6 +515,7 @@ void rad_init_energy()
 void progressiverad()
 {
        RPatch *shoot;
+       float unshot[3];
        int it= 0;
 
        rad_printstatus();
@@ -546,12 +531,20 @@ void progressiverad()
                
                drawpatch_ext(shoot, 0x88FF00);
 
+               if(shoot->first->f & RAD_TWOSIDED) {
+                       VECCOPY(unshot, shoot->unshot);
+                       VecNegf(shoot->norm);
+                       if(makeformfactors(shoot))
+                               applyformfactors(shoot);
+                       VecNegf(shoot->norm);
+                       VECCOPY(shoot->unshot, unshot);
+               }
+       
                if( makeformfactors(shoot) ) {
-               
                        applyformfactors(shoot);
        
                        it++;
-                       set_timecursor(it);
+                       //XXX set_timecursor(it);
                        if( (it & 3)==1 ) {
                                make_node_display();
                                rad_forcedraw();
@@ -561,7 +554,7 @@ void progressiverad()
                
                clear_backface_test();
                
-               if(blender_test_break()) break;
+               //XXX if(blender_test_break()) break;
                if(RG.maxiter && RG.maxiter<=it) break;
 
                shoot=findshootpatch();
@@ -633,7 +626,7 @@ void minmaxradelemfilt(RNode *rn, float *min, float *max, float *errmin, float *
        }
 }
 
-void setsubflagelem(RNode *rn)
+static void setsubflagelem(RNode *rn)
 {
        
        if(rn->down1) {
@@ -645,7 +638,7 @@ void setsubflagelem(RNode *rn)
        }
 }
 
-void clearsubflagelem(RNode *rn)
+static void clearsubflagelem(RNode *rn)
 {
        
        if(rn->down1) {
@@ -677,7 +670,7 @@ void subdivideshootElements(int it)
                        shoot= findshootpatch();
                        if(shoot==0) break;
                        
-                       set_timecursor(a);
+                       //XXX set_timecursor(a);
                        drawpatch_ext(shoot, 0x88FF00);
                        
                        setnodeflags(shoot->first, RAD_SHOOT, 1);
@@ -727,7 +720,7 @@ void subdivideshootElements(int it)
                        }
                        else a--;
                        
-                       if(blender_test_break()) break;
+                       //XXX if(blender_test_break()) break;
                }
                
                /* test for extreme small color change within a patch with subdivflag */
@@ -746,11 +739,9 @@ void subdivideshootElements(int it)
                                        }
                                }
                                if(rn) {
-                                       min[0]= min[1]= min[2]= 1.0e10;
-                                       max[0]= max[1]= max[2]= -1.0e10;
+                                       INIT_MINMAX(min, max);
                                        /* errmin and max are the filtered colors */
-                                       errmin[0]= errmin[1]= errmin[2]= 1.0e10;
-                                       errmax[0]= errmax[1]= errmax[2]= -1.0e10;
+                                       INIT_MINMAX(errmin, errmax);
                                        minmaxradelemfilt(rp->first, min, max, errmin, errmax);
                                        
                                        /* if small difference between colors: no subdiv */
@@ -798,7 +789,7 @@ void subdivideshootElements(int it)
                }
                makeGlobalElemArray();
 
-               if(contin==0 || blender_test_break()) break;
+               //XXX if(contin==0 || blender_test_break()) break;
        }
        
        make_node_display();
@@ -823,7 +814,7 @@ void subdivideshootPatches(int it)
                        shoot= findshootpatch();
                        if(shoot==0) break;
                        
-                       set_timecursor(a);
+                       //XXX set_timecursor(a);
                        drawpatch_ext(shoot, 0x88FF00);
                        
                        setnodeflags(shoot->first, RAD_SHOOT, 1);
@@ -873,7 +864,7 @@ void subdivideshootPatches(int it)
                                
                                setnodeflags(shoot->first, RAD_SHOOT, 0);
                                
-                               if(blender_test_break()) break;
+                               //XXX if(blender_test_break()) break;
                        }
                        else a--;
                        
@@ -900,7 +891,7 @@ void subdivideshootPatches(int it)
                converttopatches();
                makeGlobalElemArray();
 
-               if(contin==0 || blender_test_break()) break;
+               //XXX if(contin==0 || blender_test_break()) break;
        }
        make_node_display();
 }
@@ -914,8 +905,8 @@ void inithemiwindows()
        memset(vw, 0, sizeof(RadView));
        vw->rectx= RG.hemires;
        vw->recty= RG.hemires;
-       vw->rectz= MEM_mallocN(4*vw->rectx*vw->recty, "initwindows");
-       vw->rect= MEM_mallocN(4*vw->rectx*vw->recty, "initwindows");
+       vw->rectz= MEM_mallocN(sizeof(int)*vw->rectx*vw->recty, "initwindows");
+       vw->rect= MEM_mallocN(sizeof(int)*vw->rectx*vw->recty, "initwindows");
        vw->mynear= RG.maxsize/2000.0;
        vw->myfar= 2.0*RG.maxsize;
        vw->wx1= -vw->mynear;