[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20811] branches/soc-2009-jaguarandi/ source/blender/render: *Instance support at dupliverts/faces

André Pinto andresusanopinto at gmail.com
Thu Jun 11 18:44:01 CEST 2009


Revision: 20811
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20811
Author:   jaguarandi
Date:     2009-06-11 18:44:01 +0200 (Thu, 11 Jun 2009)

Log Message:
-----------
*Instance support at dupliverts/faces
*Octree works nicely on hierarchic trees
	*the old code was quite destructive at the Isect variable
	 changing isec->start, end, vec..now it only changes isec->labda (and hit results)

Currently rendering a BVH of all objects, where each object has it own octree.

Modified Paths:
--------------
    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/rayobject.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/renderdatabase.c

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-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-06-11 16:44:01 UTC (rev 20811)
@@ -46,7 +46,7 @@
 /* RayObject constructors */
 RayObject* RE_rayobject_octree_create(int ocres, int size);
 RayObject* RE_rayobject_bvh_create(int size);
-RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4]);
+RayObject* RE_rayobject_instance_create(RayObject *target, float transform[][4], void *ob, void *target_ob);
 
 //RayObject* RayObject_derivedmesh_create(struct DerivedMesh*, void *ob);
 RayObject* RE_rayobject_mesh_create(struct Mesh*, void *ob);

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h	2009-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/render_types.h	2009-06-11 16:44:01 UTC (rev 20811)
@@ -54,6 +54,7 @@
 struct RenderBuckets;
 struct ObjectInstanceRen;
 struct RayObject;
+struct RayFace;
 
 #define TABLEINITSIZE 1024
 #define LAMPINITSIZE 256
@@ -170,7 +171,7 @@
 	
 	/* octree tables and variables for raytrace */
 	struct RayObject *raytree;
-	struct RayObject *rayfaces; /* TODO Temporary */
+	struct RayFace *rayfaces;
 
 	/* occlusion tree */
 	void *occlusiontree;
@@ -280,6 +281,12 @@
 	int  actmtface, actmcol, bakemtface;
 
 	float obmat[4][4];	/* only used in convertblender.c, for instancing */
+
+	/* used on makeraytree */
+	struct RayObject *raytree;
+	struct RayFace *rayfaces;
+	struct ObjectInstanceRen *rayobi;
+	
 } ObjectRen;
 
 typedef struct ObjectInstanceRen {
@@ -297,6 +304,10 @@
 
 	float *vectors;
 	int totvector;
+	
+	/* used on makeraytree */
+	struct RayObject *raytree;
+
 } ObjectInstanceRen;
 
 /* ------------------------------------------------------------------------- */

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-06-11 16:44:01 UTC (rev 20811)
@@ -128,10 +128,6 @@
 	if(is->orig.ob == face->ob && is->orig.face == face->face)
 		return 0;
 
-	/* disabled until i got real & fast cylinder checking, this code doesnt work proper for faster strands */
-	//	if(is->mode==RE_RAY_SHADOW && is->vlr->flag & R_STRAND) 
-	//		return intersection_strand(is);
-	
 
 	VECCOPY(co1, face->v1);
 	VECCOPY(co2, face->v2);
