[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17651] branches/soc-2007-joeedh/source/ blender: made nodes work with transparent shadows.
Joseph Eagar
joeedh at gmail.com
Sun Nov 30 20:54:08 CET 2008
Revision: 17651
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17651
Author: joeedh
Date: 2008-11-30 20:54:08 +0100 (Sun, 30 Nov 2008)
Log Message:
-----------
made nodes work with transparent shadows. yay for whoever had the forsight to make set_node_shader_lamp_loop.
Modified Paths:
--------------
branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h
branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
branches/soc-2007-joeedh/source/blender/render/intern/include/shading.h
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
branches/soc-2007-joeedh/source/blender/render/intern/source/shadeinput.c
branches/soc-2007-joeedh/source/blender/render/intern/source/shadeoutput.c
branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c
branches/soc-2007-joeedh/source/blender/src/buttons_shading.c
branches/soc-2007-joeedh/source/blender/src/usiblender.c
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h 2008-11-30 19:54:08 UTC (rev 17651)
@@ -41,7 +41,7 @@
struct MemFile;
#define BLENDER_VERSION 248
-#define BLENDER_SUBVERSION 1
+#define BLENDER_SUBVERSION 15
#define BLENDER_MINVERSION 245
#define BLENDER_MINSUBVERSION 15
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2008-11-30 19:54:08 UTC (rev 17651)
@@ -98,7 +98,7 @@
#define DSM_FINAL_TILESIZE 50
#define DSM_TILE_MEMARENASIZE (1<<16)
#define DSM_AASAMPLES (shb->samp > 5? 5: shb->samp)
-#define DSM_AAWIDTH (shb->soft > 3? 3: shb->soft)
+#define DSM_AAWIDTH 1.5f;
#define DSM_MAXSAMPLES 25
#define DSM_SAMPLEMERGE_LIMIT (0x7FFFFFFF) //20000000
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h 2008-11-30 19:54:08 UTC (rev 17651)
@@ -55,7 +55,8 @@
int index; /* color component index */
} _ClrEntry;
-
+void DSM_getPCSShadow(Render *re, ShadBuf *shb, ShadeInput *shi, LampRen *lar,
+ float *rco, float *dxco, float *dyco, float inp, float *shadfac);
void DSM_getSoftShadow(Render *re, ShadBuf *shb, struct ShadeInput *shi, LampRen *lar, float *rco, float *dxco, float *dyco, float inp, float *shadowclr);
float DSM_getShadow(ShadBuf *buf, float *rco, float *dxco, float *dyco, float inp, int component);
float DSM_getBilinearShadow(ShadBuf *shb, float *rco, float *dxco, float *dyco, float inp, int component);
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/shading.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/shading.h 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/shading.h 2008-11-30 19:54:08 UTC (rev 17651)
@@ -66,6 +66,7 @@
void shade_input_set_strand(struct ShadeInput *shi, struct StrandRen *strand, struct StrandPoint *spoint);
void shade_input_set_strand_texco(struct ShadeInput *shi, struct StrandRen *strand, struct StrandVert *svert, struct StrandPoint *spoint);
void shade_input_do_shade(struct ShadeInput *shi, struct ShadeResult *shr);
+void shade_input_do_color(struct ShadeInput *shi, struct ShadeResult *shr);
void shade_input_initialize(struct ShadeInput *shi, struct RenderPart *pa, struct RenderLayer *rl, int sample);
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-11-30 19:54:08 UTC (rev 17651)
@@ -646,7 +646,7 @@
shade_input_set_shade_texco(&shi);
- shade_color(&shi, &shr);
+ shade_input_do_color(&shi, &shr);
SWAP(int, osatex, shi.osatex); // XXXXX!!!!
diff[0] = shr.diff[0];
@@ -953,7 +953,7 @@
rdrect= pa.rectdaps;
row = (_ClrEntry*) mergescratch;
-
+
/* render the tile */
for(y=0; y<pa.recty; y++) {
if(re->test_break && re->test_break())
@@ -1219,7 +1219,7 @@
aprectstrand+= pa.rectx;
offs+= pa.rectx;
}
-
+
MEM_freeN(APixbuf);
dsm_freepsA(&apsmbase);
if (APixbufstrand) MEM_freeN(APixbufstrand);
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c 2008-11-30 19:52:21 UTC (rev 17650)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c 2008-11-30 19:54:08 UTC (rev 17651)
@@ -43,6 +43,7 @@
#include "BKE_bucketbuffer.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_utildefines.h"
#include "DNA_material_types.h"
#include "DNA_object_types.h"
@@ -104,37 +105,82 @@
return fac;
}
-#if 0
+static float dsm_homogz_to_dist(int z, float winmat[][4])
+{
+ float fac = (float)z / (float)0x7FFFFFFF;
+ fac = (winmat[3][2])/(winmat[2][2] - winmat[2][3]*fac);
+
+ return fac;
+}
+#if 1
+
+DSMFunction *get_dsm_func(DSMBuffer *dbuf, int xs, int ys, int channel)
+{
+ DSMFunction *func = NULL;
+ DSMTile *tile = NULL;
+
+ if (xs < 0 || ys < 0 || xs >= dbuf->sizex || ys >= dbuf->sizey) return NULL;
+
+ xs /= dbuf->tsizex;
+ ys /= dbuf->tsizey;
+
+ tile = TCS_GetTile(dbuf, xs, ys, 0);
+ if (!tile) return NULL;
+
+ xs %= dbuf->tsizex;
+ ys %= dbuf->tsizey;
+
+ switch (channel) {
+ case 0:
+ if (tile->r_rect[ys*tile->sizex+xs] != -1)
+ func = &tile->funcarray[tile->r_rect[ys*tile->sizex+xs]];
+ break;
+ case 1:
+ if (tile->g_rect[ys*tile->sizex+xs] != -1)
+ func = &tile->funcarray[tile->g_rect[ys*tile->sizex+xs]];
+ break;
+ case 2:
+ if (tile->b_rect[ys*tile->sizex+xs] != -1)
+ func = &tile->funcarray[tile->b_rect[ys*tile->sizex+xs]];
+ break;
+ default:
+ printf("bad component value for dsm_getshadow!\n");
+ }
+
+ return func;
+}
+
/*backprojection based method*/
-float DSM_getBPSoftShadow(Render *re, ShadBuf *shb, ShadeInput *shi, LampRen *lar,
- float *rco, float *dxco, float *dyco, float inp, int channel)
+void DSM_getPCSShadow(Render *re, ShadBuf *shb, ShadeInput *shi, LampRen *lar,
+ float *rco, float *dxco, float *dyco, float inp, float *shadfac)
{
- DSMBuffer *buf = shb->dsmbuffer;
+ DSMBuffer *dbuf = shb->dsmbuffer;
DSMTile *tile;
DSMFunction *func;
- DSMSampleLayer *samp, *startsamp=NULL;
+ DSMLayerSample *samp, *startsamp=NULL;
float fac, co[4], co2[4], d, siz;
- float xs, ys, a, b, res, worldz, startz;
- int zs, bias, i;
+ float xs, ys, res, startz, searchsize, averz, fz;
+ int zs, bias, i, a, b, c, totblockers;
float corners[4];
BASSERT(shb->dsmbuffer);
+
+ if(inp <= 0.0f) {
+ shadfac[0] = shadfac[1] = shadfac[2] = 0.0f;
+ return;
+ }
- if(inp <= 0.0f) return 0.0f;
-
/* rotate renderco en osaco */
siz= 0.5f*(float)shb->size;
VECCOPY(co, rco);
- VECCOPY(co4, rco;
+// VECCOPY(co4, rco);
- co4[3] = 1.0f;
+// co4[3] = 1.0f;
co[3]= 1.0f;
MTC_Mat4MulVec4fl(shb->persmat, co); /* rational hom co */
- MTC_Mat4MulVec4fl(shb->viewmat, co4); /* used for getting world-space depth */
+// MTC_Mat4MulVec4fl(shb->viewmat, co4); /* used for getting world-space depth */
- worldz = co4[2];
-
xs= siz*(1.0f+co[0]/co[3]);
ys= siz*(1.0f+co[1]/co[3]);
@@ -146,7 +192,7 @@
else d = -1.0f;
if (G.rt == 30) {
- if (co[2] - shb->clipsta < -0.00001f) return 1.0;
+ if (co[2] - shb->clipsta < -0.00001f) return;
else if (co[2] > shb->clipend) co[2] = shb->clipend - 0.001;
fac= (double)(co[2] - shb->clipsta) / (double)(shb->clipend - shb->clipsta);
@@ -175,33 +221,21 @@
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 (xs >= dbuf->sizex || xs < 0) {
+ return;
}
- if (ys >= buf->sizey || ys < 0) {
- return 1.0;
+ if (ys >= dbuf->sizey || ys < 0) {
+ return;
}
- tile = TCS_GetAndLockTile(dbuf, xs, ys, 0);
- xs %= buf->tsizex;
- ys %= buf->tsizey;
+ func = get_dsm_func(dbuf, xs, ys, 0);
- switch (channel) {
- 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;
- }
+ if (!func) return;
samp = func->samples;
for (i=0; i<func->totsamples; i++, samp++) {
- if (zs > samp->depth) {
+ if (zs > samp->depth+bias) {
startsamp = samp;
break;
}
@@ -210,13 +244,97 @@
BASSERT(startsamp);
if (startsamp == NULL) {
TCS_UnlockTile(tile);
- return 1.0f;
+ return;
}
-
+
+ /*find initial search size*/
//compute the light-space depth
- startz = dsm_linearz_to_dist(startsamp->depth, shb->clipsta, shb->clipend, shb->winmat);
+ startz = dsm_homogz_to_dist(startsamp->depth, shb->winmat);
+ searchsize = shb->soft * (startz - shb->clipsta) / startz;
+ searchsize /= 2;
+ if (searchsize == 0) searchsize = 1;
- TCS_UnlockTile(tile);
+ printf("u - %f %f %f %f\n", shb->clipsta, shb->soft, startz, searchsize);
+
+ averz = 0.0f;
+ totblockers = 0;
+
+ for (a=xs-searchsize; a<xs+searchsize; a++) {
+ printf("0");
+ if (a < 0 || a >= dbuf->sizex) continue;
+ for (b=ys-searchsize; b<ys+searchsize; b++) {
+ printf("1");
+ if (b < 0 || b >= dbuf->sizey) continue;
+ func = get_dsm_func(dbuf, a, b, 0);
+ if (!func) continue;
+
+ samp = func->samples;
+ for (i=0; i<func->totsamples; i++, samp++) {
+ if (samp->depth < startsamp->depth) {
+ fz = dsm_homogz_to_dist(samp->depth, shb->winmat);
+ averz += fz;
+ totblockers++;
+ break;
+ }
+ printf("2");
+ }
+ }
+ }
+
+ if (totblockers) averz /= totblockers;
+ if (averz == 0.0f) averz = startz;
+
+ printf("d - %d %f %f %f\n", totblockers, averz, startz, searchsize);
+
+ shadfac[0] = shadfac[1] = shadfac[2] = 0.0f;
+ totblockers = 0;
+
+ searchsize = (startz - averz) / averz;
+ printf("t - %d %f %f %f\n", totblockers, averz, startz, searchsize);
+ searchsize = searchsize * shb->soft * shb->clipsta / startz;
+ searchsize /= 2.0;
+ if (searchsize == 0) searchsize = 1;
+
+ printf("u - %d %f %f %f\n", totblockers, averz, startz, searchsize);
+
+ for (a=xs-searchsize; a < xs+searchsize; a++) {
+ //printf("(3 %f %d %f %f %f) ", searchsize, a, xs, (xs-searchsize), (xs+searchsize));
+ if (a < 0) continue;
+ if (a >= dbuf->sizex) break;
+
+ for (b=ys-searchsize; b < ys+searchsize; b++) {
+ printf("4");
+ if (b < 0) continue;
+ if (b >= dbuf->sizey) break;
+
+ for (i=0; i<3; i++) {
+ func = get_dsm_func(dbuf, a, b, i);
+ if (!func) {
+ shadfac[i] += 1.0;
+ totblockers++;
+ continue;
+ }
+
+ samp = func->samples;
+ for (c=0; c<func->totsamples; c++, samp++) {
+ if (samp->depth < startsamp->depth) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list