Revision: 15790
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15790
Author: joeedh
Date: 2008-07-27 01:40:01 +0200 (Sun, 27 Jul 2008)
Log Message:
-----------
Properly integrated the strand renderer into DSM; among other things, this
means textured strands will now work properly (e.g. if you had a blend texture
to make the ends blend out).
There is still an issue with some render artifacts, will need to work on that
next.
Also, dupli objects still arn't rendering right.
Modified Paths:
--------------
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/strand.h
branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
branches/soc-2007-joeedh/source/blender/render/intern/source/shadeinput.c
branches/soc-2007-joeedh/source/blender/render/intern/source/strand.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
2008-07-26 22:37:05 UTC (rev 15789)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
2008-07-26 23:40:01 UTC (rev 15790)
@@ -94,7 +94,7 @@
#define MAX_SAMPLELAYERS 32
-#define DSM_FINAL_TILESIZE 32
+#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)
@@ -104,10 +104,11 @@
//angle limit of strands. is in degrees, so
//code has to convert.ss
-#define DSM_STRAND_MAX_ADAPTCOS 25.0
+#define DSM_STRAND_ADAPTCOS 25.0
#define DSM_LINEAR 1
#define DSM_SOFT 0
+#define DSM_VIS 1
//#define DOQMCDEBUG
/*little bit smaller memarena buffer size for the final diced
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
2008-07-26 22:37:05 UTC (rev 15789)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
2008-07-26 23:40:01 UTC (rev 15790)
@@ -38,12 +38,14 @@
#include "zbuf.h"
#include "shadbuf.h"
-struct _ClrEntry;
+struct StrandShadeCache;
typedef struct _ClrEntry {
struct _ClrEntry *next, *prev;
ListBase *srclist;
int depth;
+ float u, v; //for strands
+ int seg; //also for strands
int p;
int mask;
int obi;
@@ -73,9 +75,9 @@
DSMBuffer *dbuf, RE_BucketTile *btile, int
threadnr, float viewinv[4][4]);
int zbuffer_dsm(Render *re, RenderPart *pa, float winmat[4][4], APixstr
**lastbuf,
- APixstr **lastbufstrand, APixstr *APixbuf,
APixstr *APixbufstrand,
+ APixstr **lastbufstrand, APixstr *APixbuf,
APixstrand *APixbufstrand,
ListBase *apsmbase, unsigned int lay, ShadBuf
*shb,
- RE_BucketTile *buckettile);
+ RE_BucketTile *buckettile, struct
StrandShadeCache *sscache);
/* Modified zbufclipwire from zbuf.c
Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/strand.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/strand.h
2008-07-26 22:37:05 UTC (rev 15789)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/strand.h
2008-07-26 23:40:01 UTC (rev 15790)
@@ -44,6 +44,10 @@
struct StrandSurface;
struct DerivedMesh;
struct ObjectRen;
+struct APixstrand;
+struct StrandShadeCache;
+struct GHash;
+struct MemArena;
typedef struct StrandPoint {
/* position within segment */
@@ -83,8 +87,36 @@
StrandPoint point1, point2;
int shaded;
+ int shadow_mode; //for shadows, doesn't do more complex lighting
} StrandSegment;
+typedef struct StrandPart {
+ struct Render *re;
+ struct ZSpan *zspan;
+
+ struct APixstrand *apixbuf;
+ int *totapixbuf;
+ int *rectz;
+ int *rectmask;
+ long *rectdaps;
+ int rectx, recty;
+ int sample;
+
+ StrandSegment *segment;
+ float t[3], s[3];
+
+ struct StrandShadeCache *cache;
+
+ int shadow_mode;
+ int max_shadowsamples; //max number of samples in shadow mode
+} StrandPart;
+
+struct StrandShadeCache {
+ struct GHash *resulthash;
+ struct GHash *refcounthash;
+ struct MemArena *memarena;
+};
+
struct StrandShadeCache;
typedef struct StrandShadeCache StrandShadeCache;
Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
2008-07-26 22:37:05 UTC (rev 15789)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
2008-07-26 23:40:01 UTC (rev 15790)
@@ -62,6 +62,7 @@
#include "rendercore.h"
#include "shadbuf.h"
#include "shading.h"
+#include "strand.h"
#include "sss.h"
#include "zbuf.h"
#include "qmc.h"
@@ -164,6 +165,7 @@
_DSM_maketile((TCS_TileBuffer*)data->dbuf,
deepbuffer_pool, (TCS_Tile*)tile);
tilet->ready = 1;
+ PIL_sleep_ms(30);
} else BLI_unlock_thread(LOCK_CUSTOM1);
}
@@ -422,6 +424,8 @@
Normalize(re2->grvec);
re2->osa = DSM_AASAMPLES*DSM_AASAMPLES;
+ memcpy(re2->jit, shb->jit, sizeof(float)*2*DSM_AASAMPLES*DSM_AASAMPLES);
+
/*unset ortho and panorama flags*/
re2->r.mode &= ~R_ORTHO;
re2->r.mode &= ~R_PANORAMA;
@@ -500,7 +504,7 @@
}
}
- if (re->r.threads < 2) {
+ /*if (re->r.threads < 2) {
thread_data[0].tiles = &threadtiles;
thread_data[0].threadnr = 0;
thread_data[0].dbuf = dbuf;
@@ -510,7 +514,7 @@
MTC_Mat4CpyMat4(thread_data[0].viewinv, re->viewinv);
thread_data[0].shb = shb;
do_dsmshadow_thread(thread_data);
- } else {
+ } else*/ {
BLI_init_threads(&threads, do_dsmshadow_thread, re->r.threads);
for (x=0; x<re->r.threads; x++) {
@@ -575,7 +579,7 @@
MEM_freeN(re2);
- if (G.rt == 27 && !(re->test_break && re->test_break())) {
+ if ((G.rt == 27 || DSM_VIS) && !(re->test_break && re->test_break())) {
ImBuf *visbuf = dsm_make_vis_imbuf(shb->dsmbuffer);
visbuf->ftype |= PNG;
IMB_saveiff(visbuf, "dsm_vis.png", 0);
@@ -705,11 +709,89 @@
}
+/*turns raw zbuffer data into a form the main dsm code can understand and work
with.
+ works on a pixel-by-pixel fashion.*/
+int dsm_strandstr_to_row(Render *re, ShadBuf *shb, DSMBuffer *dbuf, APixstrand
*ap, _ClrEntry *row2,
+ int totface)
+{
+ APixstrand *apn;
+ int a, b;
+ apn= ap;
+ while(apn) {
+ /*max_depth is divided by 6,
+ 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*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 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;
+
+ if (G.rt == 46) {
+ printf("bleh z: %d %d %d %d\n",
apn->z[0], apn->z[1], apn->z[2], apn->z[3]);
+ printf("bleh p: %d %d %d %d\n",
apn->p[0], apn->p[1], apn->p[2], apn->p[3]);
+ printf("bleh obi: %d %d %d %d\n",
apn->obi[0], apn->obi[1], apn->obi[2], apn->obi[3]);
+ }
+
+ if (apn->z[a] < 0x7FFFFFFF*-1.0f) {
+ printf("z less then 0!: z: %d\n",
apn->z[a]);
+ //continue;
+ }
+
+ for (b=0; b<DSM_AASAMPLES*DSM_AASAMPLES; b++) {
+ if (apn->mask[a] & (1<<b)) {
+ if (G.rt == 31 || DSM_LINEAR) {
+ /*use linear z. we do
it here because the actual
+ rasterization code
seems to rely on homogenous z
+ for clipping.*/
+ zco=
((float)apn->z[a])/2147483647.0f;
+ zco =
(shb->winmat[3][2])/(shb->winmat[2][2] - shb->winmat[2][3]*zco);
+ zco = (zco -
shb->clipsta) / (shb->clipend - shb->clipsta);
+ row2[totface].depth =
2147483647.0f*zco;
+ //if (zco < -0.001 ||
zco > 1.001) printf("linear z: %f\n", zco);
+ } else row2[totface].depth =
apn->z[a];
+
+ row2[totface].p = apn->p[a];
+ row2[totface].obi = apn->obi[a];
+ row2[totface].mask =
apn->mask[a];
+
+ /*samplenr is first masked bit
index*/
+ row2[totface].samplenr = b;
+
+ row2[totface].type = DSM_STRAND;
+ row2[totface].u = apn->u[a];
+ row2[totface].v = apn->v[a];
+ row2[totface].seg = apn->seg[a];
+
+ /*set appropriate pointers to
NULL*/
+ row2[totface].next =
row2[totface].prev = NULL;
+ row2[totface].srclist = NULL;
+ row2[totface].value = 0.0f;
+
+ totface++;
+ if(totface >= dbuf->max_depth/6
- DSM_AASAMPLES*DSM_AASAMPLES*2) break;
+ }
+ }
+ }
+ else break;
+ }
+ apn= apn->next;
+ }
+
+ return totface;
+}
+
+
/*turns raw zbuffer data into a form the main dsm code can understand and work
with.
works on a pixel-by-pixel fashion.*/
int dsm_apixstr_to_row(Render *re, ShadBuf *shb, DSMBuffer *dbuf, APixstr *ap,
_ClrEntry *row2,
- int totface, int type)
+ int totface)
{
APixstr *apn;
int a, b;
@@ -754,7 +836,7 @@
/*samplenr is first masked bit
index*/
row2[totface].samplenr = b;
- row2[totface].type = type;
+ row2[totface].type = DSM_FACE;
/*set appropriate pointers to
NULL*/
row2[totface].next =
row2[totface].prev = NULL;
@@ -781,15 +863,20 @@
VlakRen *vlak;
StrandRen *strand;
RenderResult pa_res;
- APixstr *APixbuf, *APixbufstrand = NULL; /* Zbuffer: linked list
of face samples */
- APixstr *ap, *apstrand, *aprect, *aprectstrand;
+ APixstr *APixbuf;
+ APixstrand *APixbufstrand = NULL; /* Zbuffer: linked list of face
samples */
+ APixstr *ap, *aprect;
+ APixstrand *apstrand, *aprectstrand;
ListBase transfuncs[LA_DEEPBUF_MAXSAMPLES][3], *bucket;
ListBase apsmbase={NULL, NULL}; //, psm={NULL, NULL};
_ClrEntry *row, *row2, *lastsamples[LA_DEEPBUF_MAXSAMPLES];
RenderPart pa;
- Material *mat;
+ Material rmat;
+ Material *mat = NULL; // = &rmat;
+ _ClrEntry *rowscratch = dbuf->s2[threadnr];
+ StrandShadeCache *sscache;
+ ShadeSample ssamp;
char *mergescratch = dbuf->s1[threadnr];
- _ClrEntry *rowscratch = dbuf->s2[threadnr];
float accum[LA_DEEPBUF_MAXSAMPLES][3];
long *rdrect;
int x, y, a, b, c, d, totface;
@@ -798,6 +885,8 @@
int samp_totlayers[LA_DEEPBUF_MAXLAYERS][3];
unsigned int lay = (1<<20)-1; /*FIXMEGREP: layer hacked to have first
20 bits set!*/
int mergescratchlen;
+
+ memset(&rmat, 0, sizeof(rmat));
if (!dbuf) {
printf("Error: no deep shadow map structure!\n");
@@ -813,6 +902,8 @@
memset(&pa, 0, sizeof(pa));
memset(&pa_res, 0, sizeof(RenderResult));
+
+ sscache= strand_shade_cache_create();
pa.rectx = tile->sizex;
pa.recty = tile->sizey;
@@ -828,6 +919,12 @@
pa.rectp = MEM_mapallocN(sizeof(int)*tile->sizex*tile->sizey,
"pa.rectz");
pa.rectdaps = MEM_mapallocN(sizeof(long)*tile->sizex*tile->sizey+4,
"pa.rectz");
+ /*initialize rectz to maximum z*/
+ for (a=0; a<tile->sizex*tile->sizey; a++) pa.rectz[a] = 0x7FFFFFFF;
+
+ /*initialize ssamp*/
+ shade_sample_initialize(&ssamp, &pa, NULL);
+
bucket = &dbuf->buckets[tile->y*dbuf->tilex+tile->x];
/* (comment from template function zbuffer_transp_shade): "looks nicer
for calling code" */
@@ -835,16 +932,19 @@
if (pa.rectz) MEM_freeN(pa.rectz);
if (pa.rectp) MEM_freeN(pa.rectp);
if (pa.rectdaps) MEM_freeN(pa.rectdaps);
-
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs