[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16069] branches/soc-2008-unclezeiv/source /blender: Added buttons to select different color weights when converting from RGB to intensity values .

Davide Vercelli davide.vercelli at gmail.com
Tue Aug 12 18:57:39 CEST 2008


Revision: 16069
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16069
Author:   unclezeiv
Date:     2008-08-12 18:57:38 +0200 (Tue, 12 Aug 2008)

Log Message:
-----------
Added buttons to select different color weights when converting from RGB to intensity values. This is mainly to experiment around a bit.

Modified Paths:
--------------
    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/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h	2008-08-12 15:44:29 UTC (rev 16068)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h	2008-08-12 16:57:38 UTC (rev 16069)
@@ -320,7 +320,8 @@
 	int lightcuts_env_map;
 	float lightcuts_indir_fac;
 	int lightcuts_indirect;
-	int lightcuts_random_dirs;
+	short lightcuts_random_dirs;
+	short lightcuts_color_weight;
 } 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-08-12 15:44:29 UTC (rev 16068)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c	2008-08-12 16:57:38 UTC (rev 16069)
@@ -155,6 +155,8 @@
 	float error_rate;
 	int max_lights;
 	int max_cut;
+	
+	float colw[3];
 
 	CutNode *cut_nodes;
 	int cut_nodes_size;
@@ -194,9 +196,6 @@
 #define VECCOPYMUL(v1,v2,aS) {*(v1)= *(v2)*aS; *(v1+1)= *(v2+1)*aS; *(v1+2)= *(v2+2)*aS;}
 #define VECNEG(v) {*(v)=-*(v); *(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 LC_LUMINOSITY2(c1,c2) (LC_LUMINOSITY(c1)+LC_LUMINOSITY(c2))
-/* #define LC_LUMINOSITY(c) (0.316*c[0] + 0.460*c[1] + 0.224*c[2]) */
 #define IS_LEAF(node) (!(node)->child1 && !(node)->child2)
 #define LC_LUMINOSITY_LIMIT (0.0001f)
 
@@ -246,7 +245,7 @@
 }
 
 /* returns 0 if the new cluster uses the first child as representative, 1 otherwise */
-static int add_new_cluster(LightcutsCluster * array, LightcutsClusterPair * minpair, int * root)
+static int add_new_cluster(LightcutsCluster *array, LightcutsClusterPair *minpair, int *root, float *colw)
 {
 	LightcutsCluster *one = &array[minpair->first];
 	LightcutsCluster *two = &array[minpair->second];
@@ -290,7 +289,7 @@
 		VECCOPY(dest->col, two->col);
 		rep= 1;
 	}
-	dest->intensity= dest->luminance / LC_LUMINOSITY(dest->col);
+	dest->intensity= dest->luminance / INPR(colw, dest->col);
 	
 	/* worst case falloff type/dist for conservative error estimation */
 	dest->falloff_type= falloff_merge[one->falloff_type][two->falloff_type];
@@ -369,7 +368,7 @@
 	}
 }
 
