[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12368] branches/qdune/blender: Some more texture coordinates work better now, global/object, possibly
Alfredo de Greef
eeshlo at yahoo.com
Wed Oct 24 04:50:39 CEST 2007
Revision: 12368
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12368
Author: eeshlo
Date: 2007-10-24 04:50:37 +0200 (Wed, 24 Oct 2007)
Log Message:
-----------
Some more texture coordinates work better now, global/object, possibly
some others as well. Cubemapping now works too.
Uv coords used with subd.meshes should also work better now,
so long as only one uv texture at a time is used.
Multi-uv texture does not work properly yet on subsurf meshes.
Although results probably looks better than old uvtex results.
Current code is just a quick temporary hack.
Modified Paths:
--------------
branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp
branches/qdune/blender/extern/qdune/core/Mathutil.h
branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp
branches/qdune/blender/extern/qdune/primitives/Primitive.cpp
branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
branches/qdune/blender/source/blender/render/intern/source/shadeinput.c
Modified: branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp 2007-10-23 22:51:50 UTC (rev 12367)
+++ branches/qdune/blender/extern/qdune/blender/BlenderShader.cpp 2007-10-24 02:50:37 UTC (rev 12368)
@@ -44,7 +44,8 @@
RtVector *win = NULL, *windu = NULL, *windv = NULL;
RtVector *sticky = NULL, *stickydu = NULL, *stickydv = NULL;
RtFloat *stress = NULL;
- RtVector *uv[8], *uvdu[8], *uvdv[8];
+ //RtVector *uv[8], *uvdu[8], *uvdv[8];
+ RtFloat *uv_s[8], *uv_t[8], *uv_s_du[8], *uv_s_dv[8], *uv_t_du[8], *uv_t_dv[8];
float du, dv, *material;
char uvtoken[128];
int a, i, n, texco, mode, xdim, ydim, matidx;
@@ -61,6 +62,7 @@
dv = grid->get_dv();
xdim = grid->get_xdim();
ydim = grid->get_ydim();
+
float uvl[4];
grid->getParent()->get_uvlim(uvl);
@@ -73,8 +75,9 @@
dPdu = (RtVector*)grid->findVariable("dPdu");
dPdv = (RtVector*)grid->findVariable("dPdv");
+ bool curvegrid = (grid->gtype == MicroPolygonGrid::G_CURVES);
blenderShadeInit(BLENDER_THREAD, &shi, &shr, blender_object,
- (xdim==0 && (mat->mode & MA_TANGENT_STR)));
+ (curvegrid && (mat->mode & MA_TANGENT_STR)));
/* shade_input_set_triangle_i */
shi.mat= shi.mat_override? shi.mat_override: mat;
@@ -102,6 +105,7 @@
}
}
+ /*
memset(uv, 0, sizeof(RtVector*)*8);
memset(uvdu, 0, sizeof(RtVector*)*8);
memset(uvdv, 0, sizeof(RtVector*)*8);
@@ -122,7 +126,44 @@
}
}
}
+ */
+ memset(uv_s, 0, sizeof(RtFloat*)*8);
+ memset(uv_t, 0, sizeof(RtFloat*)*8);
+ memset(uv_s_du, 0, sizeof(RtFloat*)*8);
+ memset(uv_s_dv, 0, sizeof(RtFloat*)*8);
+ memset(uv_t_du, 0, sizeof(RtFloat*)*8);
+ memset(uv_t_dv, 0, sizeof(RtFloat*)*8);
+ if(texco & TEXCO_UV) {
+ for(a=0; a<8; a++) {
+ // very temporary hack, so that uv works when using one uv tex. (subd.mesh currently only knows 's' & 't' names)
+ if (a == 0)
+ sprintf(uvtoken, "s");
+ else
+ sprintf(uvtoken, "s%d", a);
+ uv_s[a] = grid->findVariable(uvtoken);
+ if (a == 0)
+ sprintf(uvtoken, "t");
+ else
+ sprintf(uvtoken, "t%d", a);
+ uv_t[a] = grid->findVariable(uvtoken);
+ if ((uv_s[a] == NULL) || (uv_t[a] == NULL))
+ break;
+
+ if(shi.osatex) {
+ uv_s_du[a] = new RtFloat[n];
+ uv_s_dv[a] = new RtFloat[n];
+ uv_t_du[a] = new RtFloat[n];
+ uv_t_dv[a] = new RtFloat[n];
+
+ grid->DuF(uv_s_du[a], uv_s[a]);
+ grid->DvF(uv_s_dv[a], uv_s[a]);
+ grid->DuF(uv_t_du[a], uv_t[a]);
+ grid->DvF(uv_t_dv[a], uv_t[a]);
+ }
+ }
+ }
+
if(texco & TEXCO_STRESS)
stress = (float*)grid->findVariable("stress");
@@ -173,7 +214,7 @@
/* loop over each micropolygon grid vertex */
for (i=0; i<n; i++) {
/* shadeinput_set_normals */
- if(xdim==0 && mode & MA_TANGENT_STR)
+ if(curvegrid && mode & MA_TANGENT_STR)
vnormalize(nor, dPdv[i]);
else
vnormalize(nor, N[i]);
@@ -182,13 +223,9 @@
nor[1]= -nor[1];
nor[2]= nor[2];
- shi.facenor[0]= nor[0];
- shi.facenor[1]= nor[1];
- shi.facenor[2]= nor[2];
+ vcopy(shi.facenor, nor);
- shi.orignor[0]= shi.facenor[0];
- shi.orignor[1]= shi.facenor[1];
- shi.orignor[2]= shi.facenor[2];
+ vcopy(shi.orignor, shi.facenor);
/* TODO if (vlr->noflag & R_FLIPPED_NO) { */
/* shade_input_set_viewco */
@@ -202,56 +239,32 @@
shi.co[1]= P[i][1];
shi.co[2]= -P[i][2];
- shi.dxco[0]= dPdu[i][0];
- shi.dxco[1]= dPdu[i][1];
- shi.dxco[2]= dPdu[i][2];
+ mulVVF(shi.dxco, dPdu[i], du);
+ mulVVF(shi.dyco, dPdv[i], dv);
- shi.dyco[0]= dPdv[i][0];
- shi.dyco[1]= dPdv[i][1];
- shi.dyco[2]= dPdv[i][2];
+ vcopy(shi.vn, nor);
- shi.vn[0]= nor[0];
- shi.vn[1]= nor[1];
- shi.vn[2]= nor[2];
+ vcopy(shi.vno, shi.vn);
- shi.vno[0]= shi.vn[0];
- shi.vno[1]= shi.vn[1];
- shi.vno[2]= shi.vn[2];
-
/* tangent */
if(mode & (MA_TANGENT_V|MA_NORMAP_TANG))
vnormalize(shi.tang, dPdv[i]);
/* texture coordinates */
if((texco & TEXCO_ORCO) && orco) {
- shi.lo[0]= orco[i][0];
- shi.lo[1]= orco[i][1];
- shi.lo[2]= orco[i][2];
-
+ vcopy(shi.lo, orco[i]);
if(shi.osatex) {
- shi.dxlo[0]= orcodu[i][0]*du;
- shi.dxlo[1]= orcodu[i][1]*du;
- shi.dxlo[2]= orcodu[i][2]*du;
-
- shi.dylo[0]= orcodv[i][0]*dv;
- shi.dylo[1]= orcodv[i][1]*dv;
- shi.dylo[2]= orcodv[i][2]*dv;
+ mulVVF(shi.dxlo, orcodu[i], du);
+ mulVVF(shi.dylo, orcodv[i], dv);
}
}
/* global coordinates */
if(texco & TEXCO_GLOB) {
- shi.gl[0]= shi.co[0];
- shi.gl[1]= shi.co[1];
- shi.gl[2]= shi.co[2];
+ vcopy(shi.gl, shi.co);
if(shi.osatex) {
- shi.dxgl[0]= shi.dxco[0];
- shi.dxgl[1]= shi.dxco[1];
- shi.dxgl[2]= shi.dxco[2];
-
- shi.dygl[0]= shi.dyco[0];
- shi.dygl[1]= shi.dyco[1];
- shi.dygl[2]= shi.dyco[2];
+ vcopy(shi.dxgl, shi.dxco);
+ vcopy(shi.dygl, shi.dyco);
}
}
@@ -259,6 +272,7 @@
if(texco & TEXCO_UV) {
shi.totuv= 0;
+ /*
for(a=0; a<8; a++) {
if(uv[a]) {
ShadeInputUV *suv= &shi.uv[a];
@@ -281,7 +295,30 @@
}
}
}
+ */
+ for(a=0; a<8; a++) {
+ if (uv_s[a] && uv_t[a]) {
+ ShadeInputUV *suv = &shi.uv[a];
+ shi.totuv++;
+ suv->name= "";
+
+ suv->uv[0]= -1.0f + 2.0f*uv_s[a][i];
+ suv->uv[1]= -1.0f + 2.0f*uv_t[a][i];
+ suv->uv[2]= 0.0f;
+
+ if(shi.osatex) {
+ suv->dxuv[0]= 2.0f*uv_s_du[a][i]*du;
+ suv->dxuv[1]= 2.0f*uv_t_du[a][i]*du;
+ suv->dxuv[2]= 0.0f;
+
+ suv->dyuv[0]= 2.0f*uv_s_dv[a][i]*dv;
+ suv->dyuv[1]= 2.0f*uv_t_dv[a][i]*dv;
+ suv->dyuv[2]= 0.0f;
+ }
+ }
+ }
+
if(shi.totuv == 0) {
ShadeInputUV *suv= &shi.uv[0];
float u, v;
@@ -289,8 +326,8 @@
u= (i % (xdim+1))/(float)xdim;
v= (i / (xdim+1))/(float)ydim;
+ suv->uv[0]= 2.f*((uvl[2] + v*(uvl[3] - uvl[2])) + 0.5f);
suv->uv[1]= 2.f - 2.f*((uvl[0] + u*(uvl[1] - uvl[0])) + 0.5f);
- suv->uv[0]= 2.f*((uvl[2] + v*(uvl[3] - uvl[2])) + 0.5f);
suv->uv[2]= 0.0f;
if(mode & MA_FACETEXTURE) {
@@ -325,9 +362,7 @@
/* win */
if(texco & TEXCO_WINDOW) {
- shi.winco[0]= win[i][0];
- shi.winco[1]= win[i][1];
- shi.winco[2]= win[i][2];
+ vcopy(shi.winco, win[i]);
if(shi.osatex) {
/* TODO: seems too blurry? */
shi.dxwin[0]= windu[i][0];
@@ -390,10 +425,14 @@
if(stickydv) delete [] stickydv;
for(a=0; a<8; a++) {
- if(uvdu[a]) {
- delete [] uvdu[a];
- delete [] uvdv[a];
+ if (uv_s_du[a]) {
+ delete [] uv_s_du[a];
+ delete [] uv_s_dv[a];
}
+ if (uv_t_du[a]) {
+ delete [] uv_t_du[a];
+ delete [] uv_t_dv[a];
+ }
}
}
Modified: branches/qdune/blender/extern/qdune/core/Mathutil.h
===================================================================
--- branches/qdune/blender/extern/qdune/core/Mathutil.h 2007-10-23 22:51:50 UTC (rev 12367)
+++ branches/qdune/blender/extern/qdune/core/Mathutil.h 2007-10-24 02:50:37 UTC (rev 12368)
@@ -242,6 +242,12 @@
r = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
+// convenience function
+inline RtVoid vcopy(RtVector r, const RtVector v)
+{
+ r[0] = v[0], r[1] = v[1], r[2] = v[2];
+}
+
inline RtVoid vnormalize(RtVector r, const RtVector v)
{
RtFloat d = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
Modified: branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp 2007-10-23 22:51:50 UTC (rev 12367)
+++ branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp 2007-10-24 02:50:37 UTC (rev 12368)
@@ -2032,8 +2032,9 @@
g.initVars(std_dice);
float *s_grid = NULL, *t_grid = NULL;
if (have_st) {
- s_grid = g.findVariable("s"), t_grid = g.findVariable("t");
- assert((s_grid!=NULL) && (t_grid!=NULL));
+ //s_grid = g.findVariable("s"), t_grid = g.findVariable("t");
+ //assert((s_grid!=NULL) && (t_grid!=NULL));
+ s_grid = g.addVariable("s"), t_grid = g.addVariable("t");
idx = 0;
for (vg=0; vg<=ydim; ++vg) {
for (ug=0; ug<=xdim; ++ug, ++idx) {
@@ -2100,6 +2101,9 @@
}
}
}
+
+ // all others, linear only still
+ Primitive::linear_dice(g);
}
//------------------------------------------------------------------------------
Modified: branches/qdune/blender/extern/qdune/primitives/Primitive.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/primitives/Primitive.cpp 2007-10-23 22:51:50 UTC (rev 12367)
+++ branches/qdune/blender/extern/qdune/primitives/Primitive.cpp 2007-10-24 02:50:37 UTC (rev 12368)
@@ -169,7 +169,8 @@
float uvl[4];
get_uvlim(uvl);
const float ud = uvl[1] - uvl[0], vd = uvl[3] - uvl[2];
- const float du = (xdim)? 1.f/float(xdim): 0.0f, dv = 1.f/float(ydim);
+ bool curvegrid = (g.gtype == MicroPolygonGrid::G_CURVES);
+ const float du = curvegrid ? 0.f : (1.f/float(xdim)), dv = 1.f/float(ydim);
while (vdt) {
bool varying = (((*vdt)->param.ct_flags & (SC_VARYING | SC_FACEVARYING | SC_VERTEX)) != 0);
const char* name = primvars->pvars.getName();
@@ -180,7 +181,7 @@
const RtFloat* da = (RtFloat*)(*vdt)->data;
if (varying) {
idx = 0;
- if(xdim == 0) {
+ if (curvegrid) {
for (vg=0, v=0.f; vg<=ydim; ++vg, v+=dv, ++idx)
mixf(Fgrid[idx], da[0], da[1], uvl[2] + v*vd);
}
@@ -203,7 +204,7 @@
const RtVector* da = (RtVector*)(*vdt)->data;
if (varying) {
idx = 0;
- if(xdim == 0) {
+ if (curvegrid) {
for (vg=0, v=0.f; vg<=ydim; ++vg, v+=dv, ++idx)
mixv(Vgrid[idx], da[0], da[1], uvl[2] + v*vd);
}
Modified: branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/qdinterface.c 2007-10-23 22:51:50 UTC (rev 12367)
+++ branches/qdune/blender/source/blender/render/intern/source/qdinterface.c 2007-10-24 02:50:37 UTC (rev 12368)
@@ -55,7 +55,9 @@
float *No;
float (*orco)[3];
float (*sticky)[3];
- float (*uv[8])[3];
+ //float (*uv[8])[3];
+ // temporary facevarying test, subdiv faces currently only know s/t
+ float *uv_s[8], *uv_t[8];
float *stress;
float *material;
@@ -198,6 +200,7 @@
{
}
+#if 0
static void qdune_add_face(RenderInterface *iface, RenderFace *face)
{
QDRenderContext *qdcontext= iface->context;
@@ -254,7 +257,65 @@
ppoly->totpoly++;
}
+#endif
+// temporary facevarying test, subdiv faces currently only know s/t
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list