[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13164] branches/soc-2007-joeedh/source/ blender/render/intern/source/dsm.c: Several algorithmic bugs have been fixed.
Joseph Eagar
joeedh at gmail.com
Tue Jan 8 01:49:33 CET 2008
Revision: 13164
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13164
Author: joeedh
Date: 2008-01-08 01:49:33 +0100 (Tue, 08 Jan 2008)
Log Message:
-----------
Several algorithmic bugs have been fixed. Main issue now is some
sort of color accumulation problem. I've hacked it to be better,
and it kindof works.
Next step I either try and fix the color accumulation problem or
I merge with trunk to integrate the new strand renderer.
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-01-07 19:38:01 UTC (rev 13163)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-01-08 00:49:33 UTC (rev 13164)
@@ -497,11 +497,27 @@
{
DSMLayerSample *samp = func->samples, *cursamp, *newsamp;
/*start and end are slopes*/
- double start, end, ostartpoint, oendpoint, startpoint = -1, endpoint = -1, err=error/2.0;
- int totface=0, a=0, olda, count=0;
+ double start, end, ostartpoint, oendpoint, startpoint = -1, endpoint = -1, err=error; ///2.0;
+ int totface=0, a=0, count=0;
cursamp = func->samples;
-
+
+ #define WRITETESTFILE
+ #ifdef WRITETESTFILE
+ #define DSMTESTFILE "densityfuncs.txt"
+ if (G.rt==63) {
+ FILE *file = fopen(DSMTESTFILE, "ab");
+ int i;
+
+ if (!file) return;
+ fprintf(file, "numsamples-noncomp: %d\n", func->totsamples);
+ for (i=0; i<func->totsamples; i++) {
+ fprintf(file, "sample: %d %f %d\n", func->samples[i].depth, func->samples[i].value, func->samples[i].orig_totsamples);
+ }
+ fclose(file);
+ }
+ #endif
+
if (G.rt == 43) {
cursamp = BLI_memarena_alloc(arena, sizeof(DSMLayerSample)*func->totsamples);
memcpy(cursamp, func->samples, sizeof(DSMLayerSample)*func->totsamples);
@@ -534,25 +550,25 @@
}
a += 1;
- olda = a;
while (a < func->totsamples) {
ostartpoint = startpoint;
oendpoint = endpoint;
if (samp[a].depth == cursamp->depth) {
- startpoint = cursamp->value + err;
- endpoint = cursamp->value - err;
+ //startpoint = cursamp->value + err;
+ //endpoint = cursamp->value - err;
+ break;
} else {
startpoint = cursamp->value + start * (double)(samp[a].depth - cursamp->depth);
endpoint = cursamp->value + end * (double)(samp[a].depth - cursamp->depth);
}
if (startpoint > samp[a].value && endpoint < samp[a].value) {
- if (startpoint > samp[a].value) {
+ if (startpoint > samp[a].value+err) {
start = (samp[a].value+err) - cursamp->value;
if (samp[a].depth != cursamp->depth) {
start /= (double)(samp[a].depth - cursamp->depth);
}
}
- if (endpoint < samp[a].value) {
+ if (endpoint < samp[a].value-err) {
end = (samp[a].value-err) - cursamp->value;
if (samp[a].depth != cursamp->depth) {
end /= (double)(samp[a].depth - cursamp->depth);
@@ -562,8 +578,7 @@
a -= 1;
break;
}
- olda -= a;
-
+
cursamp->orig_totsamples++;
a += 1;
}
@@ -583,6 +598,22 @@
func->totsamples = totface;
func->samples = newsamp;
+
+ #define WRITETESTFILE
+ #ifdef WRITETESTFILE
+ #define DSMTESTFILE "densityfuncs.txt"
+ if (G.rt==63) {
+ FILE *file = fopen(DSMTESTFILE, "ab");
+ int i;
+
+ if (!file) return;
+ fprintf(file, "numsamples: %d\n", func->totsamples);
+ for (i=0; i<func->totsamples; i++) {
+ fprintf(file, "sample: %d %f %d\n", func->samples[i].depth, func->samples[i].value, func->samples[i].orig_totsamples);
+ }
+ fclose(file);
+ }
+ #endif
}
static void shade_dsmsample(Render *re, VlakRen *vlr, int facenr, float *diff,
@@ -666,7 +697,7 @@
DSMFunction *func;
DSMLayerSample *samp;
_ClrEntry *csamp, *lastcsamp=NULL;
- double slope, accum, lastaccum[LA_DEEPBUF_MAXSAMPLES], s1, s2;
+ double slope, accum, s1, s2;
int samplesqr = samplewid*samplewid;
int i;
@@ -676,8 +707,6 @@
func->zmin = 0x7FFFFFFF;
func->zmax = -0x7FFFFFFF;
- for (i=0; i<samplesqr; i++) lastaccum[i] = -1;
-
accum = 1.0;
slope = 0.0;
samp=func->samples;
@@ -691,6 +720,7 @@
continue;
}
+ samp->orig_totsamples = 0;
samp->depth = csamp->depth;
if (samp->depth > func->zmax) func->zmax = samp->depth;
if (samp->depth < func->zmin) func->zmin = samp->depth;
@@ -771,7 +801,7 @@
RenderPart pa;
float accum[LA_DEEPBUF_MAXSAMPLES][3], co[4];
long *rdrect;
- int x, y, a, b, c, totface;
+ int x, y, a, b, c, d, totface;
int offs= 0, od, rwinx, rwiny, rrectx, rrecty, rpartsdone;
int samp_totfaces[LA_DEEPBUF_MAXSAMPLES]; /*threshold for removing duplicate samples in Z per pixel*/
int samp_totlayers[LA_DEEPBUF_MAXLAYERS][3];
@@ -908,12 +938,12 @@
2 (since polygon samples are doubled) * 3 (since all samples are tripled for
the different r, g, b visibility functions)
*/
- if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
+ if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES*2) 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/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
+ need the space in the array to insert the 2 starting-visibility-
+ at-1 samples in each subpixel visibility function.*/
+ if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES*2) break;
if(apn->p[a]) {
float zco;
@@ -943,7 +973,7 @@
row2[totface].value = 0.0f;
totface++;
- if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES) break;
+ if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES*2) break;
}
else break;
}
@@ -964,8 +994,12 @@
an extra anyway for the final step in processing the visibility functions).
annoyingly, we have to duplicate each sample three times for
- colored shadows
-
+ colored shadows.
+
+ note the sample order follows a r-sample, g-sample, b-sample, (repeat)
+ component order.
+
+ ignore the next paragraph:
one note, while I did manage to get the visibility function
merging function to work with vertical steps in the input
functions, theres still some annoying bug with that causing
@@ -975,6 +1009,23 @@
row = rowscratch;
b = totface;
totface = 0;
+
+ /*add the first header samples, which are at -0x7FFFFFF z and
+ have a visibility of 1.0f.*/
+ for (d=0; d<shb->samp*shb->samp; d++) {
+ for (a=0; a<3; a++) {
+ row[totface].p = -1;
+ row[totface].value = 1.0f;
+ row[totface].index = a;
+ row[totface].ispolygon = 0;
+ row[totface].samplenr = d;
+ row[totface].depth = -0x7FFFFFFF;
+ row[totface].next = row[totface].prev = NULL;
+ row[totface].srclist = NULL;
+ totface++;
+ }
+ }
+
for (a=0; a<b; a++) {
if (lastsamples[row2[a].samplenr]) {
/*add polygon "step" to the transmittance function,
@@ -984,7 +1035,7 @@
for (c=0; c<3; c++) {
row[totface] = *lastsamples[row2[a].samplenr];
row[totface].index = c;
- row[totface].depth = row2[a].depth - 3;
+ row[totface].depth = row2[a].depth;
row[totface].next = row[totface].prev = NULL;
row[totface].srclist = NULL;
@@ -992,7 +1043,7 @@
}
}
} else {
- /*add visibility of 1.0 header sample to transmittance function.
+ /*add the second visibility of 1.0 header sample to transmittance function.
actual visibility value is set in a later loop*/
for (c=0; c<3; c++) {
row[totface].p = -1;
@@ -1000,7 +1051,7 @@
row[totface].index = c;
row[totface].ispolygon = 0;
row[totface].samplenr = row2[a].samplenr;
- row[totface].depth = row2[a].depth - 3;
+ row[totface].depth = row2[a].depth;
row[totface].next = row[totface].prev = NULL;
row[totface].srclist = NULL;
@@ -1053,7 +1104,8 @@
if (accum[row[a].samplenr][0] > 0.001 || accum[row[a].samplenr][1] > 0.001 || accum[row[a].samplenr][2] > 0.001) {
float clr[4];
- /*first sample is always fully out of shadow.*/
+ /*first two samples are always fully out of shadow and are flagged with
+ .p being -1.*/
if (row[a].p == -1) {
row[a].value = 1.0f;
BASSERT(row[a].index >= 0 && row[a].index <= 3);
@@ -1094,12 +1146,12 @@
//if (G.rt == 1) printf("accum2: %f\n", accum[row[a].samplenr]);
- if (row[a].ispolygon) {
- clr[3] /= 2.0f;
+ /*if (row[a].ispolygon) {
+ //clr[3] /= 2.0f;
//clr[2] *= 2.0f;
//clr[1] *= 2.0f;
//clr[0] *= 2.0f;
- }
+ }*/
//clr[3] *= 2.0;
for (b=0; b<3; b++) {
@@ -1113,9 +1165,9 @@
/*this stuff taken from rayshade.c code*/
fac= 1.0f + vlak->mat->filter*(clr[b]-1.0f);
accum[row[a].samplenr][b] = clr[3]*clr[b] + fac*(1.0f-clr[3])*accum[row[a].samplenr][b];
- accum[row[a].samplenr][b] *= 1.0f - clr[3];
+ accum[row[a].samplenr][b] *= (1.0f - clr[3])*1.2; //((float)G.rt/500.0f);
- //accum[row[a].samplenr][b] = clr[b]*(1.0f - clr[3]*2.0);
+ //accum[row[a].samplenr][b] *= (1.0f - clr[3])*((float)G.rt/500.0f); //clr[b]*(1.0f - clr[3]*2.0);
row[a].value = accum[row[a].samplenr][b];
@@ -1136,13 +1188,13 @@
together*/
tile->r_rect[y*tile->sizex+x] = DSM_MergeLayerList(tile->arena, row, transfuncs, totface,
- mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.2f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 0);
+ mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.13f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 0);
tile->g_rect[y*tile->sizex+x] = DSM_MergeLayerList(tile->arena, row, transfuncs, totface,
- mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.2f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 1);
+ mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.13f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 1);
tile->b_rect[y*tile->sizex+x] = DSM_MergeLayerList(tile->arena, row, transfuncs, totface,
- mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.2f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 2);
+ mergescratch, mergescratchlen, shb->weight, DSM_AASAMPLES, 0.13f/sqrt(DSM_AASAMPLES*DSM_AASAMPLES), 2);
}
}
More information about the Bf-blender-cvs
mailing list