[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15404] branches/soc-2008-unclezeiv/source /blender/render/intern/source/lightcuts.c: Moved area light conversion code in its own function.
Davide Vercelli
davide.vercelli at gmail.com
Wed Jul 2 13:47:14 CEST 2008
Revision: 15404
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15404
Author: unclezeiv
Date: 2008-07-02 13:45:37 +0200 (Wed, 02 Jul 2008)
Log Message:
-----------
Moved area light conversion code in its own function. Fixed a bug that led to incorrect distribution of lights on the y direction.
Modified Paths:
--------------
branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-07-02 02:05:33 UTC (rev 15403)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-07-02 11:45:37 UTC (rev 15404)
@@ -431,7 +431,6 @@
MEM_freeN(pair_array);
}
-
static void create_lamp_oriented(Render * re, LampRen * lar, LampRen * orig)
{
/* float xs, ys, dist; */
@@ -566,6 +565,85 @@
*/
}
+static void convert_area_light(Render * re, LightcutsData *lcd, LampRen *orig)
+{
+ GroupObject *gonew;
+ int x, y, smpx, smpy;
+ float area, gapx, gapy, factor, realw, realh;
+ float xdir[3];
+ float ydir[3];
+ float stepx, stepy;
+ LampRen *lar;
+ float density;
+
+ density= sqrtf(re->r.lightcuts_area_density);
+
+ VECCOPY(xdir, orig->mat[0]);
+ VECCOPY(ydir, orig->mat[1]);
+
+ realw= sqrtf(VEC_LEN_SQ(orig->mat[0])) * orig->area_size;
+ realh= sqrtf(VEC_LEN_SQ(orig->mat[1])) * orig->area_sizey;
+
+ area= realw * realh;
+ smpx= MAX2((int)(density * realw), 1);
+ smpy= MAX2((int)(density * realh), 1);
+ gapx= 1.0 / (float)(smpx);
+ gapy= 1.0 / (float)(smpy);
+ factor= 0.5f * sqrtf(orig->dist) * area / (smpx * smpy);
+
+ /* XXX: TODO: temporary check just to avoid freezing on undue densities */
+ if (lcd->light_counter + smpx * smpy > re->r.lightcuts_max_lights) {
+ printf("Err: required light density would violate light limit\n");
+ return;
+ }
+
+ for (x=0; x<smpx; x++) {
+ for (y=0; y<smpy; y++) {
+ gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
+ BLI_addtail(&lcd->pointlights, gonew);
+ /* gonew->recalc= go->recalc; // XXX: what is this? */
+ /*
+ * XXX: probably wrong, more a test to see if it is used somewhere
+ * or deallocated
+ * The point here is that we create new lights with no corresponding
+ * objects... do we need objects there?
+ */
+ gonew->ob= 0; /* XXX: or go->ob */
+
+ lar = (LampRen *)MEM_callocN(sizeof(LampRen), "lampren");
+
+ create_lamp_oriented(re, lar, orig);
+ lar->r= orig->r * factor;
+ lar->g= orig->g * factor;
+ lar->b= orig->b * factor;
+ lar->energy= orig->energy * factor;
+
+ /* place a light in its own square with random jittering */
+ stepx= orig->area_size * (gapx * (x + BLI_frand()) - 0.5f);
+ stepy= orig->area_sizey * (gapy * (y + BLI_frand()) - 0.5f);
+ lar->co[0]= orig->co[0] + xdir[0] * stepx + ydir[0] * stepy;
+ lar->co[1]= orig->co[1] + xdir[1] * stepx + ydir[1] * stepy;
+ lar->co[2]= orig->co[2] + xdir[2] * stepx + ydir[2] * stepy;
+
+#ifdef LIGHTCUTS_DEBUG
+ printf("coordinates: %4f %4f %4f\n", lar->co[0], lar->co[1], lar->co[2]);
+#endif
+
+ BLI_addtail(&re->lampren, lar);
+ /* check deallocation */
+ gonew->lampren= lar;
+
+ /* TODO: handle other attenuation models */
+ if (lar->dist < lcd->max_spot_dist)
+ lcd->max_spot_dist= lar->dist;
+
+ lcd->trees[TREE_SPOT].counter++;
+ lcd->light_counter++;
+ lar->ray_samp_method = LA_SAMP_CONSTANT;
+ }
+ }
+}
+
void lightcuts_init(Render * re)
{
LightcutsData *lcd;
@@ -575,7 +653,6 @@
LampRen *lar;
char tree_time_str[12]; /* length 12 required by BLI_timestr */
int i;
- float density;
re->i.infostr= "Initializing Lightcuts";
re->stats_draw(&re->i);
@@ -585,84 +662,13 @@
lcd->max_local_dist= MAXFLOAT;
lcd->max_spot_dist= MAXFLOAT;
lcd->light_counter= 0;
- density= sqrtf(re->r.lightcuts_area_density);
for(go=lights->first; go; go= go->next) {
lar= go->lampren;
if(lar==NULL) continue;
if (lar->type == LA_AREA) {
- int x, y, smpx, smpy;
- float area, gapx, gapy, factor, realw, realh;
- float xdir[3];
- float ydir[3];
- float stepx, stepy;
- LampRen *orig= lar;
-
- VECCOPY(xdir, orig->mat[0]);
- VECCOPY(ydir, orig->mat[1]);
-
- realw= sqrtf(VEC_LEN_SQ(orig->mat[0])) * orig->area_size;
- realh= sqrtf(VEC_LEN_SQ(orig->mat[1])) * orig->area_sizey;
-
- area= realw * realh;
- smpx= MAX2((int)(density * realw), 1);
- smpy= MAX2((int)(density * realh), 1);
- gapx= 1.0 / (float)(smpx);
- gapy= 1.0 / (float)(smpx);
- factor= 2.0f * area / (smpx * smpy);
-
- /* XXX: TODO: temporary check just to avoid freezing on undue densities */
- if (lcd->light_counter + smpx * smpy > re->r.lightcuts_max_lights) {
- printf("Err: required light density would violate light limit\n");
- continue;
- }
-
- for (x=0; x<smpx; x++) {
- for (y=0; y<smpy; y++) {
- gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
- BLI_addtail(pointlights, gonew);
- gonew->recalc= go->recalc; /* XXX: what is this? */
- /*
- * XXX: probably wrong, more a test to see if it is used somewhere
- * or deallocated
- * The point here is that we create new lights with no corresponding
- * objects... do we need objects there?
- */
- gonew->ob= 0; /* XXX: or go->ob */
-
- lar = (LampRen *)MEM_callocN(sizeof(LampRen), "lampren");
-
- create_lamp_oriented(re, lar, orig);
- lar->r= orig->r * factor;
- lar->g= orig->g * factor;
- lar->b= orig->b * factor;
- lar->energy= orig->energy * factor;
-
- /* place a light in its own square with random jittering */
- stepx= orig->area_size * (gapx * (x + BLI_frand()) - 0.5f);
- stepy= orig->area_sizey * (gapy * (y + BLI_frand()) - 0.5f);
- lar->co[0]= orig->co[0] + xdir[0] * stepx + ydir[0] * stepy;
- lar->co[1]= orig->co[1] + xdir[1] * stepx + ydir[1] * stepy;
- lar->co[2]= orig->co[2] + xdir[2] * stepx + ydir[2] * stepy;
-
-#ifdef LIGHTCUTS_DEBUG
- printf("coordinates: %4f %4f %4f\n", lar->co[0], lar->co[1], lar->co[2]);
-#endif
-
- BLI_addtail(&re->lampren, lar);
- /* check deallocation */
- gonew->lampren= lar;
-
- /* TODO: handle other attenuation models */
- if (lar->dist < lcd->max_spot_dist)
- lcd->max_spot_dist= lar->dist;
-
- lcd->trees[TREE_SPOT].counter++;
- lcd->light_counter++;
- lar->ray_samp_method = LA_SAMP_CONSTANT;
- }
- }
+ convert_area_light(re, lcd, lar);
continue;
}
More information about the Bf-blender-cvs
mailing list