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

« back to all changes in this revision

Viewing changes to source/blender/render/intern/source/shadbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 * 
31
31
 *  april 95
32
32
 * 
33
 
 * $Id: shadbuf.c,v 1.7 2003/12/21 21:52:50 ton Exp $
 
33
 * $Id: shadbuf.c,v 1.15 2005/04/23 20:49:23 ton Exp $
34
34
 *
35
35
 * 27-Jun-2001 switched the shadow buffer for UR to the object-shadow
36
36
 * buffers, and removed all references and fixes for UR rendering from
42
42
 
43
43
#include "MTC_matrixops.h"
44
44
#include "MEM_guardedalloc.h"
 
45
 
 
46
#include "DNA_lamp_types.h"
 
47
#include "BKE_utildefines.h"
45
48
#include "BLI_arithb.h"
46
49
 
47
 
#include "DNA_lamp_types.h"
48
 
 
49
50
#include "render.h"
50
 
#include "render_intern.h"
51
51
 
52
52
#include "shadbuf.h"
53
53
#include "renderHelp.h"
54
54
#include "jitter.h"
55
55
#include "zbuf.h"
56
56
 
57
 
#ifdef HAVE_CONFIG_H
58
 
#include <config.h>
 
57
/* XXX, could be better implemented...
 
58
*/
 
59
#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
 
60
#define RCOMP   3
 
61
#define GCOMP   2
 
62
#define BCOMP   1
 
63
#define ACOMP   0
 
64
#else
 
65
#define RCOMP   0
 
66
#define GCOMP   1
 
67
#define BCOMP   2
 
68
#define ACOMP   3
59
69
#endif
60
70
 
61
 
/* if defined: objects don't cast shadows anymore                            */
62
 
/*  #define RE_NO_SHADOWS */
63
 
 
64
 
/* unused? */
65
 
static int bias= 0x00500000;
66
 
/* crud */
67
 
#define MIN2(x,y)               ( (x)<(y) ? (x) : (y) )
68
 
 
69
 
/* ------------------------------------------------------------------------- */
70
 
 
71
 
void lrectreadRectz(int x1, int y1, int x2, int y2, char *r1);
72
 
int sizeoflampbuf(struct ShadBuf *shb);
73
 
int firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr);
74
 
float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs);
75
 
float readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs);
76
 
float *give_jitter_tab(int samp);
77
71
/* ------------------------------------------------------------------------- */
78
72
 
79
73
 
88
82
        shb= (struct ShadBuf *)MEM_callocN( sizeof(struct ShadBuf),"initshadbuf");
89
83
        lar->shb= shb;
90
84
 
91
 
        if(shb==0) return;
 
85
        if(shb==NULL) return;
92
86
 
93
87
        VECCOPY(shb->co, lar->co);
94
88
        
138
132
/* ------------------------------------------------------------------------- */
139
133
 
140
134
 
141
 
void lrectreadRectz(int x1, int y1, int x2, int y2, char *r1) /* reads part from rectz in r1 */
 
135
static void lrectreadRectz(int x1, int y1, int x2, int y2, char *r1) /* reads part from rectz in r1 */
142
136
{
143
137
        unsigned int len4, *rz; 
144
138
 
154
148
        }
155
149
}
156
150
 
157
 
 
158
 
int sizeoflampbuf(struct ShadBuf *shb)
 
151
#if 0
 
152
static int sizeoflampbuf(struct ShadBuf *shb)
159
153
{
160
154
        int num,count=0;
161
155
        char *cp;
167
161
        
168
162
        return 256*count;
169
163
}
 
164
#endif
170
165
 
171
 
float *give_jitter_tab(int samp)
 
