[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12489] branches/soc-2007-joeedh/source/ blender: Pre-merge commit.
Joseph Eagar
joeedh at gmail.com
Tue Nov 6 03:34:53 CET 2007
Revision: 12489
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12489
Author: joeedh
Date: 2007-11-06 03:34:53 +0100 (Tue, 06 Nov 2007)
Log Message:
-----------
Pre-merge commit.
New plan for DSM: sideline soft shadow code for now (its EVIL!!!) and try and get
it basically working with no bugs. Also sideline attempts to balance memory
stuff; I know what I have to do there, but I'm sick and tired of working on that
too.
Commit also includes modified file selector code I have in all my builds.
Joe
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.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
branches/soc-2007-joeedh/source/blender/src/filesel.c
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c 2007-11-06 02:30:53 UTC (rev 12488)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_image.c 2007-11-06 02:34:53 UTC (rev 12489)
@@ -23,8 +23,42 @@
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
-
+
#if 0
+typedef struct ImageTile {
+ TCS_Tile tile;
+ union {
+ char c[];
+ float f[];
+ } img;
+} ImageTile;
+
+typedef struct ImageBuffer {
+ TCS_TileBuffer buffer;
+ ImageTile *tiles;
+ int sizex, sizey;
+ short flags, type;
+ int totchannels;
+} ImageBuffer;
+
+#define IM_TILESIZE 32
+#define IM_NUMLEVELS 4
+
+typedef struct ImagePyramid {
+ ImageBuffer levels[IM_NUMLEVELS];
+} ImagePyramid;
+
+/* mode is color ramp modes like mix, add, subtract, multiply, screen, overlay, etc.
+ this function will blit onto the proper mipmap level, and queue the rest for updating,*/
+void TCS_BlitToImage(ImageBuffer *image, void *image2, int sizex, int sizey,
+ int final_sizex, int final_size y, int x, int y, int srcx,
+ int srcy, int mode, int workinglevel)
+
+#define IM_TYPE_FLOAT 0
+#define IM_TYPE_BYTE 1
+
+#endif
+#if 0
/*Image buffer implementation*/
#define TYPE_UBYTE1 0
@@ -71,7 +105,7 @@
case TYPE_UBYTE1:\
{\
char *_bclr = GETARRAY_PIXPTR(width, x, y, arr, char, 1);\
- _clr[0] = (float)*_bclr;\
+ _clr[0] = float)_bclr[0]/255.0f;;\
_clr[1] = _clr[0];\
_clr[2] = _clr[0];\
_clr[3] = 1.0;\
@@ -118,6 +152,7 @@
} ImageTile;
struct ImBuf;
+
typedef struct ImageBuffer {
TCS_TileBuffer buf;
struct ImBuf *imbuf;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2007-11-06 02:30:53 UTC (rev 12488)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2007-11-06 02:34:53 UTC (rev 12489)
@@ -395,7 +395,7 @@
buf->dsmbuffer = dbuf;
- if (G.rt==44) *((int*)0L) = 0;
+ //if (G.rt==44) *((int*)0L) = 0;
for (y=0; y<dbuf->tiley; y++) {
for (x=0; x<dbuf->tilex; x++) {
@@ -1402,6 +1402,12 @@
rayend[0] *= (float)shb->soft/10.0f;
rayend[1] *= (float)shb->soft/10.0f;
rayend[3] = 1.0f;
+
+ printf("[%f, %f, %f, %f]", shb->winmat[0][0], shb->winmat[0][1], shb->winmat[0][2], shb->winmat[0][3]);
+ printf("[%f, %f, %f, %f]", shb->winmat[1][0], shb->winmat[1][1], shb->winmat[1][2], shb->winmat[1][3]);
+ printf("[%f, %f, %f, %f]", shb->winmat[2][0], shb->winmat[2][1], shb->winmat[2][2], shb->winmat[2][3]);
+ printf("[%f, %f, %f, %f]", shb->winmat[3][0], shb->winmat[3][1], shb->winmat[3][2], shb->winmat[3][3]);
+ //*((int*)0L) = 1;
QUATCOPY(raystart2, raystart);
printf("unprojected lamp_raystart: [%f, %f, %f]\n", rco[0], rco[1], rco[2]);
@@ -1410,7 +1416,7 @@
printf("pre-rayend: [%f, %f, %f, %f]\n", rayend[0], rayend[1], rayend[2], rayend[3]);
/*clip with clipstart, add small value to avoid possible numeric error*/
- VecClipLine3f(lamp_raystart, rayend, 2, shb->clipsta+0.001f)); //0.001f);
+ VecClipLine3f(lamp_raystart, rayend, 2, shb->clipsta+0.001f); //0.001f);
printf("post-rayend: [%f, %f, %f, %f]\n", rayend[0], rayend[1], rayend[2], rayend[3]);
/*project rayend into lamp screen space*/
@@ -1622,3 +1628,219 @@
return 1;
}
/* ------ end static code from zbuf.c ------ */
+
+/********** Deep shadow maps ************/
+#ifdef lerp
+#undef lerp
+#endif
+
+/*noramlized lerp*/
+//#define nlerp(a, b, percentage) ((a) + ((b) - (a))*(percentage))
+
+/*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, double interpa, double interpb)
+{
+ double fac;
+ if (pointb == pointa) return (interpa + interpb) / 2.0;
+
+ fac = (double)(point-pointa)/(double)(pointb-pointa);
+ return interpa + (interpb - interpa)*fac;
+}
+#define lerp flerp3i
+
+//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, int component)
+{
+ //ShadSampleBuf *shsample;
+ DSMTile *tile = NULL;
+ DSMBuffer *buf = shb->dsmbuffer;
+ DSMLayerSample *sample;
+ 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, newbias, tilex, tiley, i;
+
+ if (!shb->dsmbuffer) {
+ printf("Bug in code: No DSM Buffer! Please file a bug report at\n");
+ printf("projects.blender.org, including sample .blend, and assign it to\n");
+ printf("Joe Eagar.\n");
+ //G.afbreek = 1; /*stop rendering*/
+ return 1.0f;
+ }
+
+ if(inp <= 0.0f) return 0.0f;
+
+ /* rotate renderco en osaco */
+ siz= 0.5f*(float)shb->size;
+
+ VECCOPY(co, rco);
+ co[3]= 1.0f;
+
+ MTC_Mat4MulVec4fl(shb->persmat, co); /* rational hom co */
+
+ 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. */
+ fac= (co[2]/co[3]);
+
+ if(fac>=1.0f) {
+ return 0.0f;
+ } else if(fac<= -1.0f) {
+ return 1.0f;
+ }
+
+ zs= ((float)0x7FFFFFFF)*fac;
+
+ /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors
+ on cube edges, with one side being almost frontal lighted (ton) */
+ bias= (1.5f-inp*inp)*shb->bias;
+
+ if (xs >= buf->sizex || xs < 0) {
+ return 1.0;
+ }
+
+ if (ys >= buf->sizey || ys < 0) {
+ return 1.0;
+ }
+
+ tilex = xs/buf->tsizex;
+ tiley = ys/buf->tsizey;
+
+ if (tilex >= buf->tilex || tiley >= buf->tiley || tilex < 0 || tiley < 0) return 1.0;
+
+ tile = TCS_GetAndLockTile((TCS_TileBuffer*)buf, tilex, tiley, 0); //&buf->vfunc_rect[tiley*buf->tilex+tilex];
+
+ BASSERT(tile);
+ if (!tile) return 1.0;
+
+ xs = xs % buf->tsizex;
+ ys = ys % buf->tsizey;
+
+ 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) {
+ /*re-enabled caching for the tile*/
+ TCS_UnlockTile(tile);
+ return 1.0;
+ }
+
+ sample = func->samples;
+
+ alpha = 1.0;
+
+ /*this check taken from testshadowbuf*/
+ if(zs < - 0x7FFFFE00 + bias) { /* extreme close to clipstart */
+ /*re-enable caching for the tile*/
+ TCS_UnlockTile(tile);
+ return 1.0;
+ }
+
+ newbias = bias;
+
+ for (i=0; i<func->totsamples; i++) {
+ if (zs > sample[i].depth+newbias) {
+ if (i != func->totsamples-1) {
+ if (zs < sample[i+1].depth+newbias) {
+ BASSERT(sample[i].depth < sample[i+1].depth);
+ alpha = lerp(sample[i].depth+newbias, sample[i+1].depth+newbias, 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);
+
+ if (alpha < -0.0001) {
+ printf("alpha was less then 0! it was %f\n", alpha);
+ alpha = 0.0;
+ }
+
+ /*re-enable caching for the tile*/
+ TCS_UnlockTile(tile);
+
+ return alpha;
+}
+
+#if 0
+float *dsm_bsearch(DSMSample *sample, int zs, int bias)
+{
+ int len = sample[0].depth, curpos = len/2, curlen=(((float)len/2.0)+0.5);
+ int pos=0, pos2=0, i;
+ float *clr = NULL;
+
+ sample++;
+
+ while (1) {
+ if (curlen==1||curlen==0) break;
+
+ /*round midpoints.*/
+ pos = ((float)curpos + (float)curlen/2.0)+0.5;
+ pos2 = ((float)curpos - (float)curlen/2.0)+0.5;
+
+ if (ABS(zs-(sample[pos].depth+bias)) < ABS(zs-(sample[pos2].depth+bias))) curpos = pos;
+ else curpos = pos2;
+
+ curlen /= 2.0;
+ }
+
+ if (curpos > G.rt) curpos -= G.rt;
+ else curpos = 0;
+ //curpos = 0;
+
+ for (i=curpos; i<len; i++) {
+ if (zs < sample[i].depth+bias) break;
+ clr = sample[i].clr;
+ }
+ //return sample[curpos].clr;
+
+
+ #if 0
+ /*situation cuspos+1, zs, curpos then curpos-1, zs, curplus*/
+ if (zs > sample[curpos].depth+bias) {
+ return sample[curpos].clr;
+ } else if (curpos != 0) { //return sample[curpos-1].clr; //if (zs < sample[curpos].depth+bias && curpos != len - 1) {
+ //return sample[curpos-1].clr;
+ for (i=curpos-1; i>0; i--) {
+ if (zs > sample[i].depth+bias) return sample[i].clr;
+ }
+ return sample[i].clr;
+ }
+ #endif
+
+ return clr;
+}
+#endif
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-11-06 02:30:53 UTC (rev 12488)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-11-06 02:34:53 UTC (rev 12489)
@@ -424,9 +424,14 @@
/* printf("lampbuf %d\n", sizeoflampbuf(shb)); */
} else if (lar->buftype == LA_SHADBUF_DEEP) {
+ int oldsamp = shb->samp;
+
R = *re;
- shb->jit= give_jitter_tab(shb->samp);
+ shb->jit= give_jitter_tab(DSM_AASAMPLES);
+
+ shb->samp = DSM_AASAMPLES;
make_jitter_weight_tab(shb, lar->filtertype);
+ shb->samp = oldsamp;
/* temp, will be restored */
MTC_Mat4SwapMat4(shb->persmat, re->winmat);
@@ -566,224 +571,6 @@
}
-/********** Deep shadow maps ************/
-#ifdef lerp
-#undef lerp
-#endif
-
-/*noramlized lerp*/
-//#define nlerp(a, b, percentage) ((a) + ((b) - (a))*(percentage))
-
-/*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, double interpa, double interpb)
-{
- double fac;
- if (pointb == pointa) return (interpa + interpb) / 2.0;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list