[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15017] branches/soc-2008-unclezeiv/source /blender/render/intern: Moved all global variables in a new LightcutsData struct, opaquely linked by the Render database.

Davide Vercelli davide.vercelli at gmail.com
Wed May 28 00:20:03 CEST 2008


Revision: 15017
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15017
Author:   unclezeiv
Date:     2008-05-28 00:20:02 +0200 (Wed, 28 May 2008)

Log Message:
-----------
Moved all global variables in a new LightcutsData struct, opaquely linked by the Render database.
Fix: the light tree is now correctly deallocated.

Modified Paths:
--------------
    branches/soc-2008-unclezeiv/source/blender/render/intern/include/lightcuts.h
    branches/soc-2008-unclezeiv/source/blender/render/intern/include/render_types.h
    branches/soc-2008-unclezeiv/source/blender/render/intern/source/convertblender.c
    branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
    branches/soc-2008-unclezeiv/source/blender/render/intern/source/shadeoutput.c

Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/include/lightcuts.h
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/include/lightcuts.h	2008-05-27 20:02:38 UTC (rev 15016)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/include/lightcuts.h	2008-05-27 22:20:02 UTC (rev 15017)
@@ -31,10 +31,14 @@
 #include "render_types.h"
 #include "rendercore.h"
 
-void lightcuts_create_point_lights(Render * re);
+struct LightcutsData;
 
+void lightcuts_init(Render *re);
+
+void lightcuts_free(struct LightcutsData *lcd);
+
 typedef float (*LightContribFunc)(LampRen *lar, ShadeInput *shi);
 
-void lightcuts_do_lights(LightContribFunc get_contrib, ShadeInput *shi, float * diff);
+void lightcuts_do_lights(struct LightcutsData *lcd, LightContribFunc get_contrib, ShadeInput *shi, float *diff);
 
 #endif /*LIGHTCUTS_H_*/

Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/include/render_types.h	2008-05-27 20:02:38 UTC (rev 15016)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/include/render_types.h	2008-05-27 22:20:02 UTC (rev 15017)
@@ -50,6 +50,7 @@
 struct GHash;
 struct RenderBuckets;
 struct ObjectInstanceRen;
+struct LightcutsData;
 
 #define TABLEINITSIZE 1024
 #define LAMPINITSIZE 256
@@ -180,8 +181,9 @@
 
 	ListBase lights;	/* GroupObject pointers */
 	ListBase lampren;	/* storage, for free */
-	ListBase pointlights;	/* for lightcuts */
 	
+	struct LightcutsData *lcdata;
+	
 	ListBase objecttable;
 
 	struct ObjectInstanceRen *objectinstance;

Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/convertblender.c	2008-05-27 20:02:38 UTC (rev 15016)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/convertblender.c	2008-05-27 22:20:02 UTC (rev 15017)
@@ -4395,7 +4395,6 @@
 	
 	BLI_freelistN(&re->lampren);
 	BLI_freelistN(&re->lights);
-	BLI_freelistN(&re->pointlights);
 
 	free_renderdata_tables(re);
 	
@@ -4437,6 +4436,8 @@
 	free_occ(re);
 	free_strand_surface(re);
 	
+	lightcuts_free(re->lcdata);
+	
 	re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
 	re->i.convertdone= 0;
 	
@@ -4783,7 +4784,6 @@
 	re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
 	re->lights.first= re->lights.last= NULL;
 	re->lampren.first= re->lampren.last= NULL;
-	re->pointlights.first= re->pointlights.last= NULL;
 	
 	slurph_opt= 0;
 	re->i.partsdone= 0;	/* signal now in use for previewrender */
@@ -4885,7 +4885,7 @@
 		
 		/* lightcuts */
 		if((re->r.mode & R_LIGHTCUTS) && !re->test_break())
-			lightcuts_create_point_lights(re);
+			lightcuts_init(re);
 	}
 	
 	if(re->test_break())
