[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14672] branches/soc-2008-unclezeiv/source /blender: - added a lightcuts panel and a lightcuts mode (R_LIGHTCUTS)
Davide Vercelli
davide.vercelli at gmail.com
Sun May 4 12:53:51 CEST 2008
Revision: 14672
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14672
Author: unclezeiv
Date: 2008-05-04 12:53:47 +0200 (Sun, 04 May 2008)
Log Message:
-----------
- added a lightcuts panel and a lightcuts mode (R_LIGHTCUTS)
- changed rendering code iterating through lights: instead of using re.lights directly, this is now done indirectly via an iterator interface
- added proof-of-concept code for lightcuts:
- initialization step creates some random lights
- light iterator randomly selects a subset of available lights
Of course this produces meaningless (if funny) images, but with this structure in place everything should be ready to start actual development.
Modified Paths:
--------------
branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h
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/include/rendercore.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/pixelshading.c
branches/soc-2008-unclezeiv/source/blender/render/intern/source/rendercore.c
branches/soc-2008-unclezeiv/source/blender/render/intern/source/shadeoutput.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-05-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h 2008-05-04 10:53:47 UTC (rev 14672)
@@ -593,6 +593,7 @@
#define R_NO_OVERWRITE 0x400000 /* skip existing files */
#define R_TOUCH 0x800000 /* touch files before rendering */
#define R_SIMPLIFY 0x1000000
+#define R_LIGHTCUTS 0x2000000
/* filtertype */
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-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/include/lightcuts.h 2008-05-04 10:53:47 UTC (rev 14672)
@@ -28,4 +28,11 @@
#ifndef LIGHTCUTS_H_
#define LIGHTCUTS_H_
+#include "render_types.h"
+#include "rendercore.h"
+
+void lightcuts_create_point_lights(Render * re);
+
+LampRen* lightcuts_iter_lights(LampIterData ** lida);
+
#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-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/include/render_types.h 2008-05-04 10:53:47 UTC (rev 14672)
@@ -180,6 +180,7 @@
ListBase lights; /* GroupObject pointers */
ListBase lampren; /* storage, for free */
+ ListBase pointlights; /* for lightcuts */
ListBase objecttable;
Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/include/rendercore.h
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/include/rendercore.h 2008-05-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/include/rendercore.h 2008-05-04 10:53:47 UTC (rev 14672)
@@ -90,7 +90,14 @@
int get_sample_layers(struct RenderPart *pa, struct RenderLayer *rl, struct RenderLayer **rlpp);
+/* ------------------------------------------------------------------------- */
+typedef struct LampIterData {} LampIterData;
+typedef LampRen* (*LightIter)(LampIterData **);
+
+LampIterData * light_iter_init();
+LightIter light_get_iter();
+
/* -------- ray.c ------- */
extern void freeraytree(Render *re);
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-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/convertblender.c 2008-05-04 10:53:47 UTC (rev 14672)
@@ -100,6 +100,7 @@
#include "IMB_imbuf_types.h"
#include "envmap.h"
+#include "lightcuts.h"
#include "multires.h"
#include "occlusion.h"
#include "render_types.h"
@@ -4394,6 +4395,7 @@
BLI_freelistN(&re->lampren);
BLI_freelistN(&re->lights);
+ BLI_freelistN(&re->pointlights);
free_renderdata_tables(re);
@@ -4781,6 +4783,7 @@
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 */
@@ -4879,6 +4882,10 @@
if((re->r.mode & R_SSS) && !re->test_break())
if(re->r.renderer==R_INTERN)
make_sss_tree(re);
+
+ /* lightcuts */
+ if((re->r.mode & R_LIGHTCUTS) && !re->test_break())
+ lightcuts_create_point_lights(re);
}
if(re->test_break())
@@ -4919,6 +4926,7 @@
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;
@@ -5438,6 +5446,7 @@
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-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 2008-05-04 10:53:47 UTC (rev 14672)
@@ -24,3 +24,164 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
+
+#include <math.h>
+#include <string.h>
+
+#include "lightcuts.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_rand.h"
+#include "DNA_group_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_listBase.h"
+#include "MEM_guardedalloc.h"
+#include "RE_pipeline.h"
+
+#include "render_types.h"
+
+#define max(a,b) ((a)>(b)?(a):(b))
+
+/*
+ * TODO: this is a temporary function, I need a proper initializer
+ * right now this code is partly copied from add_render_lamp()
+ */
+static void init_lamp_data(Render * re, LampRen * lar)
+{
+ if(re->r.mode & R_SHADOW) {
+
+ if(lar->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && (lar->ray_samp_method == LA_SAMP_CONSTANT)) {
+ init_jitter_plane(lar);
+ }
+
+ else if (lar->type==LA_SPOT && (lar->mode & LA_SHAD_BUF) ) {
+ /* Per lamp, one shadow buffer is made. */
+#if 0
+// TODO: matrix mat is not available here
+ lar->bufflag= la->bufflag;
+ Mat4CpyMat4(mat, ob->obmat);
+ initshadowbuf(re, lar, mat); // mat is altered
+#endif
+ }
+
+ /* this is the way used all over to check for shadow */
+ if(lar->shb || (lar->mode & LA_SHAD_RAY)) {
+ LampShadowSample *ls;
+ LampShadowSubSample *lss;
+ int a, b;
+
+ memset(re->shadowsamplenr, 0, sizeof(re->shadowsamplenr));
+
+ lar->shadsamp= MEM_mallocN(re->r.threads*sizeof(LampShadowSample), "lamp shadow sample");
+ ls= lar->shadsamp;
+
+ /* shadfacs actually mean light, let's put them to 1 to prevent unitialized accidents */
+ for(a=0; a<re->r.threads; a++, ls++) {
+ lss= ls->s;
+ for(b=0; b<re->r.osa; b++, lss++) {
+ lss->samplenr= -1; /* used to detect whether we store or read */
+ lss->shadfac[0]= 1.0f;
+ lss->shadfac[1]= 1.0f;
+ lss->shadfac[2]= 1.0f;
+ lss->shadfac[3]= 1.0f;
+ }
+ }
+ }
+ }
+}
+
+/*
+ * proof-of-concept functionality:
+ * for each existing "lamp" or "sun", add another one, identical but:
+ * - having a random colour
+ * - displaced of 1 unit along light direction
+ */
+void lightcuts_create_point_lights(Render * re)
+{
+ GroupObject *go, *gonew;
+ ListBase *lights = &re->lights;
+ ListBase *pointlights = &re->pointlights;
+ LampRen *lar, *larnew;
+ float r, g, b, n;
+ int count = 0;
+
+ for(go=lights->first; go; go= go->next) {
+ lar= go->lampren;
+ if(lar==NULL) continue;
+
+ count += 2;
+
+ /* first copy the initial light */
+ gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
+ BLI_addtail(pointlights, gonew);
+ gonew->lampren= lar;
+ gonew->ob= 0;
+ gonew->recalc= go->recalc;
+
+ if (lar->type!=LA_LOCAL && lar->type!=LA_SUN)
+ continue;
+
+ /* then create a new one */
+ gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
+ BLI_addtail(pointlights, gonew);
+ gonew->recalc= go->recalc;
+ /*
+ * XXX: probably wrong, more a test to see if it is used somewhere
+ * or dealloacated
+ * The point here is that we create new lights with no corresponding
+ * objects... do we need objects there?
+ */
+ gonew->ob= 0;
+
+ larnew = (LampRen *)MEM_callocN(sizeof(LampRen), "lampren");
+ memcpy(larnew, lar, sizeof(LampRen));
+
+ /* beware of copying pointers, or destruction will have problems */
+ larnew->shb = NULL;
+ larnew->jitter = NULL;
+ larnew->shadsamp = NULL;
+ larnew->curfalloff = NULL;
+
+ init_lamp_data(re, larnew);
+
+ r = BLI_frand();
+ g = BLI_frand();
+ b = BLI_frand();
+ n = sqrt(r*r + g*g + b*b);
+
+ larnew->r = r / n;
+ larnew->g = g / n;
+ larnew->b = b / n;
+
+ /* move forward 1 unit in light direction */
+ VecAddf(larnew->co, larnew->co, larnew->vec);
+
+ BLI_addtail(&re->lampren, larnew);
+ gonew->lampren= larnew;
+ }
+}
+
+/*
+ * proof-of-concept functionality:
+ * skip lights randomly while iterating
+ */
+LampRen* lightcuts_iter_lights(LampIterData ** lida)
+{
+ GroupObject * go;
+ int skip = BLI_rand() % 3;
+
+ if (!lida || !(*lida))
+ return NULL;
+
+ for (go = ((GroupObject *)(*lida))->next; go; go=go->next)
+ {
+ if (go->lampren && (--skip) < 0)
+ {
+ *lida = (LampIterData*)(go);
+ return go->lampren;
+ }
+ }
+
+ return NULL;
+}
Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/pixelshading.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/pixelshading.c 2008-05-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/pixelshading.c 2008-05-04 10:53:47 UTC (rev 14672)
@@ -69,7 +69,8 @@
static void render_lighting_halo(HaloRen *har, float *colf)
{
- GroupObject *go;
+ LampIterData *liter;
+ LightIter light_iter;
LampRen *lar;
float i, inp, inpr, rco[3], dco[3], lv[3], lampdist, ld, t, *vn;
float ir, ig, ib, shadfac, soft, lacol[3];
@@ -81,8 +82,9 @@
vn= har->no;
- for(go=R.lights.first; go; go= go->next) {
- lar= go->lampren;
+ liter = light_iter_init();
+ light_iter = light_get_iter();
+ while((lar=light_iter(&liter))) {
/* test for lamplayer */
if(lar->mode & LA_LAYER) if((lar->lay & har->lay)==0) continue;
Modified: branches/soc-2008-unclezeiv/source/blender/render/intern/source/rendercore.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/rendercore.c 2008-05-04 10:48:45 UTC (rev 14671)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/rendercore.c 2008-05-04 10:53:47 UTC (rev 14672)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list