[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12388] branches/qdune/blender: Added initial support for strand texture coordinates,
Alfredo de Greef
eeshlo at yahoo.com
Thu Oct 25 07:46:07 CEST 2007
Revision: 12388
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12388
Author: eeshlo
Date: 2007-10-25 07:46:07 +0200 (Thu, 25 Oct 2007)
Log Message:
-----------
Added initial support for strand texture coordinates,
but doesn't quite work correctly yet.
With the exception of multi-uv & orco coords on subd.meshes,
and orco coords on strands, most texture mapping modes 'should' now work.
Modified Paths:
--------------
branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp
branches/qdune/blender/extern/qdune/core/Camera.cpp
branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
Modified: branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp 2007-10-24 21:51:49 UTC (rev 12387)
+++ branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp 2007-10-25 05:46:07 UTC (rev 12388)
@@ -51,6 +51,8 @@
int a, i, n, texco, mode, xdim, ydim, matidx;
ShadeInput shi;
ShadeResult shr;
+ RtVector *dxno = NULL, *dyno = NULL;
+ RtFloat *dxstrand = NULL, *dystrand = NULL;
material = (RtFloat*)grid->findVariable("material");
matidx = (material)? (int)*material: 0;
@@ -58,7 +60,8 @@
mat = (Material*)blender_material[matidx];
n = grid->get_nverts();
- du = grid->get_du();
+ bool curvegrid = (grid->gtype == MicroPolygonGrid::G_CURVES);
+ du = curvegrid ? 1.f : grid->get_du();
dv = grid->get_dv();
xdim = grid->get_xdim();
ydim = grid->get_ydim();
@@ -75,7 +78,8 @@
dPdu = (RtVector*)grid->findVariable("dPdu");
dPdv = (RtVector*)grid->findVariable("dPdv");
- bool curvegrid = (grid->gtype == MicroPolygonGrid::G_CURVES);
+ RtFloat* strandco = grid->findVariable("strandco");
+
blenderShadeInit(BLENDER_THREAD, &shi, &shr, blender_object,
(curvegrid && (mat->mode & MA_TANGENT_STR)));
@@ -94,7 +98,7 @@
/* get texture coordinate variables */
if(texco & TEXCO_ORCO) {
- orco = (float(*)[3])grid->findVariable("orco");
+ orco = (RtPoint*)grid->findVariable("orco");
if(orco && shi.osatex) {
orcodu = new RtVector[n];
@@ -105,6 +109,13 @@
}
}
+ if ((texco & TEXCO_STRAND) and strandco) {
+ dxstrand = new RtFloat[n];
+ dystrand = new RtFloat[n];
+ grid->DuF(dxstrand, strandco);
+ grid->DvF(dystrand, strandco);
+ }
+
/*
memset(uv, 0, sizeof(RtVector*)*8);
memset(uvdu, 0, sizeof(RtVector*)*8);
@@ -169,16 +180,18 @@
if(texco & TEXCO_REFL) {
if(shi.osatex) {
- Idu = new RtVector[n];
- Idv = new RtVector[n];
-
- grid->DuV(Idu, I);
- grid->DvV(Idv, I);
+ Idu = new RtVector[n], Idv = new RtVector[n];
+ RtVector* tmpI = new RtVector[n];
+ for (int i=0; i<n; ++i)
+ vnormalize(tmpI[i], I[i]);
+ grid->DuV(Idu, tmpI);
+ grid->DvV(Idv, tmpI);
+ delete[] tmpI;
}
}
+ Camera& cam = State::Instance()->projcam;
if(texco & TEXCO_WINDOW) {
- Camera& cam = State::Instance()->projcam;
win= new RtVector[n];
@@ -200,8 +213,20 @@
}
}
+ if (shi.osatex and (texco & TEXCO_NORM)) {
+ RtNormal* tmpN = new RtNormal[n];
+ for (int i=0; i<n; ++i) {
+ tmpN[i][0] = -N[i][0], tmpN[i][1] = -N[i][1], tmpN[i][2] = N[i][2];
+ vnormalize(tmpN[i], tmpN[i]);
+ }
+ dxno = new RtVector[n], dyno = new RtVector[n];
+ grid->DuV(dxno, tmpN);
+ grid->DvV(dyno, tmpN);
+ delete[] tmpN;
+ }
+
if(texco & TEXCO_STICKY) {
- sticky = (float(*)[3])grid->findVariable("sticky");
+ sticky = (RtVector*)grid->findVariable("sticky");
if(shi.osatex && sticky) {
stickydu = new RtVector[n];
stickydv = new RtVector[n];
@@ -246,6 +271,15 @@
vcopy(shi.vno, shi.vn);
+ if (curvegrid and strandco and (texco & TEXCO_STRAND)) {
+ // strand texture coordinate
+ shi.strand = strandco[i];
+ if (shi.osatex) {
+ shi.dxstrand = dxstrand[i]*du;
+ shi.dystrand = dystrand[i]*dv;
+ }
+ }
+
/* tangent */
if(mode & (MA_TANGENT_V|MA_NORMAP_TANG))
vnormalize(shi.tang, dPdv[i]);
@@ -350,13 +384,17 @@
shi.orn[0]= -shi.vn[0];
shi.orn[1]= -shi.vn[1];
shi.orn[2]= -shi.vn[2];
+ if (shi.osatex) {
+ mulVVF(shi.dxno, dxno[i], du);
+ mulVVF(shi.dyno, dyno[i], dv);
+ }
}
/* refl */
if(texco & TEXCO_REFL) {
if(shi.osatex) {
- shi.dxview= Idu[i][0];
- shi.dyview= Idv[i][1];
+ shi.dxview= Idu[i][0]*du;
+ shi.dyview= Idv[i][1]*dv;
}
}
@@ -364,11 +402,10 @@
if(texco & TEXCO_WINDOW) {
vcopy(shi.winco, win[i]);
if(shi.osatex) {
- /* TODO: seems too blurry? */
- shi.dxwin[0]= windu[i][0];
- shi.dxwin[1]= windu[i][1];
- shi.dywin[0]= windv[i][0];
- shi.dywin[1]= windv[i][1];
+ shi.dxwin[0]= windu[i][0]*du;
+ shi.dxwin[1]= windu[i][1]*du;
+ shi.dywin[0]= windv[i][0]*dv;
+ shi.dywin[1]= windv[i][1]*dv;
}
}
@@ -423,6 +460,10 @@
if(windv) delete [] windv;
if(stickydu) delete [] stickydu;
if(stickydv) delete [] stickydv;
+ if(dxno) delete [] dxno;
+ if(dyno) delete [] dyno;
+ if(dxstrand) delete [] dxstrand;
+ if(dystrand) delete [] dystrand;
for(a=0; a<8; a++) {
if (uv_s_du[a]) {
Modified: branches/qdune/blender/extern/qdune/core/Camera.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/core/Camera.cpp 2007-10-24 21:51:49 UTC (rev 12387)
+++ branches/qdune/blender/extern/qdune/core/Camera.cpp 2007-10-25 05:46:07 UTC (rev 12388)
@@ -80,11 +80,10 @@
w.z);
}
// perspective, cam2ras[0/1][3] always zero
- Point3 p(cam2ras[0][0]*w.x + cam2ras[0][1]*w.y + cam2ras[0][2]*w.z,
- cam2ras[1][0]*w.x + cam2ras[1][1]*w.y + cam2ras[1][2]*w.z,
- w.z);
- if (w.z != 0.f) { const float t = 1.f/w.z; p.x *= t; p.y *= t; }
- return p;
+ const float zd = (w.z != 0.f) ? (1.f/w.z) : 1.f;
+ return Point3((cam2ras[0][0]*w.x + cam2ras[0][1]*w.y)*zd + cam2ras[0][2],
+ (cam2ras[1][0]*w.x + cam2ras[1][1]*w.y)*zd + cam2ras[1][2],
+ w.z);
}
ray_t Camera::eyeRay(float x, float y)
Modified: branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/qdinterface.c 2007-10-24 21:51:49 UTC (rev 12387)
+++ branches/qdune/blender/source/blender/render/intern/source/qdinterface.c 2007-10-25 05:46:07 UTC (rev 12388)
@@ -69,6 +69,7 @@
float *width;
int *nverts;
float *material;
+ float *strandco;
int totpoint;
int totcurve;
@@ -134,6 +135,7 @@
curve->P= MEM_callocN(sizeof(float)*3*mesh->maxcurve*mesh->maxcurvepoint, "QDCurvesP");
curve->width= MEM_callocN(sizeof(float)*mesh->maxcurve*maxseg, "QDCurvesW");
curve->nverts= MEM_callocN(sizeof(int)*mesh->maxcurve, "QDCurvesNVerts");
+ curve->strandco= MEM_callocN(sizeof(int)*mesh->maxcurve*maxseg, "QDCurvesStrandCo");
if(object->totmaterial > 0)
curve->material= MEM_callocN(sizeof(float)*mesh->maxcurve, "QDPCurveMat");
@@ -363,6 +365,7 @@
width= VecLength(cross)*cp->width;
curve->width[curve->totwidth]= (w != 0.0f)? width/w: 1.0f;
+ curve->strandco[curve->totwidth]= cp->strandco;
curve->totwidth++;
}
@@ -482,6 +485,10 @@
params[n]= curve->width;
n++;
+ tokens[n]= "varying float strandco";
+ params[n]= curve->strandco;
+ n++;
+
if(curve->material) {
tokens[n]= "uniform float material";
params[n]= curve->material;
@@ -496,6 +503,7 @@
if(curve->width) MEM_freeN(curve->width);
if(curve->nverts) MEM_freeN(curve->nverts);
if(curve->material) MEM_freeN(curve->material);
+ if(curve->strandco) MEM_freeN(curve->strandco);
RiAttributeEnd();
RiTransformEnd();
More information about the Bf-blender-cvs
mailing list