[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11650] branches/soc-2007-joeedh/source/ blender: Ok, the basic volumetric structures for DSM finally all work.
Joseph Eagar
joeedh at gmail.com
Sat Aug 18 06:42:53 CEST 2007
Revision: 11650
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11650
Author: joeedh
Date: 2007-08-18 06:42:53 +0200 (Sat, 18 Aug 2007)
Log Message:
-----------
Ok, the basic volumetric structures for DSM finally all work. Theres three
visibility functions per pixel, which define r, g, b values.
Also I have basic colors working (but textures arn't taken into account) although theres still some sort of bug, and I highly doubt ray transp will give correct results (I had to do some modifications to the shadow code, and I still need to update it; basically shadows were being defined as a 4-component value when they should've been 3-component).
Now on to the tiling cache system, after I get a few people to do some tests.
Joe
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c
branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
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/shadeoutput.c
branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2007-08-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2007-08-18 04:42:53 UTC (rev 11650)
@@ -6,7 +6,7 @@
struct MemArena;
typedef struct DSMLayerSample {
- float clr[4];
+ float value;
int depth;
/*original number of samples between this layer and the previous one.*/
@@ -19,6 +19,8 @@
is the total number of samples going from light
energy 1.0 to 0.0, then repeating.*/
typedef struct DSMFunction {
+ /*don't forget to implement calculating zmin and zmax for
+ MTSM!*/
int totsamples, zmin, zmax;
/*consequtive array of samples*/
@@ -40,6 +42,10 @@
typedef struct DSMTile {
TCS_Tile tile;
DSMFunction **layer_rect;
+
+ DSMFunction **r_rect;
+ DSMFunction **g_rect;
+ DSMFunction **b_rect;
//DSMLayerSample **sample_rect; /*first entry's depth is the length of the pixel array*/
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-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c 2007-08-18 04:42:53 UTC (rev 11650)
@@ -101,10 +101,10 @@
TCS_fread(&sample->depth, sizeof(int), 1, file);
TCS_fread(sclr, sizeof(unsigned short), 4, file);
- sample->clr[0] = ((float)sclr[0]) / 65535.0f;
+ /*sample->clr[0] = ((float)sclr[0]) / 65535.0f;
sample->clr[1] = ((float)sclr[1]) / 65535.0f;
sample->clr[2] = ((float)sclr[2]) / 65535.0f;
- sample->clr[3] = ((float)sclr[3]) / 65535.0f;
+ sample->clr[3] = ((float)sclr[3]) / 65535.0f;*/
}
}
}
@@ -150,10 +150,10 @@
TCS_fwrite(&first->depth, sizeof(int), 1, file);
for (j=0; j < first->depth; j++, sample++) {
- PACK_SHORTFLOAT(sclr[0], sample->clr[0]);
+ /*PACK_SHORTFLOAT(sclr[0], sample->clr[0]);
PACK_SHORTFLOAT(sclr[1], sample->clr[1]);
PACK_SHORTFLOAT(sclr[2], sample->clr[2]);
- PACK_SHORTFLOAT(sclr[3], sample->clr[3]);
+ PACK_SHORTFLOAT(sclr[3], sample->clr[3]);*/
TCS_fwrite(&sample->depth, sizeof(int), 1, file);
TCS_fwrite(sclr, sizeof(short), 4, file);
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h 2007-08-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h 2007-08-18 04:42:53 UTC (rev 11650)
@@ -73,7 +73,7 @@
* Deep Shadow Buffer
*/
-float DSM_getShadow(ShadBuf *buf, float *rco, float *dxco, float *dyco, float inp);
+float DSM_getShadow(ShadBuf *buf, float *rco, float *dxco, float *dyco, float inp, int component);
void DSM_CreateBuffer(Render *re, ShadBuf *buf, int tilesize);
void DSM_FreeBuffer(DSMBuffer *dbuf);
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-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/rayshade.c 2007-08-18 04:42:53 UTC (rev 11650)
@@ -315,7 +315,7 @@
{
float dx, dy, dz, d, p;
- if (0 == (shi->mat->mode & (MA_RAYTRANSP|MA_ZTRA)))
+ if ((shi->mat->mode & (MA_RAYTRANSP|MA_ZTRA)) == 0)
return -1;
if (shi->mat->tx_limit <= 0.0f) {
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-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-08-18 04:42:53 UTC (rev 11650)
@@ -575,12 +575,12 @@
/*lerp*/
//#define lerp(pointa, pointb, point, interpa, interpb) ((pointa)==(pointb) ? ((interpa)+(interpb))/2.0 : nlerp( interpa, interpb, (float)((point)-(pointa))/(float)((pointb)-(pointa)) ))
-float flerp3i(int pointa, int pointb, int point, float interpa, float interpb)
+float flerp3i(int pointa, int pointb, int point, double interpa, double interpb)
{
- float fac;
+ double fac;
if (pointb == pointa) return (interpa + interpb) / 2.0;
- fac = (float)((double)(point-pointa)/(double)(pointb-pointa));
+ fac = (double)(point-pointa)/(double)(pointb-pointa);
return interpa + (interpb - interpa)*fac;
}
#define lerp flerp3i
@@ -588,7 +588,7 @@
//float *dsm_bsearch(DSMSample *sample, int zs, int bias);
/* return 1.0: no shadow at all */
-float DSM_getShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp)
+float DSM_getShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, int component)
{
//ShadSampleBuf *shsample;
DSMTile *tile = NULL;
@@ -660,8 +660,23 @@
ys = ys % buf->tsizey;
//printf("2: xs: %d, ys: %d, zs: %d\n", xs, ys, zs);
- func = tile->layer_rect[ys*tile->sizex+xs];
+
+ switch (component) {
+ case 0:
+ func = tile->r_rect[ys*tile->sizex+xs];
+ break;
+ case 1:
+ func = tile->g_rect[ys*tile->sizex+xs];
+ break;
+ case 2:
+ func = tile->b_rect[ys*tile->sizex+xs];
+ break;
+ default:
+ printf("bad component value for dsm_getshadow!\n");
+ return 1.0f;
+ }
+
if (!func || !func->totsamples || !func->samples) return 1.0;
sample = func->samples;
@@ -670,29 +685,23 @@
bias=bias/6.0; //odd that I have to do this :/
//clr = dsm_bsearch(sample, zs, bias);
// &&
+ //printf("func->totsamples: %d\n", func->totsamples);
for (i=0; i<func->totsamples; i++) {
- //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) {
- //another attempt at halfway depth method:
- //int depth = i < func->totsamples-1 ? sample[i].depth>>1+sample[i+1].depth>>1 : i!=func->totsamples-1?sample[i+1].depth:0;
- if ( (i != func->totsamples-1 && zs < (sample[i+1].depth+bias)) || i == func->totsamples-1 ) {
- BASSERT(sample[i].clr[3] >= -0.00001);
- if (sample[i+1].clr[3] <= -0.00001) printf("alpha < 0! %f\n", (float)sample[i+1].clr[3]);
- BASSERT(zs > sample[i].depth+bias);
- if (i+1 < func->totsamples) {
- BASSERT(sample[i+1].clr[3] >= 0);
- if (sample[i+1].clr[3] <= -0.00001) printf("alpha < 0! %f\n", (float)sample[i+1].clr[3]);
+ if (i != func->totsamples-1) {
+ if (zs < sample[i+1].depth+bias) {
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;
+ alpha = lerp(sample[i].depth+bias, sample[i+1].depth+bias, zs, sample[i].value, sample[i+1].value);
+ break;
+ }
+ } else {
+ alpha = sample[i].value;
}
- }
+ } else break;
}
-
+
+ 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/shadeoutput.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/shadeoutput.c 2007-08-18 04:03:03 UTC (rev 11649)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadeoutput.c 2007-08-18 04:42:53 UTC (rev 11650)
@@ -1002,6 +1002,9 @@
diff[0]= diff[1]= diff[2]= 0.0f;
}
+#define MIN2(a, b) ((a) < (b) ? (a) : (b))
+#define MIN3(a, b, c) MIN2(MIN2(a, b), c)
+
/* result written in shadfac */
void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float *shadfac, int do_real)
{
@@ -1009,29 +1012,33 @@
if(do_real || lss->samplenr!=shi->samplenr) {
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f;
+ shadfac[0]= shadfac[1]= shadfac[2]= 1.0f;
if(lar->shb) {
if(lar->buftype==LA_SHADBUF_IRREGULAR) {
- shadfac[3]= ISB_getshadow(shi, lar->shb);
+ shadfac[0] = shadfac[1] = shadfac[2] = ISB_getshadow(shi, lar->shb);
} else if (lar->buftype==LA_SHADBUF_DEEP) {
- shadfac[3] = DSM_getShadow(lar->shb, shi->co, shi->dxco, shi->dyco, inp);
+ shadfac[0] = DSM_getShadow(lar->shb, shi->co, shi->dxco, shi->dyco, inp, 0);
+ shadfac[1] = DSM_getShadow(lar->shb, shi->co, shi->dxco, shi->dyco, inp, 1);
+ shadfac[2] = DSM_getShadow(lar->shb, shi->co, shi->dxco, shi->dyco, inp, 2);
} else
- shadfac[3] = testshadowbuf(lar->shb, shi->co, shi->dxco, shi->dyco, inp);
+ shadfac[0] = shadfac[1] = shadfac[2] = testshadowbuf(lar->shb, shi->co, shi->dxco, shi->dyco, inp);
}
else if(lar->mode & LA_SHAD_RAY) {
ray_shadow(shi, lar, shadfac);
}
if(shi->depth==0) {
- QUATCOPY(lss->shadfac, shadfac);
+ VECCOPY(lss->shadfac, shadfac);
lss->samplenr= shi->samplenr;
}
}
else {
- QUATCOPY(shadfac, lss->shadfac);
+ VECCOPY(shadfac, lss->shadfac);
}
}
+#undef MIN2;
+#undef MIN3;
/* lampdistance and spot angle, writes in lv and dist */
float lamp_get_visibility(LampRen *lar, float *co, float *lv, float *dist)
@@ -1124,7 +1131,7 @@
{
Material *ma= shi->mat;
VlakRen *vlr= shi->vlr;
- float lv[3], lampdist, lacol[3], shadfac[4];
+ float lv[3], lampdist, lacol[3], shadfac[3], shadaver;
float i, is, i_noshad, inp, *vn, *view, vnor[3], phongcorr=1.0f;
float visifac;
@@ -1231,9 +1238,11 @@
if(ma->mode & MA_TANGENT_V)
vn= shi->tang;
- /* init transp shadow */
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f;
-
+ /* init transp shadow. shadfac now only has three components */
+ shadfac[0]= shadfac[1]= shadfac[2]= 1.0f;
+ /*average of the three shadow components*/
+ shadaver = 1.0;
+
/* shadow and spec, (visifac==0 outside spot) */
if(visifac> 0.0f) {
@@ -1245,22 +1254,26 @@
lamp_get_shadow(lar, shi, INPR(shi->vn, lv), shadfac, shi->depth);
else
lamp_get_shadow(lar, shi, inp, shadfac, shi->depth);
-
+
+ shadaver = (shadfac[0]+shadfac[1]+shadfac[2]) / 3.0f;
+
/* warning, here it skips the loop */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list