Revision: 16243
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16243
Author:   unclezeiv
Date:     2008-08-24 23:14:07 +0200 (Sun, 24 Aug 2008)

Log Message:
-----------
Indirect lighting: added option to create a mesh during rendering; each virtual 
point light is represented as a vertex.

This feature was requested on blenderartists as a way to "debug" indirect 
lighting. Adding a mesh as a visualization feedback is surely a hack, but maybe 
a similar functionality should be available also in the final version: 
suggestions for better (future) implementations are welcome.

Modified Paths:
--------------
    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/render/intern/source/lightcuts.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 
2008-08-24 20:57:56 UTC (rev 16242)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 
2008-08-24 21:14:07 UTC (rev 16243)
@@ -51,6 +51,18 @@
 #include "render_types.h"
 #include "shading.h"
 
+/* includes for debug vpl visualization mesh */
+#include "BKE_customdata.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
+#include "BKE_library.h"
+#include "BKE_material.h"
+#include "BKE_object.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+
 /* #define LIGHTCUTS_DEBUG */
 
 #define LC_DBG_TREE_BUILDTIMES   0x0001
@@ -80,10 +92,11 @@
 #define FALLOFF_MIX    3
 #define FALLOFF_SLIDER 3
 
-#define LC_OPT_FIXED_DIRS 0x01
+#define LC_OPT_FIXED_DIRS  0x01
 #define LC_OPT_ONLY_INDIR  0x02
 #define LC_OPT_2ND_BOUNCE  0x04
 #define LC_OPT_ENV_LIGHT   0x08
+#define LC_OPT_INDIR_MESH  0x10
 
 /*
  * This is a table to select the "worst falloff" for a cluster, given the
@@ -194,6 +207,7 @@
        int dbg_first_pixel;
        int dbg_options;
 #endif
+       float* dbg_vis_vpl;
 } LightcutsData;
 
 typedef struct SampleCoordInfo {
@@ -1109,6 +1123,71 @@
        dir[2]= cosf(phi);
 }
 
+static void dbg_create_vpl_mesh(Render *re, LightcutsData *lcd)
+{
+       int i, newlen;
+       Mesh *mesh;
+       MVert *newvert, *tmpvert;
+       CustomData vdata;
+       Base *base;
+       Scene *scene;
+       Object *object, *camera;
+
+       mesh= add_mesh("indir_visualize");
+       MEM_freeN(mesh->bb);
+       mesh->bb= NULL;
+       mesh->id.us = 0;
+
+       /* create custom vertex data arrays and copy existing vertices into it 
*/
+       newlen = mesh->totvert + lcd->vpl_counter;
+       CustomData_copy( &mesh->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, newlen 
);
+       CustomData_copy_data( &mesh->vdata, &vdata, 0, 0, mesh->totvert );
+
+       if ( !CustomData_has_layer( &vdata, CD_MVERT ) )
+               CustomData_add_layer( &vdata, CD_MVERT, CD_CALLOC, NULL, newlen 
);
+
+       newvert = CustomData_get_layer( &vdata, CD_MVERT );
+
+       /* scan the input list and insert the new vertices */
+
+       tmpvert = &newvert[mesh->totvert];
+       for( i = 0; i < lcd->vpl_counter; ++i, ++tmpvert )
+               memcpy( tmpvert->co, &lcd->dbg_vis_vpl[3 * i], sizeof(float) * 
3 );
+       
+       CustomData_free( &mesh->vdata, mesh->totvert );
+       mesh->vdata = vdata;
+       mesh_update_customdata_pointers( mesh );
+       mesh->totvert = newlen;
+
+       object= add_only_object(OB_MESH, "indir_visualize");
+       object->data= mesh;
+       id_us_plus((ID *)mesh);
+       object->flag = SELECT;
+
+       /* link to scene */
+       scene= re->scene;
+       base= MEM_callocN( sizeof( Base ), "lc_newbase" );
+       base->object= object; /* link object to the new base */
+       base->lay= object->lay = scene->lay & ((1<<20)-1); /* Layer, by default 
visible*/
+       base->flag= SELECT;
+       object->id.us= 1; /* we will exist once in this scene */
+
+       /* finally, link new base to scene */
+       BLI_addhead( &(scene->base), base );
+
+       /* make sure data and object materials are consistent */
+       test_object_materials( (ID *)object->data );
+
+       /* copy camera location and rotation */
+       camera= scene->camera;          
+       VECCOPY(object->loc, camera->loc);
+       VECCOPY(object->dloc, camera->dloc);
+       VECCOPY(object->rot, camera->rot);
+       VECCOPY(object->drot, camera->drot);
+
+       DAG_object_flush_update(scene, object, OB_RECALC_OB);
+}
+
 /* XXX: terrible hack currently needed by get_bounce_color */
 extern struct Render R;
 
