Revision: 18666
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18666
Author:   unclezeiv
Date:     2009-01-25 15:40:27 +0100 (Sun, 25 Jan 2009)

Log Message:
-----------
Meshlights: added support for textured materials.

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 
2009-01-25 11:45:40 UTC (rev 18665)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 
2009-01-25 14:40:27 UTC (rev 18666)
@@ -1522,14 +1522,16 @@
        
        /* hack: increase current color/energy in order to avoid too dark 
results */
        /* XXX: how does this interact with color ramps? */
-       energy= lar->energy;
-       savecol[0]= lar->r;
-       savecol[1]= lar->g;
-       savecol[2]= lar->b;
-       lar->r /= lar->energy;
-       lar->g /= lar->energy;
-       lar->b /= lar->energy;
-       lar->energy= 1.0f;
+       if (lar) {
+               energy= lar->energy;
+               savecol[0]= lar->r;
+               savecol[1]= lar->g;
+               savecol[2]= lar->b;
+               lar->r /= lar->energy;
+               lar->g /= lar->energy;
+               lar->b /= lar->energy;
+               lar->energy= 1.0f;
+       }
        
        /* don't do normal flipping in this phase, as the query is not camera 
aligned */
        old_vlr_flag= vla->flag;
@@ -1556,7 +1558,7 @@
        shi->light_override= &light_override; // rl->light_override;
        
        /* simplified code from shade_samples_fill_with_ps */
-       shi->obi= &R.objectinstance[obi];
+       shi->obi= RAY_OBJECT_GET(&R, obi);
        shi->obr= shi->obi->obr;
        shi->facenr= vla->index; // (facenr-1) & RE_QUAD_MASK;
        if (isect==2)
@@ -1601,7 +1603,8 @@
        }
 #else
        VECCOPY(shi->co, co);
-       VECSUB(shi->view, co, lar->co);
+       if (lar)
+               VECSUB(shi->view, co, lar->co);
        Normalize(shi->view);
 #endif
        
@@ -1631,10 +1634,12 @@
        VECCOPY(col, shr.col);
        
        /* restore lar colors */
-       lar->energy= energy;
-       lar->r= savecol[0];
-       lar->g= savecol[1];
-       lar->b= savecol[2];
+       if (lar) {
+               lar->energy= energy;
+               lar->r= savecol[0];
+               lar->g= savecol[1];
+               lar->b= savecol[2];
+       }
        
        /* restore VlakRen flags */
        vla->flag= old_vlr_flag;
@@ -1646,10 +1651,13 @@
                return 0.0f;
        }
        
-       /* code to avoid zero division and riduce numerical problems */
-       max_idx= max_col==shr.col[0] ? 0 : max_col==shr.col[1] ? 1 : 2;
-       
-       return shr.diff[max_idx] / shr.col[max_idx];
+       if (lar) {
+               /* code to avoid zero division and riduce numerical problems */
+               max_idx= max_col==shr.col[0] ? 0 : max_col==shr.col[1] ? 1 : 2;
+               
+               return shr.diff[max_idx] / shr.col[max_idx];
+       }
+       return 1.0f;    
 }
 
 static void add_virtual_point_light(Render * re, LightcutsData *lcd, LampRen 
*orig, float *col, short lev, float weight)
@@ -1909,17 +1917,27 @@
        VECADDFAC(res, res, dir2, r2);
 }
 
-void add_meshlight(Render *re, LightcutsData *lcd, ObjectRen *obr, VlakRen 
*vla, float *co, float weight)
+void add_meshlight(Render *re, LightcutsData *lcd, ObjectInstanceRen *obi, 
VlakRen *vla, float *co, float weight, short type)
 {
        LampRen *lar;
        int i;
-       float col[3];
+       float col[3], fac;
        
+       fac = get_bounce_color(lcd, RAY_OBJECT_SET(re, obi), vla, co, NULL, 
col, type);
+
+       if (fac == -1.0f)
+               return;
+
+       if (fac <= 0.0f) {
+               lcd->stat_discard_black++;
+               return;
+       }
+
        lar= MEM_callocN(sizeof(LampRen), "lampren");
        lamp_init(re, lar);
        lar->dist= lcd->indir_dist;
        lar->distkw= lar->dist * lar->dist;
-       lar->lay= obr->lay;
+       lar->lay= obi->obr->lay;
 
        /* TODO: how to decide specular */
        // lar->mode |= LA_NO_SPEC;
@@ -1936,10 +1954,6 @@
        lar->ray_samp_method= LA_SAMP_CONSTANT;
        
        lar->energy= vla->mat->emit * weight;
-       
-       col[0]= vla->mat->r;
-       col[1]= vla->mat->g;
-       col[2]= vla->mat->b;
 
        lar->r= lar->energy * col[0];
        lar->g= lar->energy * col[1];
@@ -1962,13 +1976,15 @@
 
 void add_lights_from_mesh(LightcutsData *lcd, Render *re)
 {
+       ObjectInstanceRen *obi;
        ObjectRen *obr;
        float *v1, *v2, *v3, *v4, area, co[3], budget;
        float density= lcd->meshlights_density;
        float weight= 1.0f / density;
        int a, n, i;
        
-       for(obr=re->objecttable.first; obr; obr=obr->next) {
+       for(obi=re->instancetable.first; obi; obi=obi->next) {
+               obr= obi->obr;
                for(a=0; a<obr->totvlak; a++) {
                        VlakRen *vlr= RE_findOrAddVlak(obr, a);
                        
@@ -1989,7 +2005,7 @@
 
                        for (i= 0; i < n; i++) {
                                get_random_point_on_triangle(v1, v2, v3, co);
-                               add_meshlight(re, lcd, obr, vlr, co, weight);
+                               add_meshlight(re, lcd, obi, vlr, co, weight, 1);
                        }
                        
                        if (vlr->v4) {
@@ -2002,7 +2018,7 @@
 
                                for (i= 0; i < n; i++) {
                                        get_random_point_on_triangle(v1, v3, 
v4, co);
-                                       add_meshlight(re, lcd, obr, vlr, co, 
weight);
+                                       add_meshlight(re, lcd, obi, vlr, co, 
weight, 2);
                                }       
                        } 
                }
@@ -2056,15 +2072,6 @@
                break;
        }
        
-       /* XXX: terrible hack currently needed by get_bounce_color */
-       if (lcd->do_indir > 0) {
-               R= *re;
-               R.r.mode&= ~R_LIGHTCUTS;
-       }
-       /* other hack to make shadeSkyView work... */
-       else if (lcd->options & LC_OPT_ENV_LIGHT && re->r.lightcuts_env_map > 0)
-               R= *re;
-       
        if (lcd->do_indir > 0 && lcd->options & LC_OPT_INDIR_MESH) {
                int n_orig= 0;
                int n_area= 0;
@@ -2127,6 +2134,15 @@
                        lcd->meshlights_density= re->r.lightcuts_meshlights / 
lcd->meshlights_density;
                /* lcd->dbg_vis_vpl= MEM_callocN(sizeof(float) * 3 * 
re->r.lightcuts_meshlights, "lc_vpl_visualization"); */
        }
+       
+       /* XXX: terrible hack currently needed by get_bounce_color */
+       if (lcd->do_indir > 0 || lcd->meshlights_density > 0.0f) {
+               R= *re;
+               R.r.mode&= ~R_LIGHTCUTS;
+       }
+       /* other hack to make shadeSkyView work... */
+       else if ((lcd->options & LC_OPT_ENV_LIGHT && re->r.lightcuts_env_map > 
0))
+               R= *re;
 
        /* light conversion */
        


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

Reply via email to