@@ -182,7 +178,7 @@
 			if(v<ISECT_EPSILON && (u + v) > -(1.0f+ISECT_EPSILON)) {
 				labda= divdet*(cros0*t10 + cros1*t11 + cros2*t12);
 
-				if(labda>-ISECT_EPSILON && labda<1.0f+ISECT_EPSILON) {
+				if(labda>-ISECT_EPSILON && labda<is->labda) {
 					ok= 1;
 				}
 			}
@@ -210,7 +206,7 @@
 				if(v<ISECT_EPSILON && (u + v) >-(1.0f+ISECT_EPSILON)) {
 					labda= divdet*(cros0*t10 + cros1*t11 + cros2*t12);
 					
-					if(labda>-ISECT_EPSILON && labda<1.0f+ISECT_EPSILON) {
+					if(labda>-ISECT_EPSILON && labda<is->labda) {
 						ok= 2;
 					}
 				}
@@ -250,9 +246,6 @@
 		}
 #endif
 
-		if(is->mode!=RE_RAY_SHADOW && labda > is->labda)
-			return 0;
-
 		is->isect= ok;	// wich half of the quad
 		is->labda= labda;
 		is->u= u; is->v= v;
@@ -274,10 +267,12 @@
 		printf("Casting %d rays\n", casted_rays);
 
 	i->labda = 10000.0;
+/*
 	i->vec[0] *= i->labda;
 	i->vec[1] *= i->labda;
 	i->vec[2] *= i->labda;
 	i->labda = 1.0f;
+*/
 	i->dist = VecLength(i->vec);
 	
 	if(i->mode==RE_RAY_SHADOW && i->last_hit && RE_rayobject_intersect(i->last_hit, i))

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c	2009-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c	2009-06-11 16:44:01 UTC (rev 20811)
@@ -66,7 +66,7 @@
 	assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */	
 	
 	obj->rayobj.api = &bvh_api;
-	obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 2, 6);
+	obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 4, 6);
 	
 	INIT_MINMAX(obj->bb[0], obj->bb[1]);
 	return RayObject_unalign((RayObject*) obj);
@@ -83,9 +83,8 @@
 
 		if(isec->mode == RE_RAY_SHADOW)
 			hit->dist = 0;
-//		TODO
-//		else
-//			hit->dist = isec->labda;
+		else
+			hit->dist = isec->labda*isec->dist;
 	}
 }
 
@@ -99,7 +98,7 @@
 	Normalize(dir);
 
 	hit.index = 0;
-	hit.dist = FLT_MAX; //TODO isec->labda;
+	hit.dist = isec->labda*isec->dist;
 	
 	return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, isec);
 }

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.c	2009-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.c	2009-06-11 16:44:01 UTC (rev 20811)
@@ -51,22 +51,28 @@
 {
 	RayObject rayobj;
 	RayObject *target;
+
+	void *ob; //Object represented by this instance
+	void *target_ob; //Object represented by the inner RayObject, needed to handle self-intersection
+	
 	float global2target[4][4];
 	float target2global[4][4];
 	
 } InstanceRayObject;
 
 
-RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4])
+RayObject *RE_rayobject_instance_create(RayObject *target, float transform[][4], void *ob, void *target_ob)
 {
 	InstanceRayObject *obj= (InstanceRayObject*)MEM_callocN(sizeof(InstanceRayObject), "InstanceRayObject");
 	assert( RayObject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */	
 	
 	obj->rayobj.api = &instance_api;
 	obj->target = target;
+	obj->ob = ob;
+	obj->target_ob = target_ob;
 	
-	Mat4CpyMat4(obj->global2target, transform);
-	Mat4Invert(obj->target2global, obj->global2target);
+	Mat4CpyMat4(obj->target2global, transform);
+	Mat4Invert(obj->global2target, obj->target2global);
 	
 	return RayObject_unalign((RayObject*) obj);
 }
@@ -78,39 +84,54 @@
 	
 	InstanceRayObject *obj = (InstanceRayObject*)o;
 	int res;
-	float start[3], vec[3], labda_point[3], labda;
+	float start[3], vec[3], labda, dist;
+	int changed = 0;
 	
+	//TODO - this is disabling self intersection on instances
+	if(isec->orig.ob == obj->ob && obj->ob)
+	{
+		changed = 1;
+		isec->orig.ob = obj->target_ob;
+	}
 	
+	
 	VECCOPY( start, isec->start );
 	VECCOPY( vec  , isec->vec   );
 	labda = isec->labda;
-	VECADDFAC( labda_point, start, vec, labda );
-	
-	
+	dist  = isec->dist;
+
 	//Transform to target coordinates system
 	VECADD( isec->vec, isec->vec, isec->start );	
-	VecMat4MulVecfl(isec->start, obj->target2global, isec->start);
-	VecMat4MulVecfl(isec->vec  , obj->target2global, isec->vec);
-	VecMat4MulVecfl(labda_point, obj->target2global, labda_point);
-	isec->labda = VecLenf( isec->start, labda_point );
+
+	Mat4MulVecfl(obj->global2target, isec->start);
+	Mat4MulVecfl(obj->global2target, isec->vec  );
+
+	isec->dist = VecLenf( isec->start, isec->vec );
 	VECSUB( isec->vec, isec->vec, isec->start );
 	
+	isec->labda *= isec->dist / dist;
+	
 	//Raycast
 	res = RE_rayobject_intersect(obj->target, isec);
 
 	//Restore coordinate space coords
 	if(res == 0)
+	{
 		isec->labda = labda;
+		
+	}
 	else
 	{
-		VECADDFAC( labda_point, isec->start, isec->vec, isec->labda );
-		VecMat4MulVecfl(labda_point, obj->global2target, labda_point);
-		isec->labda = VecLenf( start, labda_point );
-		
+		isec->labda *= dist / isec->dist;
+		isec->hit.ob = obj->ob;
 	}
+	isec->dist = dist;
 	VECCOPY( isec->start, start );
-	VECCOPY( isec->vec, vec );
+	VECCOPY( isec->vec,   vec );
 	
+	if(changed)
+		isec->orig.ob = obj->ob;
+		
 	return res;
 }
 
