[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20131] branches/soc-2009-jaguarandi/ source/blender:

André Pinto andresusanopinto at gmail.com
Sun May 10 23:02:59 CEST 2009


Revision: 20131
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20131
Author:   jaguarandi
Date:     2009-05-10 23:02:58 +0200 (Sun, 10 May 2009)

Log Message:
-----------

*new generic raytrace API
*Adapted octree to a more generic raytrace API
*ray shadow works (other untested stuff disabled atm)

On the scene tested the user-cpu time got from 1:24 to 1:19/20
probably because of removed callbacks or sligtly diferente memory usage

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c
    branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rendercore.c

Added Paths:
-----------
    branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c

Removed Paths:
-------------
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/raytrace.c

Modified: branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c	2009-05-10 20:53:58 UTC (rev 20130)
+++ branches/soc-2009-jaguarandi/source/blender/editors/armature/meshlaplacian.c	2009-05-10 21:02:58 UTC (rev 20131)
@@ -30,6 +30,7 @@
 
 #include <math.h>
 #include <string.h>
+#include <assert.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -105,7 +106,7 @@
 		float *p;			/* values from all p vectors */
 		float *mindist;		/* minimum distance to a bone for all vertices */
 		
-		RayTree *raytree;	/* ray tracing acceleration structure */
+		RayObject *raytree;	/* ray tracing acceleration structure */
 		MFace **vface;		/* a face that the vertex belongs to */
 	} heat;
 
@@ -394,77 +395,31 @@
 #define DISTANCE_EPSILON	1e-4f
 
 /* Raytracing for vertex to bone visibility */
-
-static LaplacianSystem *HeatSys = NULL;
-
-static void heat_ray_coords_func(RayFace *face, float **v1, float **v2, float **v3, float **v4)
-{
-	MFace *mface= (MFace*)face;
-	float (*verts)[3]= HeatSys->heat.verts;
-
-	*v1= verts[mface->v1];
-	*v2= verts[mface->v2];
-	*v3= verts[mface->v3];
-	*v4= (mface->v4)? verts[mface->v4]: NULL;
-}
-
-static int heat_ray_check_func(Isect *is, int ob, RayFace *face)
-{
-	float *v1, *v2, *v3, *v4, nor[3];
-
-	/* don't intersect if the ray faces along the face normal */
-	heat_ray_coords_func(face, &v1, &v2, &v3, &v4);
-
-	if(v4) CalcNormFloat4(v1, v2, v3, v4, nor);
-	else CalcNormFloat(v1, v2, v3, nor);
-
-	return (INPR(nor, is->vec) < 0);
-}
-
 static void heat_ray_tree_create(LaplacianSystem *sys)
 {
 	Mesh *me = sys->heat.mesh;
-	RayTree *tree;
 	MFace *mface;
-	float min[3], max[3];
 	int a;
 
-	/* create a raytrace tree from the mesh */
-	INIT_MINMAX(min, max);
+	sys->heat.raytree = RayObject_mesh_create(me, me);
 
-	for(a=0; a<me->totvert; a++)
-		DO_MINMAX(sys->heat.verts[a], min, max);
-
-	tree= RE_ray_tree_create(64, me->totface, min, max,
-		heat_ray_coords_func, heat_ray_check_func, NULL, NULL);
-	
-	sys->heat.vface= MEM_callocN(sizeof(MFace*)*me->totvert, "HeatVFaces");
-
-	HeatSys= sys;
-
+	sys->heat.vface = MEM_callocN(sizeof(MFace*)*me->totvert, "HeatVFaces");
 	for(a=0, mface=me->mface; a<me->totface; a++, mface++) {
-		RE_ray_tree_add_face(tree, 0, mface);
-
 		sys->heat.vface[mface->v1]= mface;
 		sys->heat.vface[mface->v2]= mface;
 		sys->heat.vface[mface->v3]= mface;
 		if(mface->v4) sys->heat.vface[mface->v4]= mface;
 	}
-
-	HeatSys= NULL;
-	
-	RE_ray_tree_done(tree);
-
-	sys->heat.raytree= tree;
 }
 
 static int heat_ray_bone_visible(LaplacianSystem *sys, int vertex, int bone)
 {
 	Isect isec;
 	MFace *mface;
-	float dir[3];
+	float end[3];
 	int visible;
 
+	assert( 0 );
 	mface= sys->heat.vface[vertex];
 	if(!mface)
 		return 1;
@@ -473,22 +428,24 @@
 	memset(&isec, 0, sizeof(isec));
 	isec.mode= RE_RAY_SHADOW;
 	isec.lay= -1;
-	isec.face_last= NULL;
-	isec.faceorig= mface;
+	isec.orig.face = mface;
+	isec.skip = RE_SKIP_CULLFACE;
 
 	VECCOPY(isec.start, sys->heat.verts[vertex]);
-	PclosestVL3Dfl(isec.end, isec.start,
-		sys->heat.root[bone], sys->heat.tip[bone]);
+	PclosestVL3Dfl(end, isec.start, sys->heat.root[bone], sys->heat.tip[bone]);
 
+	VECSUB(isec.vec, end, isec.start);
+	isec.labda = 1.0f;
+
+#if 0
+	TODO
 	/* add an extra offset to the start position to avoid self intersection */
-	VECSUB(dir, isec.end, isec.start);
+	VECCOPY(dir, isec.vec);
 	Normalize(dir);
 	VecMulf(dir, 1e-5);
 	VecAddf(isec.start, isec.start, dir);
-	
-	HeatSys= sys;
-	visible= !RE_ray_tree_intersect(sys->heat.raytree, &isec);
-	HeatSys= NULL;
+#endif	
+	visible= !RayObject_raycast(sys->heat.raytree, &isec);
 
 	return visible;
 }
