[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12465] branches/qdune/blender: Orco coords on subd.meshes finally work correctly.

Alfredo de Greef eeshlo at yahoo.com
Sun Nov 4 01:53:38 CET 2007


Revision: 12465
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12465
Author:   eeshlo
Date:     2007-11-04 01:53:37 +0100 (Sun, 04 Nov 2007)

Log Message:
-----------
Orco coords on subd.meshes finally work correctly.
They still do not *look* the same as in Blender though,
because QD still only linearly interpolates values.
Changed test of normal/displace flag again, since normals
were still being calculated if the displacement texture
was also used for other purposes. Now bumpnormals are only
calculated if bumpmapping is in fact enabled ('nor' button).
This will still cause severe artifacts in some cases.
If you use displacement, do not enable the same channel
for bumpmapping as well.
Also a fixed a bug that could cause segfaults because
of using a NULL pointer.

Modified Paths:
--------------
    branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp
    branches/qdune/blender/source/blender/render/intern/source/convertblender.c
    branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
    branches/qdune/blender/source/blender/render/intern/source/texture.c

Modified: branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp
===================================================================
--- branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp	2007-11-03 21:00:19 UTC (rev 12464)
+++ branches/qdune/blender/extern/qdune/primitives/CCSubdivision.cpp	2007-11-04 00:53:37 UTC (rev 12465)
@@ -495,6 +495,7 @@
 		array_t<Vector> pvedV;  // edge values of all varying vector primvars
 		if (OF->pv) {
 			const unsigned int vs = verts.size();
+			const float ctd = 1.f/float(vs);
 			sklist_t<vardata_t*>& varlist = const_cast<PrimVars*>(OF->pv)->pvars;
 			vardata_t** vdt = varlist.first();
 			while (vdt) {
@@ -508,7 +509,7 @@
 							tmped[fvi] = 0.5f*(ofa[fvi] + ofa[(fvi + 1) % vs]);
 							ct += ofa[fvi];
 						}
-						pvctF.push_back(ct / float(vs));
+						pvctF.push_back(ct*ctd);
 						for (unsigned int fvi=0; fvi<vs; ++fvi)
 							pvedF.push_back(tmped[fvi]);
 					}
@@ -522,7 +523,7 @@
 							tmped[fvi][2] = 0.5f*(ova[fvi][2] + ova[(fvi + 1) % vs][2]);
 							addVVV(ct,  ct, ova[fvi]);
 						}
-						divVVF(ct, ct, float(vs));
+						mulVVF(ct, ct, ctd);
 						pvctV.push_back(Vector(ct));
 						for (unsigned int fvi=0; fvi<vs; ++fvi)
 							pvedV.push_back(Vector(tmped[fvi]));
@@ -569,7 +570,7 @@
 				const int sti = st_rot ? ((int)ei - 1) : 0;
 				sklist_t<vardata_t*>& varlist = const_cast<PrimVars*>(OF->pv)->pvars;
 				vardata_t** vdt = varlist.first();
-				int pvidx = 0;
+				int pvidxF = 0, pvidxV = 0;
 				while (vdt) {
 					decParam_t& dp = (*vdt)->param;
 					vardata_t* nvdt = NULL;
@@ -597,27 +598,28 @@
 							nvdt = new vardata_t(ndp);
 							RtFloat *nfa = new RtFloat[4];
 							const RtFloat *ofa = (*vdt)->data;
-							nfa[sti & 3] = pvctF[pvidx];
-							nfa[(sti + 1) & 3] = pvedF[pvidx*vs + ei];
+							nfa[sti & 3] = pvctF[pvidxF];
+							nfa[(sti + 1) & 3] = pvedF[pvidxF*vs + ei];
 							nfa[(sti + 2) & 3] = ofa[(ei + 1) % mv];
-							nfa[(sti + 3) & 3] = pvedF[pvidx*vs +((ei + 1) % num_e)];
+							nfa[(sti + 3) & 3] = pvedF[pvidxF*vs +((ei + 1) % num_e)];
 							nvdt->data = nfa;
+							pvidxF++;
 						}
 						else if (dp.ct_flags & DT_FLOAT3MASK) {
 							decParam_t ndp = {dp.ct_flags, 1, 12};
 							nvdt = new vardata_t(ndp);
 							RtVector *nva = new RtVector[4];
 							const RtVector *ova = reinterpret_cast<RtVector*>((*vdt)->data);
-							vcopy(nva[sti & 3], pvctV[pvidx].asArray());
-							vcopy(nva[(sti + 1) & 3], pvedV[pvidx*vs + ei].asArray());
+							vcopy(nva[sti & 3], pvctV[pvidxV].asArray());
+							vcopy(nva[(sti + 1) & 3], pvedV[pvidxV*vs + ei].asArray());
 							vcopy(nva[(sti + 2) & 3], ova[(ei + 1) % mv]);
-							vcopy(nva[(sti + 3) & 3], pvedV[pvidx*vs + ((ei + 1) % num_e)].asArray());
+							vcopy(nva[(sti + 3) & 3], pvedV[pvidxV*vs + ((ei + 1) % num_e)].asArray());
 							nvdt->data = reinterpret_cast<float*>(nva);
+							pvidxV++;
 						}
 					}
 					if (nvdt) nf->pv->pvars.insert(varlist.getName(), nvdt);
 					vdt = varlist.next();
