Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2005-12-09 01:05:42 +0300
committerTon Roosendaal <ton@blender.org>2005-12-09 01:05:42 +0300
commitc492729b3a0d52ae01ee67e5ad92bdb02f6585df (patch)
tree4e83439d1aed0a943c0abe44ceaf8d9b72f8f7e2 /source/blender/render
parent13d638c8b8975db9faccb50774e68b84cd0d132b (diff)
New feature: "Stress" texture input channel
(As usual movies disappears after while) Face example showing stress values on a blend. White is stretch, black is squeeze http://www.blender.org/bf/0001_0014.avi Quick test with softbody stretch http://www.blender.org/bf/0001_0100.avi Based on the difference of the "Orco" (original undeformed coordinate) and the actual render coordinate, a stress value is computed to make textures react to stretching or wrinking skin. The texture coordinate is neutral (0) on relaxed state. -1 is squeezed to zero, +1 is stretched to infinity. Note that scaling (object itself or parent) also will result in stress values. The reason for the huge commit is a cleanup in allocating memory for the vertices. These were growing too large with new options, so now it allocates the optional coordinates dynamically. Saves about 20 MB memory per 1M vertices already. But best of all is that I now can add much more fun... so tangents, here we come!
Diffstat (limited to 'source/blender/render')
-rw-r--r--source/blender/render/extern/include/render.h11
-rw-r--r--source/blender/render/extern/include/render_types.h11
-rw-r--r--source/blender/render/intern/source/envmap.c2
-rw-r--r--source/blender/render/intern/source/initrender.c8
-rw-r--r--source/blender/render/intern/source/renderHelp.c2
-rw-r--r--source/blender/render/intern/source/rendercore.c72
-rw-r--r--source/blender/render/intern/source/renderdatabase.c170
-rw-r--r--source/blender/render/intern/source/texture.c9
-rw-r--r--source/blender/render/intern/source/zbuf.c4
9 files changed, 226 insertions, 63 deletions
diff --git a/source/blender/render/extern/include/render.h b/source/blender/render/extern/include/render.h
index ec724b55846..5f8ceb45b15 100644
--- a/source/blender/render/extern/include/render.h
+++ b/source/blender/render/extern/include/render.h
@@ -199,7 +199,7 @@ void init_ao_sphere(float *sphere, int tot, int iter);
/* --------------------------------------------------------------------- */
-/* renderdatabase (3) */
+/* renderdatabase () */
/* --------------------------------------------------------------------- */
struct VlakRen *RE_findOrAddVlak(int nr);
struct VertRen *RE_findOrAddVert(int nr);
@@ -207,6 +207,15 @@ struct HaloRen *RE_findOrAddHalo(int nr);
HaloRen *RE_inithalo(struct Material *ma, float *vec, float *vec1, float *orco, float hasize,
float vectsize, int seed);
+float *RE_vertren_get_sticky(struct VertRen *ver, int verify);
+float *RE_vertren_get_stress(struct VertRen *ver, int verify);
+float *RE_vertren_get_rad(struct VertRen *ver, int verify);
+float *RE_vertren_get_strand(struct VertRen *ver, int verify);
+float *RE_vertren_get_tangent(struct VertRen *ver, int verify);
+
+void RE_free_vertex_tables(void);
+void RE_init_vertex_tables(void);
+
/**
* callbacks (11):
*
diff --git a/source/blender/render/extern/include/render_types.h b/source/blender/render/extern/include/render_types.h
index 531a7fc5ceb..dc2f5616f29 100644
--- a/source/blender/render/extern/include/render_types.h
+++ b/source/blender/render/extern/include/render_types.h
@@ -89,7 +89,7 @@ typedef struct ShadeInput
/* texture coordinates */
float lo[3], gl[3], uv[3], ref[3], orn[3], winco[3], sticky[3], vcol[3], rad[3];
- float vn[3], vno[3], facenor[3], view[3], refcol[4], displace[3], strand, tang[3];
+ float vn[3], vno[3], facenor[3], view[3], refcol[4], displace[3], strand, tang[3], stress;
/* dx/dy OSA coordinates */
float dxco[3], dyco[3];
@@ -110,6 +110,7 @@ typedef struct ShadeInput
} ShadeInput;
struct MemArena;
+struct VertTableNode;
/* here only stuff to initalize the render itself */
typedef struct RE_Render
@@ -149,7 +150,7 @@ typedef struct RE_Render
ListBase lights;
struct LampRen **la;
struct VlakRen **blovl;
- struct VertRen **blove;
+ struct VertTableNode *vertnodes;
struct HaloRen **bloha;
/* arena for allocating data for use during render, for
@@ -198,13 +199,11 @@ typedef struct VertRen
float co[3];
float n[3];
float ho[4];
- float rad[3]; /* result radio rendering */
float *orco;
- float *sticky;
- void *svert; /* smooth vert, only used during initrender */
short clip;
- short flag; /* in use for clipping ztra parts */
+ short flag; /* in use for clipping ztra parts, temp setting stuff in convertBlenderscene.c */
float accum; /* accum for radio weighting, and for strand texco static particles */
+ int index; /* index allows extending vertren with any property */
} VertRen;
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c
index f7c31fa099a..aba3a34929c 100644
--- a/source/blender/render/intern/source/envmap.c
+++ b/source/blender/render/intern/source/envmap.c
@@ -289,7 +289,7 @@ static void env_rotate_scene(float mat[][4], int mode)
}
for(a=0; a<R.totvert; a++) {
- if((a & 255)==0) ver= R.blove[a>>8];
+ if((a & 255)==0) ver= RE_findOrAddVert(a);
else ver++;
MTC_Mat4MulVecfl(tmat, ver->co);
diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c
index 1f1ffc20cf5..ba9216fa80e 100644
--- a/source/blender/render/intern/source/initrender.c
+++ b/source/blender/render/intern/source/initrender.c
@@ -479,11 +479,12 @@ static void init_def_material(void)
init_render_material(ma);
}
+/* this is called in creator.c, on startup */
void RE_init_render_data(void)
{
memset(&R, 0, sizeof(RE_Render));
- R.blove= (VertRen **)MEM_callocN(sizeof(void *)*(TABLEINITSIZE),"Blove");
+ RE_init_vertex_tables();
R.blovl= (VlakRen **)MEM_callocN(sizeof(void *)*(TABLEINITSIZE),"Blovl");
R.bloha= (HaloRen **)MEM_callocN(sizeof(void *)*(TABLEINITSIZE),"Bloha");
@@ -491,10 +492,11 @@ void RE_init_render_data(void)
init_filt_mask();
}
+/* called in usiblender.c on exit, also for blender -b render */
void RE_free_render_data()
{
- MEM_freeN(R.blove);
- R.blove= NULL;
+ MEM_freeN(R.vertnodes);
+ R.vertnodes= NULL;
MEM_freeN(R.blovl);
R.blovl= NULL;
MEM_freeN(R.bloha);
diff --git a/source/blender/render/intern/source/renderHelp.c b/source/blender/render/intern/source/renderHelp.c
index aa966268aca..aba78079472 100644
--- a/source/blender/render/intern/source/renderHelp.c
+++ b/source/blender/render/intern/source/renderHelp.c
@@ -149,7 +149,7 @@ void setzbufvlaggen( void (*projectfunc)(float *, float *) )
/* calculate view coordinates (and zbuffer value) */
for(a=0; a< R.totvert;a++) {
- if((a & 255)==0) ver= R.blove[a>>8];
+ if((a & 255)==0) ver= RE_findOrAddVert(a);
else ver++;
if(R.r.mode & R_PANORAMA) {
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
index 99e9384f5b8..3ca504e2ce4 100644
--- a/source/blender/render/intern/source/rendercore.c
+++ b/source/blender/render/intern/source/rendercore.c
@@ -2141,9 +2141,20 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
shi->orn[2]= -shi->vn[2];
}
if(mode & MA_RADIO) {
- shi->rad[0]= (l*v3->rad[0] - u*v1->rad[0] - v*v2->rad[0]);
- shi->rad[1]= (l*v3->rad[1] - u*v1->rad[1] - v*v2->rad[1]);
- shi->rad[2]= (l*v3->rad[2] - u*v1->rad[2] - v*v2->rad[2]);
+ float *r1, *r2, *r3;
+
+ r1= RE_vertren_get_rad(v1, 0);
+ r2= RE_vertren_get_rad(v2, 0);
+ r3= RE_vertren_get_rad(v3, 0);
+
+ if(r1 && r2 && r3) {
+ shi->rad[0]= (l*r3[0] - u*r1[0] - v*r2[0]);
+ shi->rad[1]= (l*r3[1] - u*r1[1] - v*r2[1]);
+ shi->rad[2]= (l*r3[2] - u*r1[2] - v*r2[2]);
+ }
+ else {
+ shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0;
+ }
}
else {
shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0;
@@ -2152,7 +2163,19 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
/* mirror reflection colour textures (and envmap) */
calc_R_ref(shi);
}
-
+ if(texco & TEXCO_STRESS) {
+ float *s1, *s2, *s3;
+
+ s1= RE_vertren_get_stress(v1, 0);
+ s2= RE_vertren_get_stress(v2, 0);
+ s3= RE_vertren_get_stress(v3, 0);
+ if(s1 && s2 && s3) {
+ shi->stress= l*s3[0] - u*s1[0] - v*s2[0];
+ if(shi->stress<1.0f) shi->stress-= 1.0f;
+ else shi->stress= (shi->stress-1.0f)/shi->stress;
+ }
+ else shi->stress= 0.0f;
+ }
}
else {
shi->rad[0]= shi->rad[1]= shi->rad[2]= 0.0;
@@ -2225,7 +2248,7 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
VECCOPY(rco, col);
}
else if( (facenr & 0x7FFFFF) <= R.totvlak) {
- VertRen *v1, *v2, *v3;
+ VertRen *v1;
Material *mat;
MaterialLayer *ml;
float alpha, fac, zcor;
@@ -2349,17 +2372,24 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
}
/* after this the u and v AND shi.dxuv and shi.dyuv are incorrect */
if(shi.mat->texco & TEXCO_STICKY) {
- if(v1->sticky) {
+ VertRen *v2, *v3;
+ float *s1, *s2, *s3;
+
+ if(facenr & 0x800000) {
+ v2= vlr->v3; v3= vlr->v4;
+ } else {
+ v2= vlr->v2; v3= vlr->v3;
+ }
+
+ s1= RE_vertren_get_sticky(v1, 0);
+ s2= RE_vertren_get_sticky(v2, 0);
+ s3= RE_vertren_get_sticky(v3, 0);
+
+ if(s1 && s2 && s3) {
extern float Zmulx, Zmuly;
- float *o1, *o2, *o3, hox, hoy, l, dl, u, v;
+ float hox, hoy, l, dl, u, v;
float s00, s01, s10, s11, detsh;
- if(facenr & 0x800000) {
- v2= vlr->v3; v3= vlr->v4;
- } else {
- v2= vlr->v2; v3= vlr->v3;
- }
-
s00= v3->ho[0]/v3->ho[3] - v1->ho[0]/v1->ho[3];
s01= v3->ho[1]/v3->ho[3] - v1->ho[1]/v1->ho[3];
s10= v3->ho[0]/v3->ho[3] - v2->ho[0]/v2->ho[3];
@@ -2376,12 +2406,8 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
v= (hoy - v3->ho[1]/v3->ho[3])*s00 - (hox - v3->ho[0]/v3->ho[3])*s01;
l= 1.0+u+v;
- o1= v1->sticky;
- o2= v2->sticky;
- o3= v3->sticky;
-
- shi.sticky[0]= l*o3[0]-u*o1[0]-v*o2[0];
- shi.sticky[1]= l*o3[1]-u*o1[1]-v*o2[1];
+ shi.sticky[0]= l*s3[0]-u*s1[0]-v*s2[0];
+ shi.sticky[1]= l*s3[1]-u*s1[1]-v*s2[1];
shi.sticky[2]= 0.0;
if(shi.osatex) {
@@ -2391,11 +2417,11 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
shi.dyuv[1]= s00/Zmuly;
dl= shi.dxuv[0]+shi.dxuv[1];
- shi.dxsticky[0]= dl*o3[0]-shi.dxuv[0]*o1[0]-shi.dxuv[1]*o2[0];
- shi.dxsticky[1]= dl*o3[1]-shi.dxuv[0]*o1[1]-shi.dxuv[1]*o2[1];
+ shi.dxsticky[0]= dl*s3[0]-shi.dxuv[0]*s1[0]-shi.dxuv[1]*s2[0];
+ shi.dxsticky[1]= dl*s3[1]-shi.dxuv[0]*s1[1]-shi.dxuv[1]*s2[1];
dl= shi.dyuv[0]+shi.dyuv[1];
- shi.dysticky[0]= dl*o3[0]-shi.dyuv[0]*o1[0]-shi.dyuv[1]*o2[0];
- shi.dysticky[1]= dl*o3[1]-shi.dyuv[0]*o1[1]-shi.dyuv[1]*o2[1];
+ shi.dysticky[0]= dl*s3[0]-shi.dyuv[0]*s1[0]-shi.dyuv[1]*s2[0];
+ shi.dysticky[1]= dl*s3[1]-shi.dyuv[0]*s1[1]-shi.dyuv[1]*s2[1];
}
}
}
diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c
index b2f7cdfca48..4c7453bf1b1 100644
--- a/source/blender/render/intern/source/renderdatabase.c
+++ b/source/blender/render/intern/source/renderdatabase.c
@@ -44,7 +44,7 @@
* offset in a 256-entry block.
*
* - If the 256-entry block entry has an entry in the
- * blove/bloha/blovl array of the current block, the i-th entry in
+ * vertnodes/bloha/blovl array of the current block, the i-th entry in
* that block is allocated to this entry.
*
* - If the entry has no block allocated for it yet, memory is
@@ -74,11 +74,24 @@
/* ------------------------------------------------------------------------- */
-#if 0
-/* proposal for more dynamic allocation of options for render vertices, so we dont
- have to reserve this space inside vertices */
+
+/* More dynamic allocation of options for render vertices, so we dont
+ have to reserve this space inside vertices.
+ Important; vertices should have been created already (to get tables checked)
+ that's a reason why the calls demand VertRen * as arg, not the index */
+
+/* NOTE! the hardcoded table size 256 is used still in code for going quickly over vertices/faces */
+
+#define RE_STICKY_ELEMS 2
+#define RE_STRESS_ELEMS 1
+#define RE_RAD_ELEMS 4
+#define RE_STRAND_ELEMS 1
+#define RE_TANGENT_ELEMS 3
+#define RE_STRESS_ELEMS 1
+
+/* render allocates totvert/256 of these nodes, for lookup and quick alloc */
typedef struct VertTableNode {
- VertRen *vert;
+ struct VertRen *vert;
float *rad;
float *sticky;
float *strand;
@@ -86,55 +99,162 @@ typedef struct VertTableNode {
float *stress;
} VertTableNode;
-#define RE_STICKY_ELEMS 3
float *RE_vertren_get_sticky(VertRen *ver, int verify)
{
float *sticky;
- int a= ver->index>>8;
+ int nr= ver->index>>8;
- sticky= R.blove[a].sticky;
+ sticky= R.vertnodes[nr].sticky;
if(sticky==NULL) {
if(verify)
- sticky= R.blove[a].sticky= MEM_mallocN(RE_STICKY_ELEMS*sizeof(float), "sticky table");
+ sticky= R.vertnodes[nr].sticky= MEM_mallocN(256*RE_STICKY_ELEMS*sizeof(float), "sticky table");
+ else
+ return NULL;
+ }
+ return sticky + (ver->index & 255)*RE_STICKY_ELEMS;
+}
+
+float *RE_vertren_get_stress(VertRen *ver, int verify)
+{
+ float *stress;
+ int nr= ver->index>>8;
+
+ stress= R.vertnodes[nr].stress;
+ if(stress==NULL) {
+ if(verify)
+ stress= R.vertnodes[nr].stress= MEM_mallocN(256*RE_STRESS_ELEMS*sizeof(float), "stress table");
+ else
+ return NULL;
+ }
+ return stress + (ver->index & 255)*RE_STRESS_ELEMS;
+}
+
+/* this one callocs! */
+float *RE_vertren_get_rad(VertRen *ver, int verify)
+{
+ float *rad;
+ int nr= ver->index>>8;
+
+ rad= R.vertnodes[nr].rad;
+ if(rad==NULL) {
+ if(verify)
+ rad= R.vertnodes[nr].rad= MEM_callocN(256*RE_RAD_ELEMS*sizeof(float), "rad table");
+ else
+ return NULL;
+ }
+ return rad + (ver->index & 255)*RE_RAD_ELEMS;
+}
+
+float *RE_vertren_get_strand(VertRen *ver, int verify)
+{
+ float *strand;
+ int nr= ver->index>>8;
+
+ strand= R.vertnodes[nr].strand;
+ if(strand==NULL) {
+ if(verify)
+ strand= R.vertnodes[nr].strand= MEM_mallocN(256*RE_STRAND_ELEMS*sizeof(float), "strand table");
else
return NULL;
}
- sticky+= (nr & 255)*RE_STICKY_ELEMS;
+ return strand + (ver->index & 255)*RE_STRAND_ELEMS;
}
-#endif
+
+float *RE_vertren_get_tangent(VertRen *ver, int verify)
+{
+ float *tangent;
+ int nr= ver->index>>8;
+
+ tangent= R.vertnodes[nr].tangent;
+ if(tangent==NULL) {
+ if(verify)
+ tangent= R.vertnodes[nr].tangent= MEM_mallocN(256*RE_TANGENT_ELEMS*sizeof(float), "tangent table");
+ else
+ return NULL;
+ }
+ return tangent + (ver->index & 255)*RE_TANGENT_ELEMS;
+}
+
VertRen *RE_findOrAddVert(int nr)
{
- VertRen *v, **temp;
- static int rblovelen=TABLEINITSIZE;
+ VertTableNode *temp;
+ VertRen *v;
+ static int rvertnodeslen=TABLEINITSIZE;
int a;
if(nr<0) {
printf("error in findOrAddVert: %d\n",nr);
- return R.blove[0];
+ return R.vertnodes[0].vert;
}
a= nr>>8;
- if (a>=rblovelen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */
- //printf("Allocating %i more vert groups. %i total.\n",
- // TABLEINITSIZE, rblovelen+TABLEINITSIZE );
- temp=R.blove;
- R.blove=(VertRen**)MEM_callocN(sizeof(void*)*(rblovelen+TABLEINITSIZE) , "Blove");
- memcpy(R.blove, temp, rblovelen*sizeof(void*));
- memset(&(R.blove[rblovelen]), 0, TABLEINITSIZE*sizeof(void*));
- rblovelen+=TABLEINITSIZE;
+ if (a>=rvertnodeslen-1){ /* Need to allocate more columns..., and keep last element NULL for free loop */
+ temp= R.vertnodes;
+
+ R.vertnodes= MEM_mallocN(sizeof(VertTableNode)*(rvertnodeslen+TABLEINITSIZE) , "vertnodes");
+ memcpy(R.vertnodes, temp, rvertnodeslen*sizeof(VertTableNode));
+ memset(R.vertnodes+rvertnodeslen, 0, TABLEINITSIZE*sizeof(VertTableNode));
+
+ rvertnodeslen+=TABLEINITSIZE;
MEM_freeN(temp);
}
- v= R.blove[a];
- if(v==0) {
+ v= R.vertnodes[a].vert;
+ if(v==NULL) {
+ int i;
+
v= (VertRen *)MEM_callocN(256*sizeof(VertRen),"findOrAddVert");
- R.blove[a]= v;
+ R.vertnodes[a].vert= v;
+
+ for(i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) {
+ v[a].index= i;
+ }
}
v+= (nr & 255);
return v;
}
+void RE_free_vertex_tables(void)
+{
+ int a=0;
+
+ while(R.vertnodes[a].vert) {
+ if(R.vertnodes[a].vert) {
+ MEM_freeN(R.vertnodes[a].vert);
+ R.vertnodes[a].vert= NULL;
+
+ if(R.vertnodes[a].rad) {
+ MEM_freeN(R.vertnodes[a].rad);
+ R.vertnodes[a].rad= NULL;
+ }
+ if(R.vertnodes[a].sticky) {
+ MEM_freeN(R.vertnodes[a].sticky);
+ R.vertnodes[a].sticky= NULL;
+ }
+ if(R.vertnodes[a].strand) {
+ MEM_freeN(R.vertnodes[a].strand);
+ R.vertnodes[a].strand= NULL;
+ }
+ if(R.vertnodes[a].tangent) {
+ MEM_freeN(R.vertnodes[a].tangent);
+ R.vertnodes[a].tangent= NULL;
+ }
+ if(R.vertnodes[a].stress) {
+ MEM_freeN(R.vertnodes[a].stress);
+ R.vertnodes[a].stress= NULL;
+ }
+ }
+ a++;
+ }
+}
+
+/* only once, on startup */
+void RE_init_vertex_tables(void)
+{
+ R.vertnodes= MEM_callocN(sizeof(VertTableNode)*TABLEINITSIZE , "vertnodes");
+}
+
/* ------------------------------------------------------------------------ */
int rblohalen=TABLEINITSIZE;
HaloRen *RE_findOrAddHalo(int nr)
diff --git a/source/blender/render/intern/source/texture.c b/source/blender/render/intern/source/texture.c
index 344957608fe..38936ec89fa 100644
--- a/source/blender/render/intern/source/texture.c
+++ b/source/blender/render/intern/source/texture.c
@@ -1462,6 +1462,15 @@ void do_material_tex(ShadeInput *shi)
dy[0]= shi->dystrand;
dy[1]= dy[2]= 0.0f;
}
+ else if(mtex->texco==TEXCO_STRESS) {
+ co= tempvec; dx= dxt; dy= dyt;
+ co[0]= shi->stress;
+ co[1]= co[2]= 0.0f;
+ dx[0]= 0.0f;
+ dx[1]= dx[2]= 0.0f;
+ dy[0]= 0.0f;
+ dy[1]= dy[2]= 0.0f;
+ }
else continue; // can happen when texco defines disappear and it renders old files
/* de pointer defines if bumping happens */
diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c
index f7480c4cb2f..368acfe1a41 100644
--- a/source/blender/render/intern/source/zbuf.c
+++ b/source/blender/render/intern/source/zbuf.c
@@ -2559,9 +2559,7 @@ static void set_faces_raycountflag(void)
maxy= (float)(2*Amaxy-R.recty+2)/(float)R.recty;
for(v=0; v<R.totvert; v++) {
- if((v & 255)==0) {
- ver= R.blove[v>>8];
- }
+ if((v & 255)==0) ver= RE_findOrAddVert(v);
else ver++;
wco= ver->ho[3];