[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16311] branches/soc-2008-unclezeiv/source /blender: Added support for multiple bounces.
Davide Vercelli
davide.vercelli at gmail.com
Sat Aug 30 23:50:23 CEST 2008
Revision: 16311
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16311
Author: unclezeiv
Date: 2008-08-30 23:50:23 +0200 (Sat, 30 Aug 2008)
Log Message:
-----------
Added support for multiple bounces. Also fixed a numerical error that could give long tree building times and black screens.
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-08-30 21:41:02 UTC (rev 16310)
+++ branches/soc-2008-unclezeiv/source/blender/blenloader/intern/readfile.c 2008-08-30 21:50:23 UTC (rev 16311)
@@ -7786,6 +7786,8 @@
r->lightcuts_color_weight= 1;
if(r->lightcuts_env_map_fac==0.0f)
r->lightcuts_env_map_fac= 1.0f;
+ if(r->lightcuts_indir_bounces==0)
+ r->lightcuts_indir_bounces= 1;
}
sce= sce->id.next;
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-30 21:41:02 UTC (rev 16310)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h 2008-08-30 21:50:23 UTC (rev 16311)
@@ -319,7 +319,7 @@
short lightcuts_env_map;
short lightcuts_indirect;
short lightcuts_color_weight;
- short lightcuts_pad;
+ short lightcuts_indir_bounces;
float lightcuts_indir_fac;
int lightcuts_options;
float lightcuts_indir_dist;
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-30 21:41:02 UTC (rev 16310)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-08-30 21:50:23 UTC (rev 16311)
@@ -94,7 +94,7 @@
#define LC_OPT_FIXED_DIRS 0x0001
#define LC_OPT_ONLY_INDIR 0x0002
-#define LC_OPT_2ND_BOUNCE 0x0004
+// #define LC_OPT_2ND_BOUNCE 0x0004
#define LC_OPT_ENV_LIGHT 0x0008
#define LC_OPT_INDIR_MESH 0x0010
#define LC_OPT_NO_CLAMP 0x0020
@@ -205,6 +205,8 @@
float scene_min[3], scene_max[3];
float indir_fac;
float indir_dist;
+ short indir_bounces;
+ short pad;
int do_indir;
int options;
@@ -242,7 +244,7 @@
#define IS_LEAF(node) (!(node)->child1 && !(node)->child2)
#define LC_LUMINOSITY_LIMIT (0.0001f)
-static void add_virtual_point_light(Render * re, LightcutsData *lcd, LampRen *orig, float *col, int lev);
+static void add_virtual_point_light(Render * re, LightcutsData *lcd, LampRen *orig, float *col, short lev, float weight);
/* XXX: this function looks really slow! */
static float get_bounding_cone(LightcutsCluster * one, LightcutsCluster * two, float *vec)
@@ -992,10 +994,8 @@
}
/* indirect lighting */
- for (i= 0; i < lcd->do_indir; i++) {
- int lev= (lcd->options & LC_OPT_2ND_BOUNCE) ? 1 : 0;
- add_virtual_point_light(re, lcd, lar, col, lev);
- }
+ for (i= 0; i < lcd->do_indir; i++)
+ add_virtual_point_light(re, lcd, lar, col, lcd->indir_bounces, 1.0f / lcd->do_indir);
if (lcd->do_indir > 0 && (lcd->options & LC_OPT_ONLY_INDIR))
continue;
@@ -1319,7 +1319,7 @@
max_col= MAX3(shr.col[0], shr.col[1], shr.col[2]);
- if (max_col==0.0f) {
+ if (max_col <= FLT_EPSILON) {
lcd->stat_discard_black+= 10000;
return 0.0f;
}
@@ -1330,7 +1330,7 @@
return shr.diff[max_idx] / shr.col[max_idx];
}
-static void add_virtual_point_light(Render * re, LightcutsData *lcd, LampRen *orig, float *col, int lev)
+static void add_virtual_point_light(Render * re, LightcutsData *lcd, LampRen *orig, float *col, short lev, float weight)
{
LampRen *lar;
VlakRen *vla;
@@ -1389,17 +1389,17 @@
fac= get_bounce_color(lcd, isec.ob, vla, co, orig, scol, isec.isect);
- if (fac == 0.0f) {
+ if (fac <= 0.0f) {
lcd->stat_discard_black++;
return;
}
-#ifdef LIGHTCUTS_DEBUG
- if ((lcd->options & LC_DBG_INDIR_DISCARD_NAN) && fac >= 0.499f) {
+// #ifdef LIGHTCUTS_DEBUG
+ if (/*(lcd->options & LC_DBG_INDIR_DISCARD_NAN) && */fac >= (1.0f / M_PI)) {
lcd->stat_discard_nan++;
return;
}
-#endif
+// #endif
lar= &lcd->lampren_pool[lcd->pool_counter++];
lamp_init(re, lar);
@@ -1423,7 +1423,7 @@
lar->ray_samp_method= LA_SAMP_CONSTANT;
/* note that lamp_get_visibility is called in get_bounce_color */
- lar->energy= fac * orig->energy * (lev + 1) * lcd->indir_fac / lcd->do_indir;
+ lar->energy= fac * orig->energy * lcd->indir_fac * weight;
/* TODO: without proper spectrum handling, this could be too darkening */
scol[0]*= col[0];
@@ -1446,8 +1446,8 @@
lcd->trees[TREE_SPOT].counter++;
lcd->vpl_counter++;
- if (lev > 0)
- add_virtual_point_light(re, lcd, lar, scol, lev - 1);
+ if (lev > 1)
+ add_virtual_point_light(re, lcd, lar, scol, lev - 1, 1.0f);
}
static float get_area_light_actual_area(LampRen *lar)
@@ -1537,10 +1537,8 @@
lar->energy= orig->energy * factor;
/* indirect lighting */
- for (i= 0; i < lcd->do_indir; i++) {
- int lev= (lcd->options & LC_OPT_2ND_BOUNCE) ? 1 : 0;
- add_virtual_point_light(re, lcd, lar, col, lev);
- }
+ for (i= 0; i < lcd->do_indir; i++)
+ add_virtual_point_light(re, lcd, lar, col, lcd->indir_bounces, 1.0f / lcd->do_indir);
if (lcd->do_indir > 0 && (lcd->options & LC_OPT_ONLY_INDIR))
continue;
@@ -1567,6 +1565,7 @@
re->lcdata = lcd = MEM_callocN(sizeof(LightcutsData), "LightcutsData");
lcd->indir_fac= re->r.lightcuts_indir_fac;
lcd->indir_dist= re->r.lightcuts_indir_dist;
+ lcd->indir_bounces= re->r.lightcuts_indir_bounces;
lcd->do_indir= re->r.lightcuts_indirect;
lcd->options= re->r.lightcuts_options;
lcd->error_rate= re->r.lightcuts_max_error;
@@ -1576,9 +1575,6 @@
#endif
RE_ray_tree_aabb(re->raytree, lcd->scene_min, lcd->scene_max);
- if (lcd->options & LC_OPT_2ND_BOUNCE)
- lcd->indir_fac /= 2.0f;
-
switch (re->r.lightcuts_color_weight) {
case 0x1:
lcd->colw[0]= 0.316;
@@ -1631,11 +1627,8 @@
n_generated+= re->r.lightcuts_env_map;
if (lcd->do_indir > 0) {
- n_vpl= (n_orig + n_generated) * lcd->do_indir;
+ n_vpl= (n_orig + n_generated) * lcd->do_indir * lcd->indir_bounces;
- if (lcd->options & LC_OPT_2ND_BOUNCE)
- n_vpl += n_vpl * lcd->do_indir;
-
/* allocate array to hold coordinates for all possible virtual point lights */
if (lcd->options & LC_OPT_INDIR_MESH && n_vpl != 0)
lcd->dbg_vis_vpl= MEM_callocN(sizeof(float) * 3 * n_vpl, "lc_vpl_visualization");
@@ -1683,9 +1676,8 @@
if (lcd->do_indir > 0) {
int i;
for (i= 0; i < lcd->do_indir; i++) {
- int lev= (lcd->options & LC_OPT_2ND_BOUNCE) ? 1 : 0;
float col[3] = {lar->r, lar->g, lar->b};
- add_virtual_point_light(re, lcd, lar, col, lev);
+ add_virtual_point_light(re, lcd, lar, col, lcd->indir_bounces, 1.0f / lcd->do_indir);
}
if (lcd->options & LC_OPT_ONLY_INDIR)
Modified: branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c 2008-08-30 21:41:02 UTC (rev 16310)
+++ branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c 2008-08-30 21:50:23 UTC (rev 16311)
@@ -3462,8 +3462,8 @@
/* TODO: yep, magic numbers, but they are going to change soon anyway */
uiDefButBitI(block, TOG, 0x0080, B_DIFF, "No spec", 0, -162, 62, 20, &G.scene->r.lightcuts_options, 0, 0, 0, 0, "Disable specular from indirect lighting");
uiDefButF(block, NUM, B_DIFF, "Fac:", 63, -162, 128, 20, &G.scene->r.lightcuts_indir_fac, 1.0, 100000.0, 0, 0, "Indirect lighting factor");
- uiDefButBitI(block, TOG, 0x4, B_DIFF, "2nd", 0, -184, 62, 20, &G.scene->r.lightcuts_options, 0, 0, 0, 0, "Enable second bounce for indirect lighting");
- uiDefButF(block, NUM, B_DIFF, "Dist:", 63, -184, 128, 20, &G.scene->r.lightcuts_indir_dist, 0.001, 1000.0, 0, 0, "Distance for indirect lights");
+ uiDefButS(block, NUM, B_DIFF, "Bounces", 0, -184, 95, 20, &G.scene->r.lightcuts_indir_bounces, 1, 10, 0, 0, "Select number of bounces for indirect lighting");
+ uiDefButF(block, NUM, B_DIFF, "Dist:", 97, -184, 95, 20, &G.scene->r.lightcuts_indir_dist, 0.001, 1000.0, 0, 0, "Distance for indirect lights");
uiBlockEndAlign(block);
uiBlockBeginAlign(block);
More information about the Bf-blender-cvs
mailing list