[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14990] branches/soc-2008-unclezeiv/source /blender: - added UI controls for

Davide Vercelli davide.vercelli at gmail.com
Tue May 27 02:03:38 CEST 2008


Revision: 14990
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14990
Author:   unclezeiv
Date:     2008-05-27 02:03:37 +0200 (Tue, 27 May 2008)

Log Message:
-----------
- added UI controls for
  - maximum number of lights (but additional lights are not being generated yet)
  - maximum error ratio
  - cut size (the number of lights considered per sample)
- values are initialized in readfile.c:do_versions (is this correct?)
- accordingly, removed all static allocations in lightcuts.c
- finally, shuffled some code around to group type definitions and variables previously scattered around

Modified Paths:
--------------
    branches/soc-2008-unclezeiv/source/blender/blenloader/intern/readfile.c
    branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
    branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c

Modified: branches/soc-2008-unclezeiv/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/blenloader/intern/readfile.c	2008-05-26 23:04:37 UTC (rev 14989)
+++ branches/soc-2008-unclezeiv/source/blender/blenloader/intern/readfile.c	2008-05-27 00:03:37 UTC (rev 14990)
@@ -7630,6 +7630,25 @@
 			}
 		}
 	}
+	
+	if(main->versionfile <= 246) {
+		Scene *sce= main->scene.first;
+		RenderData *r;
+		
+		while(sce) {
+			r= &sce->r;
+			if(r) {
+				if(r->lightcuts_max_lights<=0)
+					r->lightcuts_max_lights= 10000;
+				if(r->lightcuts_max_error<=0.0)
+					r->lightcuts_max_error= 0.02;
+				if(r->lightcuts_max_cut<=0)
+					r->lightcuts_max_cut= 1000;
+			}
+			
+			sce= sce->id.next;
+		}
+	}
 
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */

Modified: branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h	2008-05-26 23:04:37 UTC (rev 14989)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h	2008-05-27 00:03:37 UTC (rev 14990)
@@ -310,6 +310,12 @@
 	/* cineon */
 	short cineonwhite, cineonblack;
 	float cineongamma;
+	
+	/* lightcuts */
+	float lightcuts_max_error;
+	int lightcuts_max_lights;
+	int lightcuts_max_cut;
+	int pad1;
 } RenderData;
 
 /* control render convert and shading engine */

Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-05-26 23:04:37 UTC (rev 14989)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-05-27 00:03:37 UTC (rev 14990)
@@ -50,7 +50,6 @@
 
 /* TODO: these are WIP values */
 #define LIGHTCUTS_MAX_METRIC (10e38)
-#define LIGHTCUTS_MAX_LIGHTS (10000)
 
 /* node of the lightcuts tree */
 typedef struct LightcutsCluster
@@ -72,8 +71,32 @@
 	int second;
 } LightcutsClusterPair;
 
+typedef struct CutNode {
+	int id;
+	float contr_factor;
+	float contr_own[3];
+	float contr_clus[3];
+	float error_bound;
+} CutNode;
+
 #define VEC_LEN_SQ(v) (v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
+/* TODO: tentative calculation, will look better into it */
+#define LC_LUMINOSITY(c) (0.299*c[0] + 0.587*c[1] + 0.114*c[2])
+#define VECCOPYMUL(v1,v2,aS) {*(v1)= *(v2)*aS; *(v1+1)= *(v2+1)*aS; *(v1+2)= *(v2+2)*aS;}
 
+/* TODO: move local variables in a cleaner structure */
+/* NOTE: conservative space estimation */
+/* TODO: dynamic allocation required of course */
+/* TODO: equivalent data structures for sun and spot */
+static LightcutsCluster *array_local= 0;
+static int free_local; /* location of first empty slot */
+static int root_local; /* id of root node */
+static float max_local_dist; /* maximum distance for local lights */
+
+static float error_rate;
+static int max_lights;
+static int max_cut;
+
 static float lightcuts_compute_metric(LightcutsCluster * one, LightcutsCluster * two)
 {
 	/* TODO: compute metric also for oriented lights */
@@ -133,7 +156,7 @@
 	int other = -1;
 	int i;
 	
-	for (i = from; i < LIGHTCUTS_MAX_LIGHTS * 2; i++)
+	for (i = from; i < max_lights * 2; i++)
 	{
 		if (i == id)
 			continue;
@@ -162,16 +185,6 @@
 	}
 }
 
