[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21264] branches/soc-2009-jaguarandi/ source/blender/render/intern: *reserved RayObject align offset 0 for private usage inside each structure

André Pinto andresusanopinto at gmail.com
Tue Jun 30 16:05:34 CEST 2009


Revision: 21264
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21264
Author:   jaguarandi
Date:     2009-06-30 16:05:33 +0200 (Tue, 30 Jun 2009)

Log Message:
-----------
*reserved RayObject align offset 0 for private usage inside each structure
point is that other structures like trees can then distiguish between other nodes or rayobject primitives
withouth needing any other variable.
	(Note yet used but will reduce memory by a nice factor (linear to the number of primitives))

Modified 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_bvh.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.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
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-06-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h	2009-06-30 14:05:33 UTC (rev 21264)
@@ -58,13 +58,15 @@
 	only 2 are used:
 
 	 addr&2  - type of object
-		0     	RayFace
-		1		RayObject (generic with API callbacks)
-		2		unused
+	 	0		Self (reserved for each structure)
+		1     	RayFace
+		2		RayObject (generic with API callbacks)
 		3		unused
 
-	0 was choosed to RayFace because thats the one where speed will be needed.
-	
+	0 means it's reserved and has it own meaning inside each ray acceleration structure
+	(this way each structure can use the allign offset to determine if a node represents a
+	 RayObject primitive, which can be used to save memory)
+
 	You actually don't need to care about this if you are only using the API
 	described on RE_raytrace.h
  */
@@ -101,10 +103,13 @@
 } RayObjectAPI;
 
 //TODO use intptr_t
-#define RayObject_align(o)		((RayObject*)(((int)o)&(~3)))
-#define RayObject_unalign(o)	((RayObject*)(((int)o)|1))
-#define RayObject_isFace(o)		((((int)o)&3) == 0)
+#define RayObject_align(o)				((RayObject*)(((int)o)&(~3)))
+#define RayObject_unalignRayFace(o)		((RayObject*)(((int)o)|1))
+#define RayObject_unalignRayAPI(o)		((RayObject*)(((int)o)|2))
+
 #define RayObject_isAligned(o)	((((int)o)&3) == 0)
+#define RayObject_isRayFace(o)	((((int)o)&3) == 1)
+#define RayObject_isRayAPI(o)	((((int)o)&3) == 2)
 
 /*
  * Extend min/max coords so that the rayobject is inside them

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-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -255,7 +255,7 @@
 
 		is->hit.ob   = face->ob;
 		is->hit.face = face->face;
-		is->last_hit = (RayObject*)face;
+		is->last_hit = (RayObject*) RayObject_unalignRayFace(face);
 		return 1;
 	}
 
@@ -289,15 +289,16 @@
 
 int RE_rayobject_intersect(RayObject *r, Isect *i)
 {
-	if(RayObject_isFace(r))
+	if(RayObject_isRayFace(r))
 	{
-		return intersect_rayface( (RayFace*) r, i);
+		return intersect_rayface( (RayFace*) RayObject_align(r), i);
 	}
-	else
+	else if(RayObject_isRayAPI(r))
 	{
 		r = RayObject_align( r );
 		return r->api->raycast( r, i );
 	}
+	else assert(0);
 }
 
 void RE_rayobject_add(RayObject *r, RayObject *o)
@@ -320,19 +321,20 @@
 
 void RE_rayobject_merge_bb(RayObject *r, float *min, float *max)
 {
-	if(RayObject_isFace(r))
+	if(RayObject_isRayFace(r))
 	{
-		RayFace *face = (RayFace*)r;
+		RayFace *face = (RayFace*) RayObject_align(r);
 		DO_MINMAX( face->v1, min, max );
 		DO_MINMAX( face->v2, min, max );
 		DO_MINMAX( face->v3, min, max );
 		if(face->v4) DO_MINMAX( face->v4, min, max );
 	}
-	else
+	else if(RayObject_isRayAPI(r))
 	{
 		r = RayObject_align( r );
 		r->api->bb( r, min, max );
 	}
+	else assert(0);
 }
 
 #ifdef RE_RAYCOUNTER

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-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_bvh.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -69,7 +69,7 @@
 	obj->bvh = BLI_bvhtree_new(size, FLT_EPSILON, 4, 6);
 	
 	INIT_MINMAX(obj->bb[0], obj->bb[1]);
-	return RayObject_unalign((RayObject*) obj);
+	return RayObject_unalignRayAPI((RayObject*) obj);
 }
 
 static void bvh_callback(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit)

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-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_instance.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -74,7 +74,7 @@
 	Mat4CpyMat4(obj->target2global, transform);
 	Mat4Invert(obj->global2target, obj->target2global);
 	
-	return RayObject_unalign((RayObject*) obj);
+	return RayObject_unalignRayAPI((RayObject*) obj);
 }
 
 static int  RayObject_instance_intersect(RayObject *o, Isect *isec)

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c	2009-06-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_mesh.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -128,5 +128,5 @@
 		face->face = (void*)i;
 	}
 	
-	return RayObject_unalign((RayObject*) rm);
+	return RayObject_unalignRayAPI((RayObject*) rm);
 }

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-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_octree.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -461,7 +461,7 @@
 	oc->ro_nodes_used = 0;
 
 	
-	return RayObject_unalign((RayObject*) oc);
+	return RayObject_unalignRayAPI((RayObject*) oc);
 }
 
 
@@ -631,7 +631,7 @@
 
 	for(c=0; c<oc->ro_nodes_used; c++)
 	{
-		assert( RayObject_isFace(oc->ro_nodes[c]) );
+		assert( RayObject_isRayFace(oc->ro_nodes[c]) );
 		octree_fill_rayface(oc, (RayFace*)oc->ro_nodes[c]);
 	}
 

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c	2009-06-30 12:52:16 UTC (rev 21263)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c	2009-06-30 14:05:33 UTC (rev 21264)
@@ -198,7 +198,9 @@
 				face->ob   = obi;
 				face->face = vlr;
 				
-				RE_rayobject_add( raytree, (RayObject*)face++ );
+				RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
+				
+				face++;
 			}
 		}
 		RE_rayobject_done( raytree );
@@ -311,7 +313,8 @@
 			face->ob   = obi;
 			face->face = vlr;
 			
-			RE_rayobject_add( raytree, (RayObject*)face++ );
+			RE_rayobject_add( raytree, RayObject_unalignRayFace(face) );
+			face++;
 		}
 	}
 	RE_rayobject_done( raytree );	





More information about the Bf-blender-cvs mailing list