-					pvidx++;
 				}
 			}
 			// set face ptrs in vert_list

Modified: branches/qdune/blender/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/convertblender.c	2007-11-03 21:00:19 UTC (rev 12464)
+++ branches/qdune/blender/source/blender/render/intern/source/convertblender.c	2007-11-04 00:53:37 UTC (rev 12465)
@@ -1254,11 +1254,9 @@
 
 	if (re->r.renderer == R_QDUNE)	{
 		// need vertex normals for qdune renderer
-		// For now, use the state of the flag of the first face in the mesh,
-		// but really should know per face/vertex if it is smooth.
-		// (face has smooth flag, but since vertex normals are added in add_vertex(),
-		//  it needs a smooth flag or access to corresponding face, but has neither currently)
-		rmesh.use_vertex_normals = ((me->mface->flag & ME_SMOOTH) != 0);
+		// For now, use the state of the flag of the first face in the mesh
+		// bug: mface can be NULL
+		rmesh.use_vertex_normals = me->mface ? ((me->mface->flag & ME_SMOOTH) != 0) : rmesh.use_fluid_normals;
 	}
 	else
 		rmesh.use_vertex_normals= rmesh.use_fluid_normals;
@@ -1269,7 +1267,7 @@
 
 	/* create orco and derivedmesh */
 	if(!only_verts && need_orco)
-		orco = get_object_orco(re, ob, NULL, (re->r.renderer == R_QDUNE) ? 1 : rmesh.do_subsurf);
+		orco = get_object_orco(re, ob, NULL, rmesh.do_subsurf);
 
 	if(rmesh.need_stress) {
 		mesh_get_texspace(me, loc, NULL, size);

Modified: branches/qdune/blender/source/blender/render/intern/source/qdinterface.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/qdinterface.c	2007-11-03 21:00:19 UTC (rev 12464)
+++ branches/qdune/blender/source/blender/render/intern/source/qdinterface.c	2007-11-04 00:53:37 UTC (rev 12465)
@@ -215,6 +215,7 @@
 
 	P= &ppoly->P[ppoly->totvert*3];
 	VECCOPY(P, vertex->co);
+
 	if (mesh->use_vertex_normals  && (!mesh->do_subsurf)) {
 		No = &ppoly->No[ppoly->totvert*3];
 		VECCOPY(No, vertex->n);

Modified: branches/qdune/blender/source/blender/render/intern/source/texture.c
===================================================================
--- branches/qdune/blender/source/blender/render/intern/source/texture.c	2007-11-03 21:00:19 UTC (rev 12464)
+++ branches/qdune/blender/source/blender/render/intern/source/texture.c	2007-11-04 00:53:37 UTC (rev 12465)
@@ -1490,7 +1490,7 @@
 			/* de pointer defines if bumping happens */
 			if(mtex->mapto & (MAP_NORM|MAP_DISPLACE|MAP_WARP)) {
 				/* QDUNE: do not calculate normal if only displacement is needed */
-				if ((R.r.renderer == R_QDUNE) && (mtex->mapto == MAP_DISPLACE))
+				if ((R.r.renderer == R_QDUNE) && ((mtex->mapto & MAP_NORM) == 0))
 					texres.nor= NULL;
 				else {
 					texres.nor= norvec;





More information about the Bf-blender-cvs mailing list