[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15415] branches/soc-2008-unclezeiv/source /blender: Initial commit for environment map light generation: it is currently based on a simple hammersley sampling scheme.
Davide Vercelli
davide.vercelli at gmail.com
Thu Jul 3 16:48:27 CEST 2008
Revision: 15415
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15415
Author: unclezeiv
Date: 2008-07-03 16:47:07 +0200 (Thu, 03 Jul 2008)
Log Message:
-----------
Initial commit for environment map light generation: it is currently based on a simple hammersley sampling scheme. The number of samples can be selected from the Lightcuts panel, while the environment map intensity can be changed as usual under Shading > World > Range.
Known issues: on a specific test file the first rendering goes wrong as if Blender thinks that no sky textures are present; subsequent renderings are fine. Please send me confirmation of this bug if you happen to stumble on it.
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-07-03 10:38:35 UTC (rev 15414)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h 2008-07-03 14:47:07 UTC (rev 15415)
@@ -317,7 +317,7 @@
int lightcuts_max_lights;
int lightcuts_max_cut;
int lightcuts_area_density;
- float lightcuts_unused;
+ int lightcuts_env_map;
int pad4;
} RenderData;
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-03 10:38:35 UTC (rev 15414)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-07-03 14:47:07 UTC (rev 15415)
@@ -43,6 +43,7 @@
#include "RE_raytrace.h"
#include "blendef.h"
+#include "pixelshading.h"
#include "render_types.h"
/* #define LIGHTCUTS_DEBUG */
@@ -431,18 +432,15 @@
MEM_freeN(pair_array);
}
-static void create_lamp_oriented(Render * re, LampRen * lar, LampRen * orig)
+static void init_lamp(Render * re, LampRen * lar)
{
- /* float xs, ys, dist; */
+ /* float xs, ys, dist, distkw; */
/* TODO: what is xs ys ?? where are they used? */
- lar->dist= orig->dist;
- lar->distkw= lar->dist * lar->dist; /* who uses this? */
/* float co[3]; */
/* initialize later */
/* short type, mode; */
- lar->type = LA_SPOT;
lar->mode = LA_SHAD_RAY; /* at least */
/* float r, g, b, k; k is GAMMA */
@@ -454,14 +452,11 @@
/* int lay; */
/* TODO: check thislayer stuff... */
- lar->lay= orig->lay;
/* float spotsi,spotbl; */
lar->spotsi= 0.0f; /* it's actually the cosine; TODO: check if it's ok */
/* float vec[3]; */
- /* same as original area light */
- VECCOPY(lar->vec, orig->vec);
/* float xsp, ysp, distkw, inpr; TODO: unknown uses!! */
/* float halokw, halo; TODO: unknown uses!! */
@@ -508,13 +503,11 @@
/* float *jitter; */
/* float imat[3][3]; */
- Mat3CpyMat3(lar->imat, orig->imat);
/* float spottexfac; */
/* float sh_invcampos[3], sh_zfac; // sh_= spothalo */
/* float mat[3][3]; // 3x3 part from lampmat x viewmat */
- Mat3CpyMat3(lar->mat, orig->mat);
/* float area[8][3], areasize; */
/* passes & node shader support: all shadow info for a pixel */
@@ -565,6 +558,117 @@
*/
}
+static void create_lamp_oriented(Render * re, LampRen * lar, LampRen * orig)
+{
+ init_lamp(re, lar);
+ lar->dist= orig->dist;
+ lar->distkw= lar->dist * lar->dist; /* who uses this? */
+
+ lar->lay= orig->lay;
+ /* same as original area light */
+ VECCOPY(lar->vec, orig->vec);
+ Mat3CpyMat3(lar->imat, orig->imat);
+ Mat3CpyMat3(lar->mat, orig->mat);
+ lar->type = LA_SPOT;
+}
+
+
+static void convert_environment_map(Render *re, LightcutsData *lcd, int n)
+{
+ GroupObject *gonew;
+ LampRen *lar;
+ int k, kk;
+ float t, p, phi, phirad, st;
+ float maxc;
+
+ float col[3], co[3];
+ float dxyview[2];
+
+ /* XXX: not sure about this */
+ dxyview[0]= dxyview[1]= 1.0f/(sqrtf((float)n));
+
+ for (k= 0; k < n; k++) {
+ /*
+ * hammersley algorithm, from
+ * Wong, Luk, Heng "Sampling with Hammersley and Halton Points"
+ * Journal of Graphics Tools , vol. 2, no. 2, 1997, pp 9-24.
+ */
+ t= 0.0f;
+ p= 0.5f;
+ kk= k;
+
+ while (kk > 0) {
+ if (kk & 1)
+ t+= p;
+ p*= 0.5f;
+ kk >>= 1;
+ }
+
+ t= 2.0f * t - 1.0f;
+ phi= (k+0.5f)/n;
+ phirad= phi * 2.0 * M_PI;
+ st= sqrtf(1.0-t*t);
+
+ co[0]= st * cosf(phirad);
+ co[1]= st * sinf(phirad);
+ co[2]= t;
+
+ shadeSkyView(col, NULL, co, dxyview);
+
+ /* XXX: arbitrary limit */
+ if (LC_LUMINOSITY(col) < 0.01f)
+ continue;
+
+ 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");
+ init_lamp(re, lar);
+ lar->type = LA_SUN;
+
+ lar->lay= 0xffffffff; /* XXX: check */
+
+ VECCOPY(lar->co, co);
+ VECCOPY(lar->vec, lar->co);
+ VECNEG(lar->vec);
+
+ /*
+ * is it necessary for sun lamps?
+ * Mat3CpyMat3(lar->imat, orig->imat);
+ * Mat3CpyMat3(lar->mat, orig->mat);
+ */
+
+ /* please note: you can control this factor via Shading > World > Range */
+ lar->energy= M_PI / (float)n;
+ lar->r= col[0] * lar->energy;
+ lar->g= col[1] * lar->energy;
+ lar->b= col[2] * lar->energy;
+
+ maxc= MAX3(col[0], col[1], col[2]);
+
+ if (maxc > 1.0f) {
+ /* so that bright lights don't get excluded when n is large */
+ lar->energy *= maxc;
+ }
+
+ BLI_addtail(&re->lampren, lar);
+ /* check deallocation */
+ gonew->lampren= lar;
+
+ lcd->trees[TREE_SUN].counter++;
+ lcd->light_counter++;
+ lar->ray_samp_method = LA_SAMP_CONSTANT;
+ }
+}
+
static void convert_area_light(Render * re, LightcutsData *lcd, LampRen *orig)
{
GroupObject *gonew;
@@ -662,6 +766,9 @@
lcd->max_local_dist= MAXFLOAT;
lcd->max_spot_dist= MAXFLOAT;
lcd->light_counter= 0;
+
+ if (re->r.lightcuts_env_map > 0)
+ convert_environment_map(re, lcd, re->r.lightcuts_env_map);
for(go=lights->first; go; go= go->next) {
lar= go->lampren;
Modified: branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c 2008-07-03 10:38:35 UTC (rev 15414)
+++ branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c 2008-07-03 14:47:07 UTC (rev 15415)
@@ -3432,6 +3432,7 @@
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");
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, "Area lights light density:", 692, 32, 192, 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, "Environment map:", 692, 10, 192, 20, &G.scene->r.lightcuts_env_map, 0, 10000, 0, 0, "How many point lights are used to convert the environment map");
}
void render_panels()
More information about the Bf-blender-cvs
mailing list