[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21242] branches/soc-2009-jaguarandi: *make type of acceleration structure changeable at runtime

André Pinto andresusanopinto at gmail.com
Mon Jun 29 21:48:11 CEST 2009


Revision: 21242
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21242
Author:   jaguarandi
Date:     2009-06-29 21:48:11 +0200 (Mon, 29 Jun 2009)

Log Message:
-----------
*make type of acceleration structure changeable at runtime
*added some counter code (test/hits) for primitives and raycasts

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/release/ui/buttons_scene.py
    branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c

Modified: branches/soc-2009-jaguarandi/release/ui/buttons_scene.py
===================================================================
--- branches/soc-2009-jaguarandi/release/ui/buttons_scene.py	2009-06-29 19:46:28 UTC (rev 21241)
+++ branches/soc-2009-jaguarandi/release/ui/buttons_scene.py	2009-06-29 19:48:11 UTC (rev 21242)
@@ -25,6 +25,7 @@
 		col.itemR(rd, "render_raytracing", text="Ray Tracing")
 		colsub = col.column()
 		colsub.active = rd.render_raytracing
+		colsub.itemR(rd, "raytrace_structure", text="Structure")
 		colsub.itemR(rd, "octree_resolution", text="Octree")
 		col.itemR(rd, "dither_intensity", text="Dither", slider=True)
 		

Modified: branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c	2009-06-29 19:46:28 UTC (rev 21241)
+++ branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c	2009-06-29 19:48:11 UTC (rev 21242)
@@ -199,6 +199,13 @@
 		{256, "OCTREE_RES_256", 0, "256", ""},
 		{512, "OCTREE_RES_512", 0, "512", ""},
 		{0, NULL, 0, NULL, NULL}};
+
+	static EnumPropertyItem raytrace_structure_items[] = {
+		{R_RAYSTRUCTURE_HIER_BVH_BVH, "{R_RAYSTRUCTURE_HIER_BVH_BVH", 0, "BVH of BVH's", "Create a BVH of objects (each object has it own BVH)"},
+		{R_RAYSTRUCTURE_HIER_BVH_OCTREE, "{R_RAYSTRUCTURE_HIER_BVH_OCTREE", 0, "BVH of octree", "Create a BVH of objects (each object has it own octree)"},
+		{R_RAYSTRUCTURE_SINGLE_BVH, "{R_RAYSTRUCTURE_SINGLE_BVH", 0, "Single BVH", "BVH of all primitives (no instance support)"},
+		{R_RAYSTRUCTURE_SINGLE_OCTREE, "{R_RAYSTRUCTURE_SINGLE_OCTREE", 0, "Octree", "Octree of all primitives (no instance support)"},
+		{0, NULL, 0, NULL, NULL}};
 		
 	static EnumPropertyItem fixed_oversample_items[] = {
 		{5, "OVERSAMPLE_5", 0, "5", ""},
@@ -594,6 +601,12 @@
 	RNA_def_property_enum_items(prop, octree_resolution_items);
 	RNA_def_property_ui_text(prop, "Octree Resolution", "Resolution of raytrace accelerator. Use higher resolutions for larger scenes.");
 	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
+
+	prop= RNA_def_property(srna, "raytrace_structure", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "raystructure");
+	RNA_def_property_enum_items(prop, raytrace_structure_items);
+	RNA_def_property_ui_text(prop, "Raytrace Acceleration Structure", "Type of raytrace accelerator structure.");
+	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 	
 	prop= RNA_def_property(srna, "antialiasing", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mode", R_OSA);

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-29 19:46:28 UTC (rev 21241)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-06-29 19:48:11 UTC (rev 21242)
@@ -31,10 +31,12 @@
 #ifndef RE_RAYTRACE_H
 #define RE_RAYTRACE_H
 
+#define RE_RAY_COUNTER
 
 /* Internals about raycasting structures can be found on intern/raytree.h */
 typedef struct RayObject RayObject;
 typedef struct Isect Isect;
+typedef struct RayCounter RayCounter;
 struct DerivedMesh;
 struct Mesh;
 
@@ -80,10 +82,42 @@
 	int skip;				/* RE_SKIP_CULLFACE */
 
 	float col[4];			/* RGBA for shadow_tra */
+
+	void *userdata;
 	
-	void *userdata;
+#ifdef RE_RAY_COUNTER
+	RayCounter *count;
+#endif
+	
 };
 
+#ifdef RE_RAYCOUNTER
+
+struct RayCounter
+{
+
+	struct
+	{
+		unsigned long long test, hit;
+		
+	} intersect_rayface, raycast;
+	
+	unsigned long long rayshadow_last_hit_optimization;
+};
+
+void RE_RC_INIT (RayCounter *rc);
+void RE_RC_MERGE(RayCounter *rc, RayCounter *tmp);
+#define RE_RC_COUNT(var) (var)++
+
+#else
+
+#define RE_RC_INIT(rc)
+#define RE_RC_MERGE(dest,src)
+#define	RE_RC_COUNT(var)
+	
+#endif
+
+
 /* ray types */
 #define RE_RAY_SHADOW 0
 #define RE_RAY_MIRROR 1

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-29 19:46:28 UTC (rev 21241)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject.c	2009-06-29 19:48:11 UTC (rev 21242)
@@ -128,6 +128,7 @@
 	if(is->orig.ob == face->ob && is->orig.face == face->face)
 		return 0;
 
+	RE_RC_COUNT(is->count->intersect_rayface.test);
 
 	VECCOPY(co1, face->v1);
 	VECCOPY(co2, face->v2);
@@ -246,6 +247,8 @@
 		}
 #endif
 