@@ -1348,6 +1427,9 @@
                        lev, co[0], co[1], co[2], scol[0], scol[1], scol[2], 
isec.vec[0], isec.vec[1], isec.vec[2]);
 #endif
        
+       if (lcd->options & LC_OPT_INDIR_MESH)
+               VECCOPY(lcd->dbg_vis_vpl + 3 * lcd->vpl_counter, co);
+       
        /* XXX: see remarks on similar code in convert_environment_map */
        go= MEM_callocN(sizeof(GroupObject), "groupobject");
        BLI_addtail(&lcd->pointlights, go);
@@ -1531,6 +1613,24 @@
                R.r.mode&= ~R_LIGHTCUTS;
        }
        
+       if (lcd->options & LC_OPT_INDIR_MESH) {
+               /* allocate array to hold coordinates for all possible virtual 
point lights */
+               int max_vpl;
+               int nlights= 0;
+               
+               for(go=lights->first; go; go= go->next) {
+                       lar= go->lampren;
+                       if(lar==NULL) continue;
+                       
+                       if (ELEM3(lar->type, LA_LOCAL, LA_SUN, LA_SPOT))
+                               nlights++;
+               }
+               
+               max_vpl= (nlights + re->r.lightcuts_area_lights + 
re->r.lightcuts_env_map) * lcd->do_indir;
+               
+               lcd->dbg_vis_vpl= MEM_callocN(sizeof(float) * 3 * max_vpl, 
"lc_vpl_visualization");
+       }
+       
        /* TODO: we could do some form of importance sampling here */
        for(go=lights->first; go; go= go->next) {
                lar= go->lampren;
@@ -1634,6 +1734,9 @@
        
        /* XXX: restore mode (terrible hack needed by get_bounce_color) */
        R.r.mode|= R_LIGHTCUTS;
+       
+       if (lcd->options & LC_OPT_INDIR_MESH)
+               dbg_create_vpl_mesh(re, lcd);
 }
 
 /* Adapted from "Transforming Axis-Aligned Bounding Boxes" by Jim Arvo, 
"Graphics Gems", Academic Press, 1990 */
@@ -2293,6 +2396,8 @@
                                MEM_freeN(lcd->trees[i].array);
                BLI_freelistN(&lcd->pointlights);
                MEM_freeN(lcd->cut_nodes);
+               if (lcd->dbg_vis_vpl);
+                       MEM_freeN(lcd->dbg_vis_vpl);
                MEM_freeN(lcd);
        }
        *p= NULL;

Modified: branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c      
2008-08-24 20:57:56 UTC (rev 16242)
+++ branches/soc-2008-unclezeiv/source/blender/src/buttons_scene.c      
2008-08-24 21:14:07 UTC (rev 16243)
@@ -3450,6 +3450,7 @@
        uiBlockBeginAlign(block);
        uiDefButBitI(block, TOG, SCE_PASS_LCFAUX, B_SET_PASS, "False color", 
200, 0, 48, 20, &srl->passflag, 0, 0, 0, 0, "(Debug option) Deliver false color 
pass");
        uiDefButI(block, NUM, B_DIFF, "Debug:", 200, -22, 48, 20, 
&G.scene->r.lightcuts_debug_options, 0, 0xffffffff, 0, 0, "(Debug option) 
Slider to select debug prints");
+       uiDefButBitS(block, TOG, 0x10, B_SET_PASS, "VPL Mesh", 200, -44, 48, 
20, &G.scene->r.lightcuts_options, 0, 0, 0, 0, "(Debug option) Creates a mesh 
to visualize indirect light placement");
        uiBlockEndAlign(block);
        
        uiBlockBeginAlign(block);


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to