@@ -4926,7 +4926,6 @@
 	re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
 	re->i.totface=re->i.totvert=re->i.totstrand=re->i.totlamp=re->i.tothalo= 0;
 	re->lights.first= re->lights.last= NULL;
-	re->pointlights.first= re->pointlights.last= NULL;
 
 	slurph_opt= 0;
 	
@@ -5450,7 +5449,6 @@
 	re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
 	re->lights.first= re->lights.last= NULL;
 	re->lampren.first= re->lampren.last= NULL;
-	re->pointlights.first= re->pointlights.last= NULL;
 
 	/* in localview, lamps are using normal layers, objects only local bits */
 	if(re->scene->lay & 0xFF000000) lay= re->scene->lay & 0xFF000000;

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-27 20:02:38 UTC (rev 15016)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-05-27 22:20:02 UTC (rev 15017)
@@ -40,6 +40,7 @@
 #include "MEM_guardedalloc.h"
 #include "RE_pipeline.h"
 
+#include "blendef.h"
 #include "render_types.h"
 
 /* = LA_X + 1 */
@@ -48,9 +49,6 @@
 #define CLUSTER_SUN   2
 #define CLUSTER_SPOT  3
 
-/* TODO: these are WIP values */
-#define LIGHTCUTS_MAX_METRIC (10e38)
-
 /* node of the lightcuts tree */
 typedef struct LightcutsCluster
 {
@@ -79,24 +77,25 @@
 	float error_bound;
 } CutNode;
 
+typedef struct LightcutsData {
+	/* NOTE: conservative space estimation */
+	/* TODO: equivalent data structures for sun and spot */
+	ListBase pointlights;
+	LightcutsCluster *array_local;
+	int free_local; /* location of first empty slot */
+	int root_local; /* id of root node */
+	float max_local_dist; /* maximum distance for local lights */
+	
+	float error_rate;
+	int max_lights;
+	int max_cut;
+} LightcutsData;
+
 #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 */
@@ -147,16 +146,16 @@
 	(*root)++;
 }
 
-static void find_and_insert_new_min(Heap * heap, LightcutsCluster * array, LightcutsClusterPair * pair, int id, int from)
+static void find_and_insert_new_min(Heap * heap, LightcutsCluster * array, int size, LightcutsClusterPair * pair, int id, int from)
 {
 	LightcutsCluster * el = &array[id];
 	LightcutsCluster * el2;
-	float metric = LIGHTCUTS_MAX_METRIC + 1.0;
+	float metric = MAXFLOAT;
 	float pair_metric;
 	int other = -1;
 	int i;
 	
-	for (i = from; i < max_lights * 2; i++)
+	for (i = from; i < size; i++)
 	{
 		if (i == id)
 			continue;
@@ -185,16 +184,17 @@
 	}
 }
 
-static void lightcuts_fill_array(ListBase * pointlights)
+static void lightcuts_fill_array(LightcutsData *lcd, ListBase * pointlights)
 {
 	GroupObject *go;
 	LampRen *lar;
-	LightcutsCluster *clus = array_local;
+	LightcutsCluster *clus;
 	
-	/* TODO: check if not already filled in ? */
-	memset(array_local, 0, sizeof(LightcutsCluster) * (max_lights * 2));
-	free_local = 0;
-	root_local = 0;
+	lcd->array_local= MEM_callocN(sizeof(LightcutsCluster) * lcd->max_lights * 2, "array_local");
+	lcd->free_local= 0;
+	lcd->root_local= 0;
+	
+	clus= lcd->array_local;
 		
 	for(go = pointlights->first; go; go = go->next) {
 		lar = go->lampren;
@@ -205,20 +205,20 @@
 		
 		clus->type = CLUSTER_LOCAL;
 		clus->in_tree = 0;
-		clus->id = free_local;
+		clus->id = lcd->free_local;
 		clus->intensity = lar->energy;
 		VECCOPY(clus->min, lar->co);
 		VECCOPY(clus->max, lar->co);
 		clus->lar = lar;
 		
 		clus++;
-		free_local++;
+		lcd->free_local++;
 	}
 }
 
