Revision: 15402
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15402
Author:   unclezeiv
Date:     2008-07-02 03:48:57 +0200 (Wed, 02 Jul 2008)

Log Message:
-----------
Initial commit for area light conversion code.

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-02 00:23:02 UTC (rev 15401)
+++ branches/soc-2008-unclezeiv/source/blender/makesdna/DNA_scene_types.h       
2008-07-02 01:48:57 UTC (rev 15402)
@@ -316,7 +316,9 @@
        float lightcuts_max_error;
        int lightcuts_max_lights;
        int lightcuts_max_cut;
-       int pad1;
+       int lightcuts_area_density;
+       float lightcuts_unused;
+       int pad4;
 } RenderData;
 
 /* control render convert and shading engine */

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 00:23:02 UTC (rev 15401)
+++ branches/soc-2008-unclezeiv/source/blender/render/intern/source/lightcuts.c 
2008-07-02 01:48:57 UTC (rev 15402)
@@ -431,55 +431,140 @@
        MEM_freeN(pair_array);
 }
 
-#ifdef LIGHTCUTS_CURRENTLY_UNUSED
-/*
- * 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)
+
+static void create_lamp_oriented(Render * re, LampRen * lar, LampRen * orig)
 {
-       if(re->r.mode & R_SHADOW) {
+       /* float xs, ys, dist; */
+       /* 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 */
+       /* initialize later */
+       
+       /* float energy, haint; */
+       /* initialize later */
+       lar->haint= 0.0f;
+       
+       /* 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!! */
+       
+       /* short falloff_type; */
+       lar->falloff_type= LA_FALLOFF_INVSQUARE;
+       
+       /* float ld1,ld2; */
+       /* struct CurveMapping *curfalloff; */
+       lar->curfalloff= NULL;
 
-               if(lar->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && 
(lar->ray_samp_method == LA_SAMP_CONSTANT)) {
-                       init_jitter_plane(lar);
-               }
+       /* copied from Lamp, to decouple more rendering stuff */
+       /** Size of the shadowbuffer */
+       /* short bufsize; */
+       /** Number of samples for the shadows */
+       /*      short samp; */
+       /** Softness factor for shadow */
+       /* float soft; */
+       /** amount of subsample buffers and type of filter for sampling */
+       /* short buffers, filtertype; */
+       /** shadow buffer type (regular, irregular) */
+       /* short buftype; */
+       /** autoclip */
+       /* short bufflag; */
+       /** shadow plus halo: detail level */
+       /* short shadhalostep; */
+       /** Near clip of the lamp */
+       /* float clipsta; */
+       /** Far clip of the lamp */
+       /* float clipend; */
+       /** A small depth offset to prevent self-shadowing. */
+       /* float bias; */
+       
+       /*      short ray_samp, ray_sampy, ray_sampz, ray_samp_method, 
ray_samp_type, area_shape, ray_totsamp; */
+       lar->ray_samp= 1;
+       lar->ray_samp_method= LA_SAMP_CONSTANT;
+       lar->ray_samp_type= LA_SAMP_UMBRA; /* LA_SAMP_DITHER, LA_SAMP_JITTER 
TODO: is it for area lights?*/
+       
+       /* short xold[BLENDER_MAX_THREADS], yold[BLENDER_MAX_THREADS]; // last 
jitter table for area lights */
+       /* float area_size, area_sizey, area_sizez; */
+       /* float adapt_thresh; */
 
-               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
-               }
+       /* struct ShadBuf *shb; */
+       /* 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 */
+       /* LampShadowSample *shadsamp; */
+       {
+               LampShadowSample *ls;
+               LampShadowSubSample *lss;
+               int a, b;
 
-               /* 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;
 
-                       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 uninitialized 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;
-                               }
+               /* shadfacs actually mean light, let's put them to 1 to prevent 
uninitialized 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;
                        }
                }
        }
+               
+       /* yafray: photonlight params */
+       /*
+       int YF_numphotons, YF_numsearch;
+       short YF_phdepth, YF_useqmc, YF_bufsize;
+       float YF_causticblur, YF_ltradius;
+       float YF_glowint, YF_glowofs;
+       short YF_glowtype;
+       */
+       
+       /* ray optim */
+       /*
+       VlakRen *vlr_last[BLENDER_MAX_THREADS];
+       ObjectInstanceRen *obi_last[BLENDER_MAX_THREADS];
+       
+       struct MTex *mtex[MAX_MTEX];
+       */
+       /* threading */
+       /*
+       int thread_assigned;
+       int thread_ready;
+       */
 }
-#endif
 
 void lightcuts_init(Render * re)
 {
@@ -490,11 +575,7 @@
        LampRen *lar;
        char tree_time_str[12]; /* length 12 required by BLI_timestr */
        int i;
-
-#ifdef LIGHTCUTS_CURRENTLY_UNUSED
-       LampRen *larnew;
-       float r, g, b, n;
-#endif
+       float density;
        
        re->i.infostr= "Initializing Lightcuts";
        re->stats_draw(&re->i);
@@ -504,11 +585,87 @@
        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;
+                               }
+                       }
+                       continue;
+               }
+
                /* first copy the initial light */
                gonew= MEM_callocN(sizeof(GroupObject), "groupobject");
                BLI_addtail(pointlights, gonew);
@@ -549,51 +706,6 @@
                 * TODO: QMC may be restored for stronger lights
                 */
                lar->ray_samp_method = LA_SAMP_CONSTANT;
-
-#ifdef LIGHTCUTS_CURRENTLY_UNUSED
-               /*
-                * 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
-                */
-               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 deallocated
-                * 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;
-

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to