@@ -123,17 +144,20 @@
 static void RayObject_instance_bb(RayObject *o, float *min, float *max)
 {
 	//TODO:
-	// *better bb.. calculated witouth rotations of bb
-	// *maybe cache that better fitted BB at the InstanceRayObject
+	// *better bb.. calculated without rotations of bb
+	// *maybe cache that better-fitted-BB at the InstanceRayObject
 	InstanceRayObject *obj = (InstanceRayObject*)o;
 
-	float m[3], M[3];
+	float m[3], M[3], t[3];
+	int i, j;
 	INIT_MINMAX(m, M);
 	RE_rayobject_merge_bb(obj->target, m, M);
 
-	VecMat4MulVecfl(m, obj->target2global, m);
-	VecMat4MulVecfl(M, obj->target2global, M);
-
-	DO_MINMAX(m, min, max);
-	DO_MINMAX(M, min, max);
+	//There must be a faster way than rotating all the 8 vertexs of the BB
+	for(i=0; i<8; i++)
+	{
+		for(j=0; j<3; j++) t[j] = i&(1<<j) ? M[j] : m[j];
+		Mat4MulVecfl(obj->target2global, t);
+		DO_MINMAX(t, min, max);
+	}
 }

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c	2009-06-11 15:10:23 UTC (rev 20810)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c	2009-06-11 16:44:01 UTC (rev 20811)
@@ -636,7 +636,9 @@
 	}
 
 	MEM_freeN(oc->ocface);
+	oc->ocface = NULL;
 	MEM_freeN(oc->ro_nodes);
+	oc->ro_nodes = NULL;
 	
 	printf("%f %f - %f\n", oc->min[0], oc->max[0], oc->ocfacx );
 	printf("%f %f - %f\n", oc->min[1], oc->max[1], oc->ocfacy );
@@ -820,9 +822,10 @@
 	Octree *oc= (Octree*)tree;
 	Node *no;
 	OcVal ocval;
-	float vec1[3], vec2[3], end[3];
+	float vec1[3], vec2[3], start[3], end[3];
 	float u1,u2,ox1,ox2,oy1,oy2,oz1,oz2;
 	float labdao,labdax,ldx,labday,ldy,labdaz,ldz, ddalabda;
+	float olabda = 0;
 	int dx,dy,dz;	
 	int xo,yo,zo,c1=0;
 	int ocx1,ocx2,ocy1, ocy2,ocz1,ocz2;
@@ -838,35 +841,33 @@
 	is->userdata= oc->userdata;
 #endif
 
+	VECCOPY( start, is->start );
 	VECADDFAC( end, is->start, is->vec, is->labda );
-	ldx= end[0] - is->start[0];
+	ldx= is->vec[0]*is->labda;
+	olabda = is->labda;
 	u1= 0.0f;
 	u2= 1.0f;
 	
 	/* clip with octree cube */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list