[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11571] branches/soc-2007-joeedh/source/ blender: Deep shadow maps now work again.
Joseph Eagar
joeedh at gmail.com
Mon Aug 13 08:42:21 CEST 2007
Revision: 11571
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11571
Author: joeedh
Date: 2007-08-13 08:42:21 +0200 (Mon, 13 Aug 2007)
Log Message:
-----------
Deep shadow maps now work again. They now correctly use visibility functions.
However, I have yet to implement the lossy compression or get the cache system
working again, so it takes a large amount of RAM again. Rather more then it
did before *without* the tiling cache, in fact, around twice as much.
Joe
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
branches/soc-2007-joeedh/source/blender/src/header_filesel.c
branches/soc-2007-joeedh/source/blender/src/interface_draw.c
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-13 01:01:32 UTC (rev 11570)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-08-13 06:42:21 UTC (rev 11571)
@@ -580,7 +580,7 @@
float fac;
if (pointb == pointa) return (interpa + interpb) / 2.0;
- fac = (float)(point-pointa)/(float)(pointb-pointa);
+ fac = (float)((double)(point-pointa)/(double)(pointb-pointa));
return interpa + (interpb - interpa)*fac;
}
#define lerp flerp3i
@@ -671,22 +671,26 @@
//clr = dsm_bsearch(sample, zs, bias);
// &&
for (i=0; i<func->totsamples; i++) {
- if ( zs > (sample[i].depth+bias) ) {
+ //halfway method:
+ //int prev = i==0 ? sample[i].depth : sample[i-1].depth;
+ //if ( zs > ((sample[i].depth>>1) + (prev>>1)) + bias ) {
+ if (zs > sample[i].depth+bias) {
if ( (i != func->totsamples-1 && zs < (sample[i+1].depth+bias)) || i == func->totsamples-1 ) {
- BASSERT(sample[i].clr[3] >= 0);
- BASSERT(sample[i+1].clr[3] >= 0);
-
- BASSERT(sample[i].depth < sample[i+1].depth);
+ BASSERT(sample[i].clr[3] >= -0.0001);
BASSERT(zs > sample[i].depth+bias);
-
- alpha = sample[i].clr[3]; //lerp(sample[i].depth, sample[i+1].depth, zs, sample[i].clr[3], sample[i+1].clr[3]);
+ if (i+1 < func->totsamples) {
+ BASSERT(sample[i+1].clr[3] >= 0);
+ BASSERT(sample[i].depth < sample[i+1].depth);
+ alpha = lerp(sample[i].depth, sample[i+1].depth, zs, sample[i].clr[3], sample[i+1].clr[3]);
+ } else alpha = sample[i].clr[3];
+ //alpha = sample[i].clr[3];
break;
}
}
}
- if (alpha < 0) {
- printf("alpha was less then 0!\n");
+ 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-13 01:01:32 UTC (rev 11570)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c 2007-08-13 06:42:21 UTC (rev 11571)
@@ -3334,6 +3334,7 @@
ListBase *srclist;
int depth;
int p;
+ int ispolygon;
int samplenr;
float clr[4];
} _ClrEntry;
@@ -3349,6 +3350,29 @@
}
+static DSMLayerSample *DSM_CompressFunction(MemArena *arena, DSMFunction *func, float error)
+{
+ DSMLayerSample *sample, *cursample;
+ double slope, threshold[2];
+ int totface, a, b, c;
+
+ sample = BLI_memarena_alloc(arena, sizeof(DSMLayerSample)*func->totsamples);
+ memcpy(sample, func->samples, sizeof(DSMLayerSample)*func->totsamples);
+
+ return sample;
+ /*
+ samp = cursamp = func->samples;
+ for (a=0; a<func->totsamples; a++) {
+ threshold[0] = 1.0f;
+ threshold[1] = -1.0f;
+
+ while (1) {
+
+ }
+
+ }*/
+}
+
static void shade_dsmsample(Render *re, VlakRen *vlr, int facenr, float *diff,
float *screenco, ShadeInput *shi, ShadeResult *shr, ShadBuf *buf)
{
@@ -3428,49 +3452,70 @@
{
DSMFunction *func;
DSMLayerSample *samp;
- _ClrEntry *csamp, nullsamp, nullsamp2, *prev, *cursamp[LA_DEEPBUF_MAXSAMPLES];
+ _ClrEntry *csamp, *prev;
int samplesqr = samplewid*samplewid;
int i, j;
- float accum;
+ double slope, accum, s1, s2;
- nullsamp.depth = 0;
- nullsamp.clr[3] = 1.0f;
- nullsamp.next = &nullsamp2;
- nullsamp.prev = NULL;
-
- nullsamp2.depth = 0x7FFFFFFF;
- nullsamp2.clr[3] = 1.0f;
- nullsamp2.next = NULL;
- nullsamp2.prev = &nullsamp;
-
- for (i=0; i<samplesqr; i++) {
- if (!transfuncs[i].first) cursamp[i] = &nullsamp;
- else cursamp[i] = transfuncs[i].first;
- }
-
- /*for now, just pass the samples through*/
func = BLI_memarena_alloc(arena, sizeof(DSMFunction));
- func->samples = samp = BLI_memarena_alloc(arena, sizeof(DSMLayerSample)*totface);
+ func->samples = samp = scratchmem;
func->totsamples = totface;
-
- accum = 1.0f;
+
+ accum = 1.0;
+ slope = 0.0;
+ samp=func->samples;
for (i=0, csamp=row; i<totface; i++, csamp++, samp++) {
+ /*we've hit an invalid sample*/
+ if (csamp->srclist==NULL) {
+ samp--;
+ i--;
+ printf("skipped sample!\n");
+ continue;
+ }
samp->depth = csamp->depth;
- if (csamp->prev) {
- accum = accum + weight[csamp->samplenr]*(csamp->clr[3] - csamp->prev->clr[3]);
- } else accum = accum + weight[csamp->samplenr]*(csamp->clr[3] - 1.0f);
- if (accum < 0.0f) {
- printf("EVIL!\n");
+ if (G.rt == 1) printf("accum3: %lf\n", accum);
+ if (i != 0) accum = accum + (double)(csamp->depth-(csamp-1)->depth)*slope;
+ samp->clr[3] = (float) accum;
+
+ if (G.rt == 1) printf("accum: %f\n", accum);
+ //samp->clr[3] = 0.0;
+
+ if (csamp->next) {
+ s2 = ((double)(csamp->next->clr[3] - csamp->clr[3])) / (double)(csamp->next->depth - csamp->depth);
+ if (csamp->prev) {
+ s1 = ((double)(csamp->clr[3] - csamp->prev->clr[3])) / (double)(csamp->depth - csamp->prev->depth);
+ slope = slope + weight[csamp->samplenr]*(s2 - s1);
+ } else {
+ slope = slope + weight[csamp->samplenr]*s2;
+ }
+ } else {
+ if (csamp->prev) {
+ s1 = ((double)(csamp->clr[3] - csamp->prev->clr[3])) / (double)(csamp->depth - csamp->prev->depth);
+ slope = slope - weight[csamp->samplenr]*s1;
+ }
+ }
+
+ if (accum < -0.001f) {
+ printf("EVIL! accum: %f\n", accum);
accum = 0.0f;
}
- else if (accum > 1.0f) {
- printf("EVIL 2!\n");
+ else if (accum > 1.001f) {
+ printf("EVIL 2! accum: %f\n", accum);
accum = 1.0f;
}
- samp->clr[3] = accum;
+ if (accum <= 0.0005) {
+ /*this doesn't increment i, which means
+ the current sample is cut out of the range
+ of func->totsamples. which is probably a good thing :)
+ */
+ //break;
+ }
}
+
+ //func->totsamples = i;
+ func->samples = DSM_CompressFunction(arena, func, 0.1);
return func;
}
@@ -3489,11 +3534,11 @@
ListBase rlayers, transfuncs[LA_DEEPBUF_MAXSAMPLES]; /*compress_list is is use
d to combine nearly duplicate samples*/
ListBase apsmbase={NULL, NULL}; //, psm={NULL, NULL};
- _ClrEntry *entry, *row;
+ _ClrEntry *entry, *row, *rowscratch, *row2, *lastsamples[LA_DEEPBUF_MAXSAMPLES];
RenderPart pa;
float accum[LA_DEEPBUF_MAXSAMPLES], co[4], fac, dx, dy;
long *rdrect;
- int x, y, a, b, totface;
+ int x, y, a, b, totface, totface2, mergescratchlen;
int offs= 0, od, rosa, rwinx, rwiny, rrectx, rrecty, totsamp, rpartsdone;
int zthreshold, samp_totlayers[LA_DEEPBUF_MAXSAMPLES], samp_totfaces[LA_DEEPBUF_MAXSAMPLES]; /*threshold for removing duplicate samples in Z per pixel*/
//unsigned short *ztramask= NULL;
@@ -3550,11 +3595,11 @@
pa.rectp = MEM_mapallocN(sizeof(int)*tile->sizex*tile->sizey, "pa.rectz");
pa.rectdaps = MEM_mapallocN(sizeof(long)*tile->sizex*tile->sizey+4, "pa.rectz");
- row = MEM_mapallocN(sizeof(_ClrEntry)*dbuf->max_depth, "_ClrEntry");
+ rowscratch = MEM_mallocN(sizeof(_ClrEntry)*dbuf->max_depth, "_ClrEntry");
/* (comment from template function zbuffer_transp_shade): "looks nicer for calling code" */
if(re->test_break && re->test_break()) {
- MEM_freeN(row);
+ MEM_freeN(rowscratch);
if (pa.rectz) MEM_freeN(pa.rectz);
if (pa.rectp) MEM_freeN(pa.rectp);
if (pa.rectdaps) MEM_freeN(pa.rectdaps);
@@ -3587,7 +3632,7 @@
MEM_freeN(pa.rectdaps);
MEM_freeN(pa.rectp);
freepsA(&apsmbase);
- MEM_freeN(row);
+ MEM_freeN(rowscratch);
re->result = res;
re->r.layers = rlayers;
@@ -3608,7 +3653,8 @@
aprect= APixbuf;
rdrect= pa.rectdaps;
- mergescratch = MEM_mapallocN(sizeof(DSMLayerSample)*dbuf->max_depth, "mergescratch in zbuf.c");
+ mergescratchlen = sizeof(_ClrEntry) > sizeof(DSMLayerSample) ? sizeof(_ClrEntry)*dbuf->max_depth : sizeof(DSMLayerSample)*dbuf->max_depth;
+ mergescratch = row = MEM_mapallocN(mergescratchlen, "mergescratch in zbuf.c");
/* render the tile */
for(y=0; y<pa.recty; y++) {
@@ -3619,52 +3665,99 @@
break;
for(x=0; x<pa.rectx; x++, ap++, od++) {
- //if (!ap->p[0]) printf("ah-oh, apn->p[0] = 0!! eek!!\n");
+ if(ap->p[0] != 0) {
+ row2 = mergescratch;
- if(ap->p[0] != 0) {
/* sort in z */
totface= 0;
apn= ap;
while(apn) {
+ if(totface >= dbuf->max_depth/2 - buf->samp*buf->samp) break;
for(a=0; a<4; a++) {
+ /*we subtract the total number of subpixel samples because we
+ need the space in the array to insert the starting-visibility-
+ at-1 sample in each subpixel visibility function.*/
+ if(totface >= dbuf->max_depth/2 - buf->samp*buf->samp) break;
+
if(apn->p[a]) {
if (apn->z[a] < 0) continue;
+
+ row2[totface].depth = apn->z[a];
+ row2[totface].p = apn->p[a];
+ row2[totface].samplenr = apn->mask[a];
+ row2[totface].ispolygon = 1;
- //printf("p: %d\n", apn->p[a]);
- row[totface].depth = apn->z[a];
- row[totface].p = apn->p[a];
- row[totface].samplenr = apn->mask[a];
-
/*set appropriate pointers to NULL*/
- row[totface].next = row[totface].prev = NULL;
- row[totface].srclist = NULL;
-
+ row2[totface].next = row2[totface].prev = NULL;
+ row2[totface].srclist = NULL;
+
totface++;
- if(totface>=dbuf->max_depth) totface= dbuf->max_depth-1;
+ if(totface >= dbuf->max_depth/2 - buf->samp*buf->samp) break;
}
else break;
}
apn= apn->next;
}
- qsort(row, totface, sizeof(_ClrEntry), dsmvergzvlak);
+ qsort(row2, totface, sizeof(_ClrEntry), dsmvergzvlak);
+ memset(lastsamples, 0, sizeof(void*)*buf->samp*buf->samp);
+
+ /*process the input sample stream, adding "steps" for polygon samples
+ and visibility-of-1.0 header samples before the first sample in subpixel
+ transmittance functions*/
+ row = rowscratch;
+ b = totface;
+ totface = 0;
+ for (a=0; a<b; a++) {
+ if (lastsamples[row2[a].samplenr] && lastsamples[row2[a].samplenr]->ispolygon) {
+ /*add polygon "step" to the transmittance function*/
+ row[totface] = *lastsamples[row2[a].samplenr];
+ row[totface].depth = row2[a].depth - 1;
+ if (row[totface].depth < 0) row[totface].depth = 0;
+ totface++;
+ } else {
+ /*add vis of 1.0 header sample to transmittance function*/
+ row[totface].p = 0;
+ row[totface].samplenr = row2[a].samplenr;
+ row[totface].next = row[totface].prev = row[totface].srclist = NULL;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list