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 $
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
43
43
#include "MTC_matrixops.h"
44
44
#include "MEM_guardedalloc.h"
46
#include "DNA_lamp_types.h"
47
#include "BKE_utildefines.h"
45
48
#include "BLI_arithb.h"
47
#include "DNA_lamp_types.h"
49
50
#include "render.h"
50
#include "render_intern.h"
52
52
#include "shadbuf.h"
53
53
#include "renderHelp.h"
54
54
#include "jitter.h"
57
/* XXX, could be better implemented...
59
#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
61
/* if defined: objects don't cast shadows anymore */
62
/* #define RE_NO_SHADOWS */
65
static int bias= 0x00500000;
67
#define MIN2(x,y) ( (x)<(y) ? (x) : (y) )
69
/* ------------------------------------------------------------------------- */
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
/* ------------------------------------------------------------------------- */
138
132
/* ------------------------------------------------------------------------- */
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 */
143
137
unsigned int len4, *rz;
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;
207
202
panophi = getPanoPhi();
209
204
/* store viewvars */
210
temprx= R.rectx; tempry= R.recty;
205
temprx= R.rectx; tempry= R.recty;
207
R.r.mode &= ~R_ORTHO;
211
208
R.rectx= R.recty= shb->size;
213
210
shb->jit= give_jitter_tab(shb->samp);
339
336
MEM_freeN(rcline);
340
MEM_freeN(R.rectz); R.rectz= 0;
337
MEM_freeN(R.rectz); R.rectz= NULL;
339
/* old globals back */
342
340
R.rectx= temprx; R.recty= tempry;
343
342
MTC_Mat4SwapMat4(shb->persmat, R.winmat);
345
344
/* printf("lampbuf %d\n", sizeoflampbuf(shb)); */
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)
350
349
/* return a 1 if fully compressed shadbuf-tile && z==const */
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 */
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)
441
441
float fac, co[4], dx[3], dy[3], aantal=0;
442
442
float xs1,ys1, siz, *j, xres, yres;
450
446
/* if(inp <= 0.0) return 1.0; */
452
448
/* rotate renderco en osaco */
476
472
num= shb->samp*shb->samp;
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;
483
return readshadowbuf(shb,(int)xs1, (int)ys1, zs);
480
return readshadowbuf(shb, bias, (int)xs1, (int)ys1, zs);
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];
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]);
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];
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);
525
522
for(a=num;a>0;a--) {
526
523
/* instead of jit i tried random: ugly! */
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);
531
aantal+= readshadowbuf(shb, xs, ys, zs);
530
aantal+= readshadowbuf(shb, bias, xs, ys, zs);
534
533
/* Renormalizes for the sample number: */
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)
543
int bias, zbias, zsamp;
546
/* negative! The other side is more important */
548
550
if(xs<0 || ys<0) return 0.0;
549
551
if(xs>=shb->size || ys>=shb->size) return 0.0;
710
710
zf= zf1 + labda*(zf2-zf1);
713
if(zf<= 0.0) lightcount += 1.0; /* close to the spot */
713
if(zf<= -1.0) lightcount += 1.0; /* close to the spot */
716
716
/* make sure, behind the clipend we extend halolines. */