-static void lightcuts_fill_array(ListBase *pointlights, LightcutsTree *tree, int cur_type)
+static void lightcuts_fill_array(ListBase *pointlights, LightcutsTree *tree, int cur_type, float *colw)
 {
 	GroupObject *go;
 	LampRen *lar;
@@ -421,7 +420,7 @@
 		clus->col[0]= lar->r / lar->energy;
 		clus->col[1]= lar->g / lar->energy;
 		clus->col[2]= lar->b / lar->energy;
-		clus->luminance= LC_LUMINOSITY(clus->col) * lar->energy;
+		clus->luminance= INPR(colw, clus->col) * lar->energy;
 		
 		switch (lar->falloff_type) {
 		case LA_FALLOFF_CONSTANT:
@@ -574,8 +573,10 @@
 #endif
 
 /* this one uses kdtree */
-static void lightcuts_build_tree2(LightcutsTree *tree, float c)
+static void lightcuts_build_tree2(LightcutsData *lcd, int tree_index)
 {
+	LightcutsTree *tree= &lcd->trees[tree_index];
+	float c= lcd->scene_diag * lcd->scene_diag;
 	int i, rep, cluster_id= 0;
 	LightcutsCluster *array= tree->array;
 #ifdef LIGHTCUTS_DEBUG
@@ -646,7 +647,7 @@
 
 		/* valid pair: build cluster out of it, mark children as used */
 		cluster_id = tree->free;
-		rep= add_new_cluster(array, minpair, &tree->free);
+		rep= add_new_cluster(array, minpair, &tree->free, lcd->colw);
 		
 		if (rep==0) {
 			BLI_kdtree_weak_delete(kdtree, minpair->second);
@@ -868,7 +869,7 @@
 		shadeSkyView(col, NULL, co, dxyview);
 		
 		/* XXX: arbitrary limit */
-		if (LC_LUMINOSITY(col) < LC_LUMINOSITY_LIMIT)
+		if (INPR(lcd->colw, col) < LC_LUMINOSITY_LIMIT)
 			continue;
 		
 		gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
@@ -1172,7 +1173,7 @@
 		}
 		
 		/* XXX: arbitrary limit */
-		if (LC_LUMINOSITY(col) < LC_LUMINOSITY_LIMIT)
+		if (INPR(lcd->colw, col) < LC_LUMINOSITY_LIMIT)
 			continue;
 		
 		gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
@@ -1233,6 +1234,25 @@
 	lcd->error_rate= re->r.lightcuts_max_error;
 	lcd->scene_diag= RE_ray_tree_max_size(re->raytree);
 	
+	switch (re->r.lightcuts_color_weight) {
+	case 0x1:
+		lcd->colw[0]= 0.316;
+		lcd->colw[1]= 0.460;
+		lcd->colw[2]= 0.224;
+		break;
+	case 0x2:
+		lcd->colw[0]= 0.333;
+		lcd->colw[1]= 0.334;
+		lcd->colw[2]= 0.333;
+		break;
+	case 0x0:
+	default:
+		lcd->colw[0]= 0.299;
+		lcd->colw[1]= 0.587;
+		lcd->colw[2]= 0.114;
+		break;
+	}
+	
 	if (re->r.lightcuts_env_map > 0)
 		convert_environment_map(re, lcd, re->r.lightcuts_env_map);
 
@@ -1288,9 +1308,9 @@
 	/* build light trees */
 	for (i= 0; i < _TREES_SIZE; i++) {
 		if (lcd->trees[i].counter > 0) {
-			lightcuts_fill_array(pointlights, &lcd->trees[i], i);
+			lightcuts_fill_array(pointlights, &lcd->trees[i], i, lcd->colw);
 			printf("Lightcuts: building %s tree - ", tree_names[i]);
-			lightcuts_build_tree2(&lcd->trees[i], lcd->scene_diag * lcd->scene_diag);
+			lightcuts_build_tree2(lcd, i);
 		}
 	}
 	
@@ -1772,7 +1792,7 @@
 		}
 #endif
 
-		if (LC_LUMINOSITY2(totest_shad, totest_spec) * lcd->error_rate > cn_hinode->error_bound * hinode->luminance) {
+		if ((INPR(lcd->colw,totest_shad)+INPR(lcd->colw,totest_spec)) * lcd->error_rate > cn_hinode->error_bound * hinode->luminance) {
 			break;
 		} else {
 			LightcutsCluster *rep= &array[hinode->child1];

Modified: branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c	2008-08-12 15:44:29 UTC (rev 16068)
+++ branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c	2008-08-12 16:57:38 UTC (rev 16069)
@@ -3440,17 +3440,23 @@
 	block= uiNewBlock(&curarea->uiblocks, "render_panel_lightcuts", UI_EMBOSS, UI_HELV, curarea->win);
 	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");
+	uiDefButBitI(block, TOG, R_LIGHTCUTS, B_DIFF, "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, 96, 20, &G.scene->r.lightcuts_max_lights, 0, 100000, 0, 0, "The maximum number of lights to generate");
-	uiDefButI(block, NUM, B_REDR, "AL density:", 692 + 96, 98, 96, 20, &G.scene->r.lightcuts_area_density, 0, 5000, 0, 0, "How many point lights per unit area are used for area lights");
-	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");
+	uiDefButF(block, NUM, B_DIFF, "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_DIFF, "Lights:", 692, 98, 96, 20, &G.scene->r.lightcuts_max_lights, 0, 100000, 0, 0, "The maximum number of lights to generate");
+	uiDefButI(block, NUM, B_DIFF, "AL density:", 692 + 96, 98, 96, 20, &G.scene->r.lightcuts_area_density, 0, 5000, 0, 0, "How many point lights per unit area are used for area lights");
+	uiDefButI(block, NUM, B_DIFF, "Max cut:", 692, 76, 192, 20, &G.scene->r.lightcuts_max_cut, 0, 5000, 0, 0, "The maximum size of the cut");
 	uiDefButBitI(block, TOG, SCE_PASS_LCFAUX, B_SET_PASS, "False color", 692, 54, 192, 20, &srl->passflag, 0, 0, 0, 0, "Deliver false color pass");
-	uiDefButI(block, NUM, B_REDR, "Environment map:", 692, 32, 192, 20, &G.scene->r.lightcuts_env_map, 0, 10000, 0, 0, "How many point lights are used to convert the environment map");
-	uiDefButF(block, NUM, B_REDR, "Indirect 1/fac:", 692, 10, 192, 20, &G.scene->r.lightcuts_indir_fac, 1.0, 100000.0, 0, 0, "Indirect lighting factor: raise to reduce intensity");
-	uiDefButI(block, NUM, B_REDR, "Indirect lights:", 692, 10-22, 96+48, 20, &G.scene->r.lightcuts_indirect, 0, 20, 0, 0, "Number of indirect lights per direct light");
-	uiDefButBitI(block, TOG, 0x1, B_REDR, "Rand", 692+96+48, 10-22, 96-48, 20, &G.scene->r.lightcuts_random_dirs, 0, 0, 0, 0, "Enable random dirs");
+	uiDefButI(block, NUM, B_DIFF, "Environment map:", 692, 32, 192, 20, &G.scene->r.lightcuts_env_map, 0, 10000, 0, 0, "How many point lights are used to convert the environment map");
+	uiDefButF(block, NUM, B_DIFF, "Indirect 1/fac:", 692, 10, 192, 20, &G.scene->r.lightcuts_indir_fac, 1.0, 100000.0, 0, 0, "Indirect lighting factor: raise to reduce intensity");
+	uiDefButI(block, NUM, B_DIFF, "Indirect lights:", 692, 10-22, 96+48, 20, &G.scene->r.lightcuts_indirect, 0, 20, 0, 0, "Number of indirect lights per direct light");
+	uiDefButBitS(block, TOG, 0x1, B_DIFF, "Rand", 692+96+48, 10-22, 96-48, 20, &G.scene->r.lightcuts_random_dirs, 0, 0, 0, 0, "Enable random dirs");
+	
+	uiBlockBeginAlign(block);
+	uiDefButS(block, ROW, B_DIFF, "R601", 692, 10-44, 64, 20, &G.scene->r.lightcuts_color_weight, 0, 0, 0, 0, "R601 color weights: 0.299r 0.587g 0.114");
+	uiDefButS(block, ROW, B_DIFF, "Mid", 692+64, 10-44, 64, 20, &G.scene->r.lightcuts_color_weight, 0, 1, 0, 0, "Midway color weights: 0.316r 0.460g 0.224g");
+	uiDefButS(block, ROW, B_DIFF, "Even", 692+128, 10-44, 64, 20, &G.scene->r.lightcuts_color_weight, 0, 2, 0, 0, "Even color weights: 1/3r 1/3g 1/3b");
+	uiBlockEndAlign(block);
 }
 
 void render_panels()





More information about the Bf-blender-cvs mailing list