166
static float *give_jitter_tab(int samp)
172
167
{
173
168
        /* these are all possible jitter tables, takes up some
174
169
         * 12k, not really bad!
200
195
        float temp, wsize, dist;
201
196
        int *rz, *rz1, verg, verg1;
202
197
        unsigned long *ztile;
203
 
        int a, x, y, minx, miny, byt1, byt2;
 
198
        int a, x, y, minx, miny, byt1, byt2, tempmode;
204
199
        short temprx,tempry, square;
205
200
        char *rc, *rcline, *ctile, *zt;
206
201
 
207
202
        panophi = getPanoPhi();
208
203
        
209
204
        /* store viewvars */
210
 
        temprx= R.rectx; tempry= R.recty;
 
205
        temprx= R.rectx; tempry= R.recty; 
 
206
        tempmode= R.r.mode;
 
207
        R.r.mode &= ~R_ORTHO;
211
208
        R.rectx= R.recty= shb->size;
212
209
 
213
210
        shb->jit= give_jitter_tab(shb->samp);
337
334
        }
338
335
 
339
336
        MEM_freeN(rcline);
340
 
        MEM_freeN(R.rectz); R.rectz= 0;
341
 
 
 
337
        MEM_freeN(R.rectz); R.rectz= NULL;
 
338
        
 
339
        /* old globals back */
342
340
        R.rectx= temprx; R.recty= tempry;
 
341
        R.r.mode= tempmode;
343
342
        MTC_Mat4SwapMat4(shb->persmat, R.winmat);
344
343
 
345
344
        /* printf("lampbuf %d\n", sizeoflampbuf(shb)); */
346
345
}
347
346
 
348
 
int firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr)
 
347
static int firstreadshadbuf(struct ShadBuf *shb, int xs, int ys, int nr)
349
348
{
350
349
        /* return a 1 if fully compressed shadbuf-tile && z==const */
351
350
        static int *rz;
372
371
        return 0;
373
372
}
374
373
 
375
 
float readshadowbuf(struct ShadBuf *shb, int xs, int ys, int zs)        /* return 1.0 : fully in light */
 
374
static float readshadowbuf(struct ShadBuf *shb, int bias, int xs, int ys, int zs)       /* return 1.0 : fully in light */
376
375
{
377
376
        float temp;
378
377
        int *rz, ofs;
435
434
        }
436
435
}
437
436
 
438
 
 
439
 
float testshadowbuf(struct ShadBuf *shb, float *rco, float inp)         /* return 1.0: no shadow at all */
 
437
/* the externally called shadow testing (reading) function */
 
438
/* return 1.0: no shadow at all */
 
