[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11747] branches/soc-2007-joeedh/source/ blender: more bugs fixed!! First I upped the max number of zsamples per pixel to 7500 (note that most will be compressed away, this is only the max limit of *initial* samples).
Joseph Eagar
joeedh at gmail.com
Mon Aug 20 19:53:55 CEST 2007
Revision: 11747
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11747
Author: joeedh
Date: 2007-08-20 19:53:55 +0200 (Mon, 20 Aug 2007)
Log Message:
-----------
more bugs fixed!! First I upped the max number of zsamples per pixel to 7500 (note that most will be compressed away, this is only the max limit of *initial* samples). Also not enough tiles were being created for the map, causing shadow clipping errors. Then there was the other clipping error, caused by me ignoring zsamples with z < 0 (why the hell does that happen?).
Next up is investigating proper way to handle transparent alpha and color, its a little messed up at the moment. then of course the tiling cache system.
Joe
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c
branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h
branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h
branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c
branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c
branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c 2007-08-20 17:53:55 UTC (rev 11747)
@@ -47,9 +47,10 @@
(int) total number of pixels
(int) x relative to tile origin
(int) y relative to tile origin
- (int) total number of elements
- (1 int per array cell) depth array
- (4 short integers per array cell) color array, packed as shorts
+ (3 ints) number of elements in the R function.
+ (1 int) for depth, (1 short) for value, (1 short) for previous values
+ needed for multilayer transparent shadow maps.
+ Repeat for G and B functions.
*/
#define DSM_MAGICNUM ('D' | ('S' << 8) | ('H' << 16) | ('D' << 24)) //"DSHD"
@@ -139,7 +140,7 @@
for (y=0; y<self->sizey; y++) {
for (x=0; x<self->sizex; x++) {
- if (self->layer_rect[y*self->sizex+x]) {
+ if (self->r_rect[y*self->sizex+x] || self->g_rect[y*self->sizex+x] || self->b_rect[y*self->sizex+x]) {
tot++;
first = self->layer_rect[y*self->sizex+x];
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h 2007-08-20 17:53:55 UTC (rev 11747)
@@ -207,7 +207,7 @@
float viewmat[4][4];
float winmat[4][4];
float *jit, *weight;
- float d, clipend, pixsize, soft;
+ float d, clipend, clipsta, pixsize, soft;
int co[3];
int size, bias;
ListBase buffers;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h 2007-08-20 17:53:55 UTC (rev 11747)
@@ -94,6 +94,10 @@
void (*zbuffunc)(struct ZSpan *, int, float *, float *, float *, float *);
void (*zbuflinefunc)(struct ZSpan *, int, float *, float *);
+
+ /*used by dsm to get linear Z*/
+ void (*hoco_to_zco)(struct ZSpan *zspan, float *zco, float *hoco);
+ void *hoco_data;
/* maximum difference between depths of pixel samples.
this is used by he transparent zbuffer functions,
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.c 2007-08-20 17:53:55 UTC (rev 11747)
@@ -2134,7 +2134,14 @@
/* bias is percentage, made 2x larger because of correction for angle of incidence */
/* when a ray is closer to parallel of a face, bias value is increased during render */
- shb->bias= (0.02*lar->bias)*0x7FFFFFFF;
+
+ /*use different method for deep shadow buffers, which use linear Z:*/
+ //if (lar->buftype==LA_SHADBUF_DEEP) {
+ // shb->bias = 0x7FFFFFFF*((double)(0.02*lar->bias)/(double)(lar->clipend - lar->clipsta));
+ //} else {
+ shb->bias= (0.02*lar->bias)*0x7FFFFFFF;
+ //}
+
shb->bias= shb->bias*(100/re->r.size);
/* halfway method (average of first and 2nd z) reduces bias issues */
@@ -3430,6 +3437,7 @@
if(!re->test_break()) {
LampRen *lar;
+ extern Render R;
sort_halos(re);
@@ -3457,6 +3465,22 @@
re->i.infostr= "Creating Shadowbuffers";
re->stats_draw(&re->i);
+ /*R needs updating before making deep shadow buffers*/
+ R = *re;
+
+ DSM_MakeTilePool(U.dsm_maxmem*1024*1024); /*FIXMEGREP: hardcoded value of 50 megs!*/
+
+ /* SHADOW BUFFER */
+ for(lar=re->lampren.first; lar; lar= lar->next) {
+ if(re->test_break()) break;
+
+ /*deep shadow buffers might need to be initilzied in another place*/
+ if(lar->shb) {
+ /* if type is irregular, this only sets the perspective matrix and autoclips */
+ makeshadowbuf(re, lar);
+ }
+ }
+
/* yafray: 'direct' radiosity, environment maps and raytree init not needed for yafray render */
/* although radio mode could be useful at some point, later */
if (re->r.renderer==R_INTERN) {
@@ -3474,7 +3498,7 @@
if(!re->test_break())
make_envmaps(re);
}
-
+
if(!re->test_break())
project_renderdata(re, projectverto, re->r.mode & R_PANORAMA, 0);
@@ -3487,31 +3511,6 @@
if(re->test_break())
RE_Database_Free(re);
else {
- LampRen *lar;
- extern Render R;
-
- R = *re;
-
- DSM_MakeTilePool(U.dsm_maxmem*1024*1024); /*FIXMEGREP: hardcoded value of 50 megs!*/
-
- /* SHADOW BUFFER */
- for(lar=re->lampren.first; lar; lar= lar->next) {
- if(re->test_break()) break;
-
- /*deep shadow buffers might need to be initilzied in another place*/
- if(lar->shb) {
- #ifdef DSM_ANNOYING_BUGTEST
- if (lar->buftype != LA_SHADBUF_DEEP) {
- #endif
- /* if type is irregular, this only sets the perspective matrix and autoclips */
- makeshadowbuf(re, lar);
- #ifdef DSM_ANNOYING_BUGTEST
- }
- #endif
- }
- }
- project_renderdata(re, projectverto, re->r.mode & R_PANORAMA, 0);
-
re->i.convertdone= 1;
}
re->i.infostr= NULL;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c 2007-08-20 17:53:55 UTC (rev 11747)
@@ -1054,10 +1054,10 @@
/* extern call from shade_lamp_loop */
-void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac)
+void ray_shadow(ShadeInput *shi, LampRen *lar, float *lampshadfac)
{
Isect isec;
- float lampco[3], maxsize;
+ float lampco[3], maxsize, shadfac[4] = {1.0f, 1.0f, 1.0f, 1.0f};
/* setup isec */
if(shi->mat->mode & MA_SHADOW_TRA) isec.mode= RE_RAY_SHADOW_TRA;
@@ -1179,6 +1179,11 @@
}
}
+ shadfac[0] *= shadfac[3];
+ shadfac[1] *= shadfac[3];
+ shadfac[2] *= shadfac[3];
+ VECCOPY(lampshadfac, shadfac);
+
/* for first hit optim, set last interesected shadow face */
if(shi->depth==0)
lar->vlr_last[shi->thread]= (VlakRen*)isec.face_last;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-08-20 17:53:55 UTC (rev 11747)
@@ -380,6 +380,8 @@
if(lar->buftype==LA_SHADBUF_IRREGULAR)
shb->size= 1024;
+ shb->clipsta = lar->clipsta;
+
/* matrices and window: in winmat the transformation is being put,
transforming from observer view to lamp view, including lamp window matrix */
@@ -597,7 +599,7 @@
DSMFunction *func;
float fac, co[4], siz, alpha; //, *clr; //*jit, *weight, *rz, note: these three might be needed, look into it
int xs, ys;
- int zs, bias, tilex, tiley, i;
+ int zs, bias, newbias, tilex, tiley, i;
//printf("in DSM_getShadow!!\n");
@@ -622,6 +624,17 @@
xs= siz*(1.0f+co[0]/co[3]);
ys= siz*(1.0f+co[1]/co[3]);
+ /* disabled code for linear zbuffer lookup. linear zbuffer is really
+ only needed for simple translucency effects, and if those ever
+ get implemented there are other ways to do it. the current
+ code isn't working.
+
+ if (co[2] < shb->clipsta) return 1.0f;
+ else if (co[2] > shb->clipend) co[2] = shb->clipend - 0.001;
+
+ fac= (double)(co[2] - shb->clipsta) / (double)(shb->clipend - shb->clipsta);*/
+
+
/* Clip for z: clipsta and clipend clip values of the shadow buffer. We
* can test for -1.0/1.0 because of the properties of the
* coordinate transformations. */
@@ -661,9 +674,6 @@
xs = xs % buf->tsizex;
ys = ys % buf->tsizey;
- //printf("2: xs: %d, ys: %d, zs: %d\n", xs, ys, zs);
-
-
switch (component) {
case 0:
func = tile->r_rect[ys*tile->sizex+xs];
@@ -684,16 +694,17 @@
alpha = 1.0;
- bias=bias/6.0; //odd that I have to do this :/
- //clr = dsm_bsearch(sample, zs, bias);
- // &&
- //printf("func->totsamples: %d\n", func->totsamples);
+ /*this check taken from testshadowbuf*/
+ if(zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */
+
+ newbias = bias/3; /* odd that I have to do this :/ */
+
for (i=0; i<func->totsamples; i++) {
- if (zs > sample[i].depth+bias) {
+ if (zs > sample[i].depth+newbias) {
if (i != func->totsamples-1) {
- if (zs < sample[i+1].depth+bias) {
+ if (zs < sample[i+1].depth+newbias) {
BASSERT(sample[i].depth < sample[i+1].depth);
- alpha = lerp(sample[i].depth+bias, sample[i+1].depth+bias, zs, sample[i].value, sample[i+1].value);
+ alpha = lerp(sample[i].depth+newbias, sample[i+1].depth+newbias, zs, sample[i].value, sample[i+1].value);
break;
}
} else {
@@ -703,7 +714,7 @@
}
if (alpha > 1.0001) printf("alpha was greater then 1.0!! alpha: %f\n", alpha);
- //printf("alpha: %f\n", alpha);
+
if (alpha < -0.0001) {
printf("alpha was less then 0! it was %f\n", alpha);
alpha = 0.0;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c 2007-08-20 17:50:04 UTC (rev 11746)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c 2007-08-20 17:53:55 UTC (rev 11747)
@@ -91,6 +91,7 @@
zspan->rectx= rectx;
zspan->recty= recty;
+ zspan->hoco_to_zco = NULL;
zspan->span1= MEM_mallocN(recty*sizeof(float), "zspan");
zspan->span2= MEM_mallocN(recty*sizeof(float), "zspan");
@@ -885,6 +886,13 @@
{
float div;
+ /*use a custom persptive divide function, if it exists
+ (currently only used for deep shadow maps)*/
+ if (zspan->hoco_to_zco) {
+ zspan->hoco_to_zco(zspan, zco, hoco);
+ return;
+ }
+
div= 1.0f/hoco[3];
zco[0]= zspan->zmulx*(1.0+hoco[0]*div) + zspan->zofsx;
zco[1]= zspan->zmuly*(1.0+hoco[1]*div) + zspan->zofsy;
@@ -2750,24 +2758,6 @@
if(my2<my0) return;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list