@@ -752,7 +709,7 @@
 	/* free */
 	if(vertsflipped) MEM_freeN(vertsflipped);
 
-	RE_ray_tree_free(sys->heat.raytree);
+	RayObject_free(sys->heat.raytree);
 	MEM_freeN(sys->heat.vface);
 
 	MEM_freeN(sys->heat.mindist);
@@ -1049,7 +1006,7 @@
 	int *varidx;
 
 	/* raytrace */
-	RayTree *raytree;
+	RayObject *raytree;
 } MeshDeformBind;
 
 /* ray intersection */
@@ -1173,7 +1130,7 @@
 static int meshdeform_intersect(MeshDeformBind *mdb, Isect *isec)
 {
 	MFace *mface;
-	float face[4][3], co[3], uvw[3], len, nor[3];
+	float face[4][3], co[3], uvw[3], len, nor[3], end[3];
 	int f, hit, is= 0, totface;
 
 	isec->labda= 1e10;
@@ -1181,6 +1138,8 @@
 	mface= mdb->cagedm->getFaceArray(mdb->cagedm);
 	totface= mdb->cagedm->getNumFaces(mdb->cagedm);
 
+	VECADDFAC( end, isec->start, isec->vec, isec->labda );
+
 	for(f=0; f<totface; f++, mface++) {
 		VECCOPY(face[0], mdb->cagecos[mface->v1]);
 		VECCOPY(face[1], mdb->cagecos[mface->v2]);
@@ -1188,26 +1147,26 @@
 
 		if(mface->v4) {
 			VECCOPY(face[3], mdb->cagecos[mface->v4]);
-			hit= meshdeform_tri_intersect(isec->start, isec->end, face[0], face[1], face[2], co, uvw);
+			hit = meshdeform_tri_intersect(isec->start, end, face[0], face[1], face[2], co, uvw);
 
 			if(hit) {
 				CalcNormFloat(face[0], face[1], face[2], nor);
 			}
 			else {
-				hit= meshdeform_tri_intersect(isec->start, isec->end, face[0], face[2], face[3], co, uvw);
+				hit= meshdeform_tri_intersect(isec->start, end, face[0], face[2], face[3], co, uvw);
 				CalcNormFloat(face[0], face[2], face[3], nor);
 			}
 		}
 		else {
-			hit= meshdeform_tri_intersect(isec->start, isec->end, face[0], face[1], face[2], co, uvw);
+			hit= meshdeform_tri_intersect(isec->start, end, face[0], face[1], face[2], co, uvw);
 			CalcNormFloat(face[0], face[1], face[2], nor);
 		}
 
 		if(hit) {
-			len= VecLenf(isec->start, co)/VecLenf(isec->start, isec->end);
+			len= VecLenf(isec->start, co)/VecLenf(isec->start, end);
 			if(len < isec->labda) {
 				isec->labda= len;
-				isec->face= mface;
+				isec->hit.face = mface;
 				isec->isect= (INPR(isec->vec, nor) <= 0.0f);
 				is= 1;
 			}
@@ -1223,20 +1182,18 @@
 	Isect isec;
 	float (*cagecos)[3];
 	MFace *mface;
-	float vert[4][3], len;
+	float vert[4][3], len, end[3];
 	static float epsilon[3]= {0, 0, 0}; //1e-4, 1e-4, 1e-4};
 
 	/* setup isec */
 	memset(&isec, 0, sizeof(isec));
 	isec.mode= RE_RAY_MIRROR; /* we want the closest intersection */
 	isec.lay= -1;
-	isec.face_last= NULL;
-	isec.faceorig= NULL;
 	isec.labda= 1e10f;
 
 	VECADD(isec.start, co1, epsilon);
-	VECADD(isec.end, co2, epsilon);
-	VECSUB(isec.vec, isec.end, isec.start);
+	VECADD(end, co2, epsilon);
+	VECSUB(isec.vec, end, isec.start);
 
 #if 0
 	/*if(RE_ray_tree_intersect(mdb->raytree, &isec)) {*/
@@ -1244,7 +1201,7 @@
 
 	if(meshdeform_intersect(mdb, &isec)) {
 		len= isec.labda;
-		mface= isec.face;
+		mface=(MFace*)isec.hit.face;
 
 		/* create MDefBoundIsect */
 		isect= BLI_memarena_alloc(mdb->memarena, sizeof(*isect));

Modified: branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-05-10 20:53:58 UTC (rev 20130)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-05-10 21:02:58 UTC (rev 20131)
@@ -22,7 +22,7 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): André Pinto.
  *
  * ***** END GPL LICENSE BLOCK *****
  * RE_raytrace.h: ray tracing api, can be used independently from the renderer. 
@@ -31,84 +31,64 @@
 #ifndef RE_RAYTRACE_H
 #define RE_RAYTRACE_H
 
-/* ray types */
-#define RE_RAY_SHADOW 0
-#define RE_RAY_MIRROR 1
-#define RE_RAY_SHADOW_TRA 2
 
-/* spatial tree for raytracing acceleration */
-typedef void RayTree;
-/* abstraction of face type */
-typedef void RayFace;
+/* Internals about raycasting structures can be found on intern/raytree.h */
+typedef struct RayObject RayObject;
+typedef struct Isect Isect;
+struct DerivedMesh;
+struct Mesh;
 
-/* object numbers above this are transformed */
-#define RE_RAY_TRANSFORM_OFFS 0x8000000
+int  RayObject_raycast(RayObject *r, Isect *i);
+void RayObject_add    (RayObject *r, RayObject *);
+void RayObject_done(RayObject *r);
+void RayObject_free(RayObject *r);
 
-/* convert from pointer to index in array and back, with offset if the
- * instance is transformed */
-#define RAY_OBJECT_SET(re, obi) \
-	((obi == NULL)? 0: \
-	((obi - (re)->objectinstance) + ((obi->flag & R_TRANSFORMED)? RE_RAY_TRANSFORM_OFFS: 0)))
+/* RayObject constructors */
+RayObject* RayObject_octree_create(int ocres, int size);
 
-#define RAY_OBJECT_GET(re, i) \
-	((re)->objectinstance + ((i >= RE_RAY_TRANSFORM_OFFS)? i-RE_RAY_TRANSFORM_OFFS: i))
+//RayObject* RayObject_derivedmesh_create(struct DerivedMesh*, void *ob);
+RayObject* RayObject_mesh_create(struct Mesh*, void *ob);
 
-
-/* struct for intersection data */
-typedef struct Isect {
-	float start[3];			/* start+vec = end, in ray_tree_intersect */
+/* Ray Intersection */
+struct Isect
+{
+	float start[3];
 	float vec[3];
-	float end[3];			
+/*	float end[3];			 - not used */
 
-	float labda, u, v;		/* distance to hitpoint, uv weights */
-
-	RayFace *face;			/* face is where to intersect with */
-	int ob;
-	RayFace *faceorig;		/* start face */
-	int oborig;
-	RayFace *face_last;		/* for shadow optimize, last intersected face */
-	int ob_last;
-
+	float labda, u, v;
+	
+	struct
+	{
+		void *ob;
+		void *face;
+/*		RayObject *obj; */
+	}
+	hit, orig;
+	
+	RayObject *last_hit;	/* last hit optimization */
+	
 	short isect;			/* which half of quad */
 	short mode;				/* RE_RAY_SHADOW, RE_RAY_MIRROR, RE_RAY_SHADOW_TRA */
 	int lay;				/* -1 default, set for layer lamps */
+	
+	int skip;				/* RE_SKIP_CULLFACE */
 
-	/* only used externally */
 	float col[4];			/* RGBA for shadow_tra */
-
-	/* octree only */
-	RayFace *facecontr;
-	int obcontr;
-	float ddalabda;
-	short faceisect;		/* flag if facecontr was done or not */
-
-	/* custom pointer to be used in the RayCheckFunc */
+	
 	void *userdata;
-} Isect;
+};
 
-/* function callbacks for face type abstraction */
-typedef void (*RayCoordsFunc)(RayFace *face,
-	float **v1, float **v2, float **v3, float **v4);
-typedef int (*RayCheckFunc)(Isect *is, int ob, RayFace *face);
-typedef float *(*RayObjectTransformFunc)(void *userdata, int ob);
+/* ray types */
+#define RE_RAY_SHADOW 0
+#define RE_RAY_MIRROR 1
+#define RE_RAY_SHADOW_TRA 2
 
-/* tree building and freeing */
-RayTree *RE_ray_tree_create(int ocres, int totface, float *min, float *max,
-	RayCoordsFunc coordfunc, RayCheckFunc checkfunc,
-	RayObjectTransformFunc transformfunc, void *userdata);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list