-/* NOTE: conservative space estimation */
-/* TODO: dynamic allocation required of course */
-LightcutsCluster array_local[LIGHTCUTS_MAX_LIGHTS * 2];
-/* location of first empty slot */
-int free_local;
-/* id of root node */
-int root_local;
-/* TODO: equivalent data structures for sun and spot */
-float max_local_dist;
-
 static void lightcuts_fill_array(ListBase * pointlights)
 {
 	GroupObject *go;
@@ -179,7 +192,7 @@
 	LightcutsCluster *clus = array_local;
 	
 	/* TODO: check if not already filled in ? */
-	memset(array_local, 0, sizeof(LightcutsCluster) * (LIGHTCUTS_MAX_LIGHTS * 2));
+	memset(array_local, 0, sizeof(LightcutsCluster) * (max_lights * 2));
 	free_local = 0;
 	root_local = 0;
 		
@@ -224,9 +237,9 @@
 	
 	Heap * heap = BLI_heap_new();
 	/* TODO: taylor size */
-	LightcutsClusterPair pair_array[LIGHTCUTS_MAX_LIGHTS];
+	LightcutsClusterPair *pair_array= MEM_callocN(sizeof(LightcutsClusterPair) * max_lights * 2, "pair_array");
 	
-	for (i = 0; i < LIGHTCUTS_MAX_LIGHTS; i++)
+	for (i = 0; i < max_lights; i++)
 	{
 		if (array_local[i].type == CLUSTER_EMPTY)
 			break;
@@ -269,6 +282,8 @@
 	
 	printf("Lightcuts tree built: %d\n", root_local);
 	debug_print_tree(root_local, 0);
+	
+	MEM_freeN(pair_array);
 }
 
 /*
@@ -401,27 +416,21 @@
 #endif
 	}
 	
+	max_lights= re->r.lightcuts_max_lights;
+	error_rate= re->r.lightcuts_max_error;
+	max_cut= re->r.lightcuts_max_cut;
+	
 	if (pointlights->first)
 	{
+		if (!array_local)
+			array_local = MEM_callocN(sizeof(LightcutsCluster) * max_lights * 2, "array_local");
 		lightcuts_fill_array(pointlights);
 		lightcuts_build_tree();
 	}
+	
+	/* XXX: TODO: we need a routine to deallocate array_local after use! */
 }
 
-typedef struct CutNode {
-	int id;
-	float contr_factor;
-	float contr_own[3];
-	float contr_clus[3];
-	float error_bound;
-} CutNode;
-
-#define LIGHTCUTS_ERROR_RATE 0.02
-#define LIGHTCUTS_MAX_CUT 1000
-
-/* TODO: tentative calculation, will look better into it */
-#define LC_LUMINOSITY(c) (0.299*c[0] + 0.587*c[1] + 0.114*c[2])
-
 /* error bound: geometric term */
 /* TODO: right now is working only for point lights */
 float calc_geometric_eb(int id, float *pos)
@@ -445,8 +454,6 @@
 	return max_local_dist / (max_local_dist + len_sq);
 }
 
-#define VECCOPYMUL(v1,v2,aS) {*(v1)= *(v2)*aS; *(v1+1)= *(v2+1)*aS; *(v1+2)= *(v2+2)*aS;}
-
 /*
  * what about intensity? which one should we use?
  * RESOLUTION: the one of the lamp, then adjusted
@@ -455,7 +462,7 @@
 void lightcuts_do_lights(LightContribFunc get_contrib, ShadeInput *shi, float * diff)
 {
 	/* TODO: show that this size is always sufficient */
-	CutNode cut_nodes[LIGHTCUTS_MAX_CUT * 2];
+	CutNode *cut_nodes; 
 	int free_node= 1;
 	
 	/* this heap maintaines the current cut */
@@ -467,7 +474,7 @@
 	/* this is the total radiance estimate, continuously updated */
 	float totest[3]= {0.0f, 0.0f, 0.0f};
 	
-	memset(cut_nodes, 0, sizeof(cut_nodes));
+	cut_nodes= MEM_callocN(sizeof(CutNode) * (max_cut * 2 + 1), "cut_nodes");
 	
 	{
 		CutNode *root= &cut_nodes[0];
@@ -493,14 +500,14 @@
 	}
 	
 	/* at each iteration the heap grows by one, but we have a maximum size */
-	while (BLI_heap_size(cut) < LIGHTCUTS_MAX_CUT && BLI_heap_size(cut) > 0) {
+	while (BLI_heap_size(cut) < max_cut && BLI_heap_size(cut) > 0) {
 		CutNode *node= BLI_heap_popmin(cut);
 		LightcutsCluster *parent= &array_local[node->id];
 		
 		if (parent->child1==0 && parent->child2==0)
 			continue;
 				
-		if (LC_LUMINOSITY(totest) * LIGHTCUTS_ERROR_RATE > node->error_bound * parent->intensity) {
+		if (LC_LUMINOSITY(totest) * error_rate > node->error_bound * parent->intensity) {
 			break;
 		} else {
 			LightcutsCluster *rep= &array_local[parent->child1];
@@ -559,4 +566,6 @@
 	VECADD(diff, diff, totest);
 	
 	BLI_heap_free(cut, 0);
+	
+	MEM_freeN(cut_nodes);
 }

Modified: branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c	2008-05-26 23:04:37 UTC (rev 14989)
+++ branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c	2008-05-27 00:03:37 UTC (rev 14990)
@@ -3413,6 +3413,10 @@
 	if(uiNewPanel(curarea, block, "Lightcuts", "Render", 640, 0, 318, 204)==0) return;
 	
 	uiDefButBitI(block, TOG, R_LIGHTCUTS, B_REDR, "Enable lightcuts", 692, 142, 192, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable lightcuts rendering");
+	
+	uiDefButF(block, NUM, B_REDR, "Max error:", 692, 120, 192, 20, &G.scene->r.lightcuts_max_error, 0.001, 1.0, 0, 0, "The maximum allowed error rate");
+	uiDefButI(block, NUM, B_REDR, "Lights:", 692, 98, 192, 20, &G.scene->r.lightcuts_max_lights, 0, 100000, 0, 0, "The maximum number of lights to generate");
+	uiDefButI(block, NUM, B_REDR, "Max cut:", 692, 76, 192, 20, &G.scene->r.lightcuts_max_cut, 0, 5000, 0, 0, "The maximum size of the cut");
 }
 
 void render_panels()





More information about the Bf-blender-cvs mailing list