439
float testshadowbuf(struct ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp)
440
440
{
441
441
        float fac, co[4], dx[3], dy[3], aantal=0;
442
442
        float xs1,ys1, siz, *j, xres, yres;
443
 
        int xs,ys, zs;
 
443
        int xs,ys, zs, bias;
444
444
        short a,num;
445
445
        
446
 
#ifdef RE_NO_SHADOWS
447
 
        return 1.0;
448
 
#endif
449
 
        
450
446
        /* if(inp <= 0.0) return 1.0; */
451
447
 
452
448
        /* rotate renderco en osaco */
476
472
        num= shb->samp*shb->samp;
477
473
        fac= shb->soft;
478
474
        
479
 
        
480
 
        bias= (1.1-inp*inp)*shb->bias;
 
475
        /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors 
 
476
           on cube edges, with one side being almost frontal lighted (ton)  */
 
477
        bias= (1.5-inp*inp)*shb->bias;
481
478
 
482
479
        if(num==1) {
483
 
                return readshadowbuf(shb,(int)xs1, (int)ys1, zs);
 
480
                return readshadowbuf(shb, bias, (int)xs1, (int)ys1, zs);
484
481
        }
485
482
 
486
 
        co[0]= rco[0]+O.dxco[0];
487
 
        co[1]= rco[1]+O.dxco[1];
488
 
        co[2]= rco[2]+O.dxco[2];
 
483
        co[0]= rco[0]+dxco[0];
 
484
        co[1]= rco[1]+dxco[1];
 
485
        co[2]= rco[2]+dxco[2];
489
486
        co[3]= 1.0;
490
487
        MTC_Mat4MulVec4fl(shb->persmat,co);     /* rational hom co */
491
488
        dx[0]= xs1- siz*(1.0+co[0]/co[3]);
492
489
        dx[1]= ys1- siz*(1.0+co[1]/co[3]);
493
490
 
494
 
        co[0]= rco[0]+O.dyco[0];
495
 
        co[1]= rco[1]+O.dyco[1];
496
 
        co[2]= rco[2]+O.dyco[2];
 
491
        co[0]= rco[0]+dyco[0];
 
492
        co[1]= rco[1]+dyco[1];
 
493
        co[2]= rco[2]+dyco[2];
497
494
        co[3]= 1.0;
498
495
        MTC_Mat4MulVec4fl(shb->persmat,co);     /* rational hom co */
499
496
        dy[0]= xs1- siz*(1.0+co[0]/co[3]);
515
512
                        if(firstreadshadbuf(shb, (int)(xs1+xres), (int)ys1, 1)) {
516
513
                                if(firstreadshadbuf(shb, (int)xs1, (int)(ys1+yres), 1)) {
517
514
                                        if(firstreadshadbuf(shb, (int)(xs1+xres), (int)(ys1+yres), 1)) {
518
 
                                                return readshadowbuf(shb,(int)xs1, (int)ys1, zs);
 
515
                                                return readshadowbuf(shb, bias,(int)xs1, (int)ys1, zs);
519
516
                                        }
520
517
                                }
521
518
                        }
524
521
 
525
522
        for(a=num;a>0;a--) {
526
523
                /* instead of jit i tried random: ugly! */
527
 
                xs= xs1 + xres*j[0];
528
 
                ys= ys1 + yres*j[1];
 
524
                /* note: the plus 0.5 gives best sampling results, jit used to go from 0-1 */
 
525
                /* xs1 and ys1 are already corrected to be corner of sample area */
 
526
                xs= xs1 + xres*(j[0] + 0.5);
 
527
                ys= ys1 + yres*(j[1] + 0.5);
529
528
                j+=2;
530
529
                
531
 
                aantal+= readshadowbuf(shb, xs, ys, zs);
 
530
                aantal+= readshadowbuf(shb, bias, xs, ys, zs);
532
531
        }
533
532
 
534
533
        /* Renormalizes for the sample number: */
537
536
 
538
537
/* different function... sampling behind clipend can be LIGHT, bias is negative! */
539
538
/* return: light */
540
 
float readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs)
 
539
static float readshadowbuf_halo(struct ShadBuf *shb, int xs, int ys, int zs)
541
540
{
542
541
        float temp;
543
542
        int *rz, ofs;
544
 
        int zbias, zsamp;
 
543
        int bias, zbias, zsamp;
545
544
        char *ct, *cz;
546
545
 
 
546
        /* negative! The other side is more important */
 
547
        bias= -shb->bias;
 
548
        
547
549
        /* simpleclip */
548
550
        if(xs<0 || ys<0) return 0.0;
549
551
        if(xs>=shb->size || ys>=shb->size) return 0.0;
618
620
        int dx = 0, dy = 0;
619
621
        
620
622
        siz= 0.5*(float)shb->size;
621
 
        /* negative! The other side is more important */
622
 
        bias= -shb->bias;
623
623
        
624
624
        co[0]= p1[0];
625
625
        co[1]= p1[1];
710
710
                zf= zf1 + labda*(zf2-zf1);
711
711
                count+= 1.0;
712
712
 
713
 
                if(zf<= 0.0) lightcount += 1.0; /* close to the spot */
 
713
                if(zf<= -1.0) lightcount += 1.0;        /* close to the spot */
714
714
                else {
715
715
                
716
716
                        /* make sure, behind the clipend we extend halolines. */