~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/radiosity/intern/source/radrender.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
#include "BIF_screen.h"
70
70
 
71
71
#include "radio.h"
72
 
#include "render.h" 
 
72
 
 
73
/* the radiosity module uses internal includes from render! */
 
74
#include "renderpipeline.h" 
 
75
#include "render_types.h" 
 
76
#include "renderdatabase.h" 
73
77
 
74
78
#ifdef HAVE_CONFIG_H
75
79
#include <config.h>
80
84
 
81
85
/* find the face with maximum energy to become shooter */
82
86
/* nb: _rr means rad-render version of existing radio call */
83
 
static VlakRen *findshoot_rr(void)
 
87
static VlakRen *findshoot_rr(Render *re)
84
88
{
85
89
        RadFace *rf;
86
90
        VlakRen *vlr=NULL, *shoot;
90
94
        shoot= NULL;
91
95
        maxenergy= 0.0;
92
96
        
93
 
        for(a=0; a<R.totvlak; a++) {
94
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
97
        for(a=0; a<re->totvlak; a++) {
 
98
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
95
99
                if(vlr->radface) {
96
100
                        rf= vlr->radface;
97
101
                        rf->flag &= ~RAD_SHOOT;
116
120
        return shoot;
117
121
}
118
122
 
119
 
static void backface_test_rr(VlakRen *shoot)
 
123
static void backface_test_rr(Render *re, VlakRen *shoot)
120
124
{
121
125
        VlakRen *vlr=NULL;
122
126
        RadFace *rf;
124
128
        int a;
125
129
        
126
130
        /* backface testing */
127
 
        for(a=0; a<R.totvlak; a++) {
128
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
131
        for(a=0; a<re->totvlak; a++) {
 
132
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
129
133
                if(vlr->radface) {
130
134
                        if(vlr!=shoot) {
131
135
                                rf= vlr->radface;
139
143
        }
140
144
}
141
145
 
142
 
static void clear_backface_test_rr()
 
146
static void clear_backface_test_rr(Render *re)
143
147
{
144
148
        VlakRen *vlr=NULL;
145
149
        RadFace *rf;
146
150
        int a;
147
151
        
148
152
        /* backface flag clear */
149
 
        for(a=0; a<R.totvlak; a++) {
150
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
153
        for(a=0; a<re->totvlak; a++) {
 
154
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
151
155
                
152
156
                if(vlr->radface) {
153
157
                        rf= vlr->radface;
159
163
extern RadView hemitop, hemiside; // radfactors.c
160
164
 
161
165
/* hemi-zbuffering, delivers formfactors array */
162
 
static void makeformfactors_rr(VlakRen *shoot)
 
166
static void makeformfactors_rr(Render *re, VlakRen *shoot)
163
167
{
164
168
        VlakRen *vlr=NULL;
165
169
        RadFace *rf;
203
207
        /* convert factors to real radiosity */
204
208
        fp= RG.formfactors;
205
209
 
206
 
        for(a=0; a<R.totvlak; a++) {
207
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
210
        for(a=0; a<re->totvlak; a++) {
 
211
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
208
212
                
209
213
                if(vlr->radface) {
210
214
                        rf= vlr->radface;
218
222
}
219
223
 
220
224
/* based at RG.formfactors array, distribute shoot energy over other faces */
221
 
static void applyformfactors_rr(VlakRen *shoot)
 
225
static void applyformfactors_rr(Render *re, VlakRen *shoot)
222
226
{
223
227
        VlakRen *vlr=NULL;
224
228
        RadFace *rf;
231
235
 
232
236
        fp= RG.formfactors;
233
237
        
234
 
        for(a=0; a<R.totvlak; a++) {
235
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
238
        for(a=0; a<re->totvlak; a++) {
 
239
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
236
240
                
237
241
                if(vlr->radface) {
238
242
                        rf= vlr->radface;
263
267
 
264
268
 
265
269
/* main loop for itterations */
266
 
static void progressiverad_rr()
 
270
static void progressiverad_rr(Render *re)
267
271
{
268
 
        extern void RE_local_timecursor(int);   // RE_callbacks.c
269
272
        VlakRen *shoot;
270
273
        float unshot[3];
271
274
        int it= 0;
272
275
        
273
 
        shoot= findshoot_rr();
 
276
        shoot= findshoot_rr(re);
274
277
        while( shoot ) {
275
278
                
276
279
                /* backfaces receive no energy, but are zbuffered... */
277
 
                backface_test_rr(shoot);
 
280
                backface_test_rr(re, shoot);
278
281
                
279
282
                /* ...unless it's two sided */
280
283
                if(shoot->radface->flag & RAD_TWOSIDED) {
281
284
                        VECCOPY(unshot, shoot->radface->unshot);
282
285
                        VecMulf(shoot->radface->norm, -1.0);
283
 
                        makeformfactors_rr(shoot);
284
 
                        applyformfactors_rr(shoot);
 
286
                        makeformfactors_rr(re, shoot);
 
287
                        applyformfactors_rr(re, shoot);
285
288
                        VecMulf(shoot->radface->norm, -1.0);
286
289
                        VECCOPY(shoot->radface->unshot, unshot);
287
290
                }
288
291
 
289
292
                /* hemi-zbuffers */
290
 
                makeformfactors_rr(shoot);
 
293
                makeformfactors_rr(re, shoot);
291
294
                /* based at RG.formfactors array, distribute shoot energy over other faces */
292
 
                applyformfactors_rr(shoot);
 
295
                applyformfactors_rr(re, shoot);
293
296
                
294
297
                it++;
295
 
                RE_local_timecursor(it);
296
 
                
297
 
                clear_backface_test_rr();
298
 
                
299
 
                if(blender_test_break()) break;
 
298
                re->timecursor(it);
 
299
                
 
300
                clear_backface_test_rr(re);
 
301
                
 
302
                if(re->test_break()) break;
300
303
                if(RG.maxiter && RG.maxiter<=it) break;
301
304
                
302
 
                shoot= findshoot_rr();
 
305
                shoot= findshoot_rr(re);
303
306
        }
304
307
        printf(" Unshot energy:%f\n", 1000.0*maxenergy);
305
308
        
306
 
        RE_local_timecursor((G.scene->r.cfra));
 
309
        re->timecursor((G.scene->r.cfra));
307
310
}
308
311
 
309
312
static RadFace *radfaces=NULL;
310
313
 
311
 
static void initradfaces(void)  
 
314
static void initradfaces(Render *re)    
312
315
{
313
316
        VlakRen *vlr= NULL;
314
317
        RadFace *rf;
323
326
        RG.max[0]= RG.max[1]= RG.max[2]= -1.0e20;
324
327
        
325
328
        /* count first for fast malloc */
326
 
        for(a=0; a<R.totvlak; a++) {
327
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
329
        for(a=0; a<re->totvlak; a++) {
 
330
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
328
331
                
329
332
                if(vlr->mat->mode & MA_RADIO) {
330
333
                        if(vlr->mat->emit > 0.0) {
339
342
 
340
343
        /* make/init radfaces */
341
344
        rf=radfaces= MEM_callocN(RG.totelem*sizeof(RadFace), "radfaces");
342
 
        for(a=0; a<R.totvlak; a++) {
343
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
345
        for(a=0; a<re->totvlak; a++) {
 
346
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
344
347
                
345
348
                if(vlr->mat->mode & MA_RADIO) {
346
349
                        
399
402
 
400
403
}
401
404
 
402
 
#if 0
403
 
/* unused now, doesnt work... */
404
 
static void filter_rad_values(void)
405
 
{
406
 
        VlakRen *vlr=NULL;
407
 
        VertRen *v1=NULL;
408
 
        RadFace *rf;
409
 
        float n1[3], n2[3], n3[4], n4[3], co[4];
410
 
        int a;
411
 
        
412
 
        /* one filter pass */
413
 
        for(a=0; a<R.totvert; a++) {
414
 
                if((a & 255)==0) v1= R.blove[a>>8]; else v1++;
415
 
                if(v1->accum>0.0) {
416
 
                        v1->rad[0]= v1->rad[0]/v1->accum;
417
 
                        v1->rad[1]= v1->rad[1]/v1->accum;
418
 
                        v1->rad[2]= v1->rad[2]/v1->accum;
419
 
                        v1->accum= 0.0;
420
 
                }
421
 
        }
422
 
        /* cosines in verts accumulate in faces */
423
 
        for(a=0; a<R.totvlak; a++) {
424
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
425
 
                
426
 
                if(vlr->radface) {
427
 
                        rf= vlr->radface;
428
 
                        
429
 
                        /* calculate cosines of angles, for weighted add (irregular faces) */
430
 
                        VecSubf(n1, vlr->v2->co, vlr->v1->co);
431
 
                        VecSubf(n2, vlr->v3->co, vlr->v2->co);
432
 
                        Normalise(n1);
433
 
                        Normalise(n2);
434
 
        
435
 
                        if(vlr->v4==NULL) {
436
 
                                VecSubf(n3, vlr->v1->co, vlr->v3->co);
437
 
                                Normalise(n3);
438
 
                                
439
 
                                co[0]= saacos(-n3[0]*n1[0]-n3[1]*n1[1]-n3[2]*n1[2])/M_PI;
440
 
                                co[1]= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2])/M_PI;
441
 
                                co[2]= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2])/M_PI;
442
 
                                co[0]= co[1]= co[2]= 1.0/3.0;
443
 
                        }
444
 
                        else {
445
 
                                VecSubf(n3, vlr->v4->co, vlr->v3->co);
446
 
                                VecSubf(n4, vlr->v1->co, vlr->v4->co);
447
 
                                Normalise(n3);
448
 
                                Normalise(n4);
449
 
                                
450
 
                                co[0]= saacos(-n4[0]*n1[0]-n4[1]*n1[1]-n4[2]*n1[2])/M_PI;
451
 
                                co[1]= saacos(-n1[0]*n2[0]-n1[1]*n2[1]-n1[2]*n2[2])/M_PI;
452
 
                                co[2]= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2])/M_PI;
453
 
                                co[3]= saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2])/M_PI;
454
 
                                co[0]= co[1]= co[2]= co[3]= 1.0/4.0;
455
 
                        }
456
 
                        
457
 
                        rf->totrad[0]= rf->totrad[1]= rf->totrad[2]= 0.0;
458
 
 
459
 
                        vecaddfac(rf->totrad, rf->totrad, vlr->v1->rad, co[0]); 
460
 
                        vecaddfac(rf->totrad, rf->totrad, vlr->v2->rad, co[1]); 
461
 
                        vecaddfac(rf->totrad, rf->totrad, vlr->v3->rad, co[2]); 
462
 
                        if(vlr->v4) {
463
 
                                vecaddfac(rf->totrad, rf->totrad, vlr->v4->rad, co[3]); 
464
 
                        }
465
 
                }
466
 
        }
467
 
 
468
 
        /* accumulate vertexcolors again */
469
 
        for(a=0; a<R.totvlak; a++) {
470
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
471
 
                
472
 
                if(vlr->radface) {
473
 
                        rf= vlr->radface;
474
 
 
475
 
                        vecaddfac(vlr->v1->rad, vlr->v1->rad, rf->totrad, rf->area); 
476
 
                        vlr->v1->accum+= rf->area;
477
 
                        vecaddfac(vlr->v2->rad, vlr->v2->rad, rf->totrad, rf->area); 
478
 
                        vlr->v2->accum+= rf->area;
479
 
                        vecaddfac(vlr->v3->rad, vlr->v3->rad, rf->totrad, rf->area); 
480
 
                        vlr->v3->accum+= rf->area;
481
 
                        if(vlr->v4) {
482
 
                                vecaddfac(vlr->v4->rad, vlr->v4->rad, rf->totrad, rf->area); 
483
 
                                vlr->v4->accum+= rf->area;
484
 
                        }
485
 
                }
486
 
        }
487
 
 
488
 
}
489
 
#endif
490
 
 
491
 
static void make_vertex_rad_values()
492
 
{
493
 
        VertRen *v1=NULL;
494
 
        VlakRen *vlr=NULL;
495
 
        RadFace *rf;
 
405
/* unused now, doesnt work..., find it in cvs of nov 2005 or older */
 
406
/* static void filter_rad_values(void) */
 
407
 
 
408
 
 
409
static void make_vertex_rad_values(Render *re)
 
410
{
 
411
        VertRen *v1=NULL;
 
412
        VlakRen *vlr=NULL;
 
413
        RadFace *rf;
 
414
        float *col;
496
415
        int a;
497
416
 
498
417
        RG.igamma= 1.0/RG.gamma;
499
418
        RG.radfactor= RG.radfac*pow(64*64, RG.igamma)/128.0; /* compatible with radio-tool */
500
419
 
501
420
        /* accumulate vertexcolors */
502
 
        for(a=0; a<R.totvlak; a++) {
503
 
                if((a & 255)==0) vlr= R.blovl[a>>8]; else vlr++;
 
421
        for(a=0; a<re->totvlak; a++) {
 
422
                if((a & 255)==0) vlr= re->blovl[a>>8]; else vlr++;
504
423
                
505
424
                if(vlr->radface) {
506
425
                        rf= vlr->radface;
515
434
                        if(vlr->mat->g > 0.0) rf->totrad[1]/= vlr->mat->g;
516
435
                        if(vlr->mat->b > 0.0) rf->totrad[2]/= vlr->mat->b;
517
436
                        
518
 
                        vecaddfac(vlr->v1->rad, vlr->v1->rad, rf->totrad, rf->area); 
519
 
                        vlr->v1->accum+= rf->area;
520
 
                        vecaddfac(vlr->v2->rad, vlr->v2->rad, rf->totrad, rf->area); 
521
 
                        vlr->v2->accum+= rf->area;
522
 
                        vecaddfac(vlr->v3->rad, vlr->v3->rad, rf->totrad, rf->area); 
523
 
                        vlr->v3->accum+= rf->area;
 
437
                        col= RE_vertren_get_rad(re, vlr->v1, 1);
 
438
                        vecaddfac(col, col, rf->totrad, rf->area); 
 
439
                        col[3]+= rf->area;
 
440
                        
 
441
                        col= RE_vertren_get_rad(re, vlr->v2, 1);
 
442
                        vecaddfac(col, col, rf->totrad, rf->area); 
 
443
                        col[3]+= rf->area;
 
444
                        
 
445
                        col= RE_vertren_get_rad(re, vlr->v3, 1);
 
446
                        vecaddfac(col, col, rf->totrad, rf->area); 
 
447
                        col[3]+= rf->area;
 
448
 
524
449
                        if(vlr->v4) {
525
 
                                vecaddfac(vlr->v4->rad, vlr->v4->rad, rf->totrad, rf->area); 
526
 
                                vlr->v4->accum+= rf->area;
 
450
                                col= RE_vertren_get_rad(re, vlr->v4, 1);
 
451
                                vecaddfac(col, col, rf->totrad, rf->area); 
 
452
                                col[3]+= rf->area;
527
453
                        }
528
454
                }
529
455
        }
530
456
        
531
457
        /* make vertex colors */
532
 
        for(a=0; a<R.totvert; a++) {
533
 
                if((a & 255)==0) v1= R.blove[a>>8]; else v1++;
534
 
                if(v1->accum>0.0) {
535
 
                        v1->rad[0]/= v1->accum;
536
 
                        v1->rad[1]/= v1->accum;
537
 
                        v1->rad[2]/= v1->accum;                 
 
458
        for(a=0; a<re->totvert; a++) {
 
459
                if((a & 255)==0) v1= RE_findOrAddVert(re, a); else v1++;
 
460
                
 
461
                col= RE_vertren_get_rad(re, v1, 0);
 
462
                if(col && col[3]>0.0) {
 
463
                        col[0]/= col[3];
 
464
                        col[1]/= col[3];
 
465
                        col[2]/= col[3];
538
466
                }
539
467
        }
540
468
 
541
469
}
542
470
 
543
471
/* main call, extern */
544
 
void do_radio_render(void)
 
472
void do_radio_render(Render *re)
545
473
{
546
474
        if(G.scene->radio==NULL) add_radio();
547
475
        freeAllRad();   /* just in case radio-tool is still used */
548
476
        
549
477
        set_radglobal(); /* init the RG struct */
550
 
 
551
 
        initradfaces();  /* add radface structs to render faces */
 
478
        RG.re= re;              /* only used by hemizbuf(), prevents polluting radio code all over */
 
479
        
 
480
        initradfaces(re);        /* add radface structs to render faces */
552
481
        if(RG.totenergy>0.0) {
553
482
 
554
483
                initradiosity();        /* LUT's */
555
484
                inithemiwindows();      /* views, need RG.maxsize for clipping */
556
485
        
557
 
                progressiverad_rr(); /* main radio loop */
 
486
                progressiverad_rr(re); /* main radio loop */
558
487
                
559
 
                make_vertex_rad_values(); /* convert face energy to vertex ones */
 
488
                make_vertex_rad_values(re); /* convert face energy to vertex ones */
560
489
 
561
490
        }
562
491