-static void debug_print_tree(int root_local, int lev)
+static void debug_print_tree(LightcutsCluster *array, int root, int lev)
 {
-	LightcutsCluster * el = &array_local[root_local];
+	LightcutsCluster *el= &array[root];
 	int i;
 	for (i = 0; i < lev; i++)
 		printf("-");
@@ -227,24 +227,24 @@
 	if (el->child1 == 0 && el->child2 == 0)
 		return;
 	
-	debug_print_tree(el->child1, lev + 1);
-	debug_print_tree(el->child2, lev + 1);		
+	debug_print_tree(array, el->child1, lev + 1);
+	debug_print_tree(array, el->child2, lev + 1);		
 }
 	
-static void lightcuts_build_tree()
+static void lightcuts_build_tree(LightcutsData *lcd)
 {	
 	int i, cluster_id = 0;
 	
 	Heap * heap = BLI_heap_new();
 	/* TODO: taylor size */
-	LightcutsClusterPair *pair_array= MEM_callocN(sizeof(LightcutsClusterPair) * max_lights * 2, "pair_array");
+	LightcutsClusterPair *pair_array= MEM_callocN(sizeof(LightcutsClusterPair) * lcd->max_lights * 2, "pair_array");
 	
-	for (i = 0; i < max_lights; i++)
+	for (i = 0; i < lcd->max_lights; i++)
 	{
-		if (array_local[i].type == CLUSTER_EMPTY)
+		if (lcd->array_local[i].type == CLUSTER_EMPTY)
 			break;
 				
-		find_and_insert_new_min(heap, array_local, &pair_array[i], i, i + 1);
+		find_and_insert_new_min(heap, lcd->array_local, lcd->max_lights * 2, &pair_array[i], i, i + 1);
 	}
 	
 	/* now we have a nice heap with shortest metric for each element */
@@ -254,8 +254,8 @@
 	while (!BLI_heap_empty(heap))
 	{
 		LightcutsClusterPair * minpair = (LightcutsClusterPair *)BLI_heap_popmin(heap);
-		short in_tree1 = array_local[minpair->first].in_tree;
-		short in_tree2 = array_local[minpair->second].in_tree;
+		short in_tree1 = lcd->array_local[minpair->first].in_tree;
+		short in_tree2 = lcd->array_local[minpair->second].in_tree;
 		
 		if (in_tree1)
 			continue;
@@ -263,25 +263,25 @@
 		/* we look for another minimum */		
 		if (in_tree2)
 		{
-			find_and_insert_new_min(heap, array_local, minpair, minpair->first, 0);
+			find_and_insert_new_min(heap, lcd->array_local, lcd->max_lights * 2, minpair, minpair->first, 0);
 			continue;
 		}
 		
 		/* valid pair: build cluster out of it, mark children as used */
-		cluster_id = free_local;
-		add_new_cluster(array_local, minpair, &free_local);
+		cluster_id = lcd->free_local;
+		add_new_cluster(lcd->array_local, minpair, &lcd->free_local);
 		
 		/* new search, avoid considering in_tree children */
-		find_and_insert_new_min(heap, array_local, minpair, cluster_id, 0);
+		find_and_insert_new_min(heap, lcd->array_local, lcd->max_lights * 2, minpair, cluster_id, 0);
 	}
 	
 	BLI_heap_free(heap, 0);
 	
 	/* the last cluster added is the root of the tree */	
-	root_local = cluster_id;
+	lcd->root_local = cluster_id;
 	
-	printf("Lightcuts tree built: %d\n", root_local);
-	debug_print_tree(root_local, 0);
+	printf("Lightcuts tree built: %d\n", lcd->root_local);
+	debug_print_tree(lcd->array_local, lcd->root_local, 0);
 	
 	MEM_freeN(pair_array);
 }
@@ -334,16 +334,20 @@
 	}
 }
 
-void lightcuts_create_point_lights(Render * re)
-{	
+void lightcuts_init(Render * re)
+{
+	LightcutsData *lcd;
 	GroupObject *go, *gonew;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list