[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11337] branches/soc-2007-joeedh/source/ blender: commit of code, nothing works yet still.
Joseph Eagar
joeedh at gmail.com
Sun Jul 22 21:06:34 CEST 2007
Revision: 11337
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11337
Author: joeedh
Date: 2007-07-22 21:06:34 +0200 (Sun, 22 Jul 2007)
Log Message:
-----------
commit of code, nothing works yet still.
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/blenlib/intern/util.c
branches/soc-2007-joeedh/source/blender/makesdna/DNA_lamp_types.h
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/blenlib/intern/util.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenlib/intern/util.c 2007-07-22 17:02:42 UTC (rev 11336)
+++ branches/soc-2007-joeedh/source/blender/blenlib/intern/util.c 2007-07-22 19:06:34 UTC (rev 11337)
@@ -1558,17 +1558,19 @@
/**/
-
/* Special quick-sort that deals with keeping an array cell's entry in
a linked list consistent. This is for if you're sorting an array,
whose cells exist in linked lists, and you want to preserve the original
lists while sorting.*/
#define _MEMCPY(a, b, len) {\
- char *_a = (char*)(a), *_b = (char*)(b); int _len = (len);\
- for (; _len>0; _len--) *_a = *_b;\
-}
+ char *_c = (char*)(a), *_d = (char*)b;\
+ unsigned int _i;\
+ for (_i=(len); _i>0; _i--) *_c++ = *_d++; }
+
+//#define _MEMCPY(a, b, len) memcpy(a, b, len);
+
typedef struct LinkExtraHeader {
struct LinkExtraHeader *next, *prev;
ListBase *list;
@@ -1590,8 +1592,7 @@
}\
_MEMCPY(scratch, a, len)\
_MEMCPY(a, b, len)\
- _MEMCPY(b, scratch, len)\
-}
+ _MEMCPY(b, scratch, len) }
static void bli_qsort_recurse(char *scratch, void *array1, int left, int right, int elemsize, int (*comparitor)(const void *a1, const void *a2))
{
@@ -1625,4 +1626,4 @@
bli_qsort_recurse(working_mem, array1, 0, len-1, elemsize, comparitor);
if (elemsize > 8096) free(working_mem);
-}
+}
\ No newline at end of file
Modified: branches/soc-2007-joeedh/source/blender/makesdna/DNA_lamp_types.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/makesdna/DNA_lamp_types.h 2007-07-22 17:02:42 UTC (rev 11336)
+++ branches/soc-2007-joeedh/source/blender/makesdna/DNA_lamp_types.h 2007-07-22 19:06:34 UTC (rev 11337)
@@ -121,8 +121,8 @@
#define LA_SHADBUF_MAXSAMPLEWID 16
#define LA_SHADBUF_MAXSAMPLES 256
-#define LA_DEEPBUF_MAXSAMPLEWID 5
-#define LA_DEEPBUF_MAXSAMPLES 25
+#define LA_DEEPBUF_MAXSAMPLEWID 16
+#define LA_DEEPBUF_MAXSAMPLES 256
/* bufflag, auto clipping */
#define LA_SHADBUF_AUTO_START 1
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-07-22 17:02:42 UTC (rev 11336)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c 2007-07-22 19:06:34 UTC (rev 11337)
@@ -569,11 +569,21 @@
#endif
/*noramlized lerp*/
-#define nlerp(a, b, percentage) ((a) + ((b) - (a))*(percentage))
+//#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)) ))
+//#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 fac;
+ if (pointb == pointa) return (interpa + interpb) / 2.0;
+
+ fac = (float)(point-pointa)/(float)(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 */
@@ -660,15 +670,24 @@
//clr = dsm_bsearch(sample, zs, bias);
for (i=0; i<func->totsamples-1; i++) {
- if (zs < sample[i+1].depth+bias) {
+ if (zs < sample[i+1].depth+bias && zs > sample[i].depth+bias) {
+ BASSERT(sample[i].clr[3] >= 0);
+ BASSERT(sample[i+1].clr[3] >= 0);
+
+ BASSERT(sample[i].depth < sample[i+1].depth);
+ BASSERT(zs > sample[i].depth+bias);
+
alpha = lerp(sample[i].depth, sample[i+1].depth, zs, sample[i].clr[3], sample[i+1].clr[3]);
break;
}
}
- if (alpha < 0) alpha = 0.0;
+ if (alpha < 0) {
+ printf("alpha was less then 0!\n");
+ alpha = 0.0;
+ }
- return 1.0f - alpha;
+ return alpha;
}
#if 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-07-22 17:02:42 UTC (rev 11336)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c 2007-07-22 19:06:34 UTC (rev 11337)
@@ -410,13 +410,13 @@
apn= ap;
while(apn) {
if(apn->p[0]==0) {apn->p[0]= zvlnr; apn->z[0]= zverg; apn->mask[0]= mask; break; }
- if(apn->p[0]==zvlnr && ABS(apn->z[0] - zverg) <= zspan->recombine_maxsize) {apn->mask[0]|= mask; break; }
+ if(apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; }
if(apn->p[1]==0) {apn->p[1]= zvlnr; apn->z[1]= zverg; apn->mask[1]= mask; break; }
- if(apn->p[1]==zvlnr && ABS(apn->z[1] - zverg) <= zspan->recombine_maxsize) {apn->mask[1]|= mask; break; }
+ if(apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; }
if(apn->p[2]==0) {apn->p[2]= zvlnr; apn->z[2]= zverg; apn->mask[2]= mask; break; }
- if(apn->p[2]==zvlnr && ABS(apn->z[2] - zverg) <= zspan->recombine_maxsize) {apn->mask[2]|= mask; break; }
+ if(apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; }
if(apn->p[3]==0) {apn->p[3]= zvlnr; apn->z[3]= zverg; apn->mask[3]= mask; break; }
- if(apn->p[3]==zvlnr && ABS(apn->z[3] - zverg) <= zspan->recombine_maxsize) {apn->mask[3]|= mask; break; }
+ if(apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; }
// if(apn->p[i]==0) {apn->p[i]= zvlnr; apn->z[i]= zverg; apn->mask[i]= mask; break; }
// if(apn->p[i]==zvlnr) {apn->mask[i]|= mask; break; }
if(apn->next==NULL) apn->next= addpsA(zspan);
@@ -2711,7 +2711,9 @@
}
}
+/* -----------Deep Shadow Depth Bufferer--------- */
+/*polygon rasterizing function*/
static void zbuffillDc4(ZSpan *zspan, int zvlnr, float *v1, float *v2, float *v3, float *v4)
{
APixstr *ap, *apofs, *apn;
@@ -2754,7 +2756,6 @@
y0= z1*x2-x1*z2;
z0= x1*y2-y1*x2;
-
if(z0==0.0) return;
xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
@@ -2805,6 +2806,7 @@
if(apn->p[1]==0) {apn->p[1]= zvlnr; apn->z[1]= zverg; apn->mask[1]= mask; break; }
if(apn->p[2]==0) {apn->p[2]= zvlnr; apn->z[2]= zverg; apn->mask[2]= mask; break; }
if(apn->p[3]==0) {apn->p[3]= zvlnr; apn->z[3]= zverg; apn->mask[3]= mask; break; }
+
if(apn->next==NULL) apn->next= addpsA(zspan);
apn= apn->next;
}
@@ -2822,12 +2824,155 @@
}
}
-/* ------------------------------------------------------------------------ */
+/*line rasterizing function*/
+static void zbuflineDc(ZSpan *zspan, int zvlnr, float *vec1, float *vec2)
+{
+ APixstr *ap, *apn;
+ int *rectz;
+ int start, end, x, y, oldx, oldy, ofs;
+ int dz, vergz, mask, maxtest=0;
+ float dx, dy;
+ float v1[3], v2[3];
+ dx= vec2[0]-vec1[0];
+ dy= vec2[1]-vec1[1];
+
+ mask= zspan->mask;
+
+ if(fabs(dx) > fabs(dy)) {
+
+ /* all lines from left to right */
+ if(vec1[0]<vec2[0]) {
+ VECCOPY(v1, vec1);
+ VECCOPY(v2, vec2);
+ }
+ else {
+ VECCOPY(v2, vec1);
+ VECCOPY(v1, vec2);
+ dx= -dx; dy= -dy;
+ }
+
+ start= floor(v1[0]);
+ end= start+floor(dx);
+ if(end>=zspan->rectx) end= zspan->rectx-1;
+
+ oldy= floor(v1[1]);
+ dy/= dx;
+
+ vergz= v1[2];
+ vergz-= zspan->polygon_offset;
+ dz= (v2[2]-v1[2])/dx;
+ if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow
+
+ rectz= (int *)(zspan->arectz+zspan->rectx*(oldy) +start);
+ ap= (zspan->apixbuf+ zspan->rectx*(oldy) +start);
+
+ if(dy<0) ofs= -zspan->rectx;
+ else ofs= zspan->rectx;
+
+ for(x= start; x<=end; x++, rectz++, ap++) {
+
+ y= floor(v1[1]);
+ if(y!=oldy) {
+ oldy= y;
+ rectz+= ofs;
+ ap+= ofs;
+ }
+
+ if(x>=0 && y>=0 && y<zspan->recty) {
+ if(vergz<*rectz) {
+
+ apn= ap;
+ while(apn) { /* loop unrolled */
+ if(apn->p[0]==0) {apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
+ if(apn->p[1]==0) {apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
+ if(apn->p[2]==0) {apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
+ if(apn->p[3]==0) {apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
+
+ if(apn->next==0) apn->next= addpsA(zspan);
+ apn= apn->next;
+ }
+
+ }
+ }
+
+ v1[1]+= dy;
+ if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+ else vergz+= dz;
+ }
+ }
+ else {
+
+ /* all lines from top to bottom */
+ if(vec1[1]<vec2[1]) {
+ VECCOPY(v1, vec1);
+ VECCOPY(v2, vec2);
+ }
+ else {
+ VECCOPY(v2, vec1);
+ VECCOPY(v1, vec2);
+ dx= -dx; dy= -dy;
+ }
+
+ start= floor(v1[1]);
+ end= start+floor(dy);
+
+ if(start>=zspan->recty || end<0) return;
+
+ if(end>=zspan->recty) end= zspan->recty-1;
+
+ oldx= floor(v1[0]);
+ dx/= dy;
+
+ vergz= v1[2];
+ vergz-= zspan->polygon_offset;
+ dz= (v2[2]-v1[2])/dy;
+ if(vergz>0x50000000 && dz>0) maxtest= 1; // prevent overflow
+
+ rectz= (int *)( zspan->arectz+ (start)*zspan->rectx+ oldx );
+ ap= (zspan->apixbuf+ zspan->rectx*(start) +oldx);
+
+ if(dx<0) ofs= -1;
+ else ofs= 1;
+
+ for(y= start; y<=end; y++, rectz+=zspan->rectx, ap+=zspan->rectx) {
+
+ x= floor(v1[0]);
+ if(x!=oldx) {
+ oldx= x;
+ rectz+= ofs;
+ ap+= ofs;
+ }
+
+ if(x>=0 && y>=0 && x<zspan->rectx) {
+ if(vergz<*rectz) {
+
+ apn= ap;
+ while(apn) { /* loop unrolled */
+ if(apn->p[0]==0) {apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
+ if(apn->p[1]==0) {apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
+ if(apn->p[2]==0) {apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
+ if(apn->p[3]==0) {apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
+
+ if(apn->next==0) apn->next= addpsA(zspan);
+ apn= apn->next;
+ }
+
+ }
+ }
+
+ v1[0]+= dx;
+ if(maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
+ else vergz+= dz;
+ }
+ }
+}
+
/**
* Do deep shadow buffer z buffering. Based on zbuffer_abuf.
*/
+/*note: can return samples with negative depths*/
static int zbuffer_dsm(Render *re, RenderPart *pa, APixstr *APixbuf,
ListBase *apsmbase, unsigned int lay, float clipend, ShadBuf *buf)
{
@@ -2853,14 +2998,11 @@
/* filling methods */
zspan.zbuffunc= zbuffillDc4;
- zspan.zbuflinefunc= zbuflineAc;
+ zspan.zbuflinefunc= zbuflineDc;
//zspan.clipend = clipend;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list