+		RE_RC_COUNT(is->count->intersect_rayface.hit);
+
 		is->isect= ok;	// wich half of the quad
 		is->labda= labda;
 		is->u= u; is->v= v;
@@ -261,24 +264,27 @@
 
 int RE_rayobject_raycast(RayObject *r, Isect *i)
 {
-	static int casted_rays = 0;
-	
-	if(casted_rays++ % (1<<20) == 0)
-		printf("Casting %d rays\n", casted_rays);
+	RE_RC_COUNT(i->count->raycast.test);
 
-/*
-	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))
+	{
+		RE_RC_COUNT(i->count->raycast.hit);
+		RE_RC_COUNT(i->count->rayshadow_last_hit_optimization );
 		return 1;
+	}
 
+#ifdef RE_RAYCOUNTER
+	if(RE_rayobject_intersect(r, i))
+	{
+		RE_RC_COUNT(i->count->raycast.hit);
+		return 1;
+	}
+	return 0;
+#else
 	return RE_rayobject_intersect(r, i);
+#endif
 }
 
 int RE_rayobject_intersect(RayObject *r, Isect *i)
@@ -329,3 +335,17 @@
 	}
 }
 
+#ifdef RE_RAYCOUNTER
+void RE_merge_raycounter(RayCounter *dest, RayCounter *tmp)
+{
+	int i;
+	for(i=0; i<3; i++) dest->casted[i] += tmp->casted[i];
+	for(i=0; i<3; i++) dest->hit   [i] += tmp->hit   [i];
+	
+	dest->test_primitives += tmp->test_primitives;
+	dest->hit_primitives  += tmp->hit_primitives;
+	
+	dest->test_bb += tmp->test_bb;
+	dest->hit_bb  += tmp->hit_bb;
+}
+#endif
\ No newline at end of file

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-29 19:46:28 UTC (rev 21241)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c	2009-06-29 19:48:11 UTC (rev 21242)
@@ -175,10 +175,13 @@
 		assert( faces > 0 );
 
 		//Create Ray cast accelaration structure
-
+		
 		//TODO dynamic ocres
-//		raytree = obr->raytree = RE_rayobject_octree_create( re->r.ocres, faces );
-		raytree = obr->raytree = RE_rayobject_bvh_create( faces );
+		if(re->r.raystructure == R_RAYSTRUCTURE_HIER_BVH_OCTREE)
+			raytree = obr->raytree = RE_rayobject_octree_create( re->r.ocres, faces );
+		else //if(re->r.raystructure == R_RAYSTRUCTURE_HIER_BVH_BVH)
+			raytree = obr->raytree = RE_rayobject_bvh_create( faces );
+			
 		face = obr->rayfaces = (RayFace*)MEM_callocN(faces*sizeof(RayFace), "ObjectRen faces");
 		obr->rayobi = obi;
 		
@@ -284,8 +287,11 @@
 	}
 	
 	//Create raytree
-//	raytree = re->raytree	= RE_rayobject_octree_create(re->r.ocres, faces);
-	raytree = re->raytree	= RE_rayobject_bvh_create(faces);
+	if(re->r.raystructure == R_RAYSTRUCTURE_SINGLE_OCTREE)
+		raytree = re->raytree = RE_rayobject_octree_create( re->r.ocres, faces );
+	else //if(re->r.raystructure == R_RAYSTRUCTURE_SINGLE_BVH)
+		raytree = re->raytree = RE_rayobject_bvh_create( faces );
+
 	face	= re->rayfaces	= (RayFace*)MEM_callocN(faces*sizeof(RayFace), "Render ray faces");
 	
 	for(obi=re->instancetable.first; obi; obi=obi->next)
@@ -313,10 +319,10 @@
 
 void makeraytree(Render *re)
 {
-	if(1)
+	if(ELEM(re->r.raystructure, R_RAYSTRUCTURE_SINGLE_BVH, R_RAYSTRUCTURE_SINGLE_OCTREE))
+		makeraytree_single(re);
+	else
 		makeraytree_hier(re);
-	else
-		makeraytree_single(re);
 }
 
 





More information about the Bf-blender-cvs mailing list