svn merge -r 15392:15551 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / render / intern / source / convertblender.c
index 796a99ca796b2ffe018692a08cce332f78218b1c..faa7a68f75421390db0f51d6bfdcd8bf35c82e34 100644 (file)
 #include "sss.h"
 #include "strand.h"
 #include "zbuf.h"
+#include "sunsky.h"
 
 #ifndef DISABLE_YAFRAY /* disable yafray */
 
@@ -203,6 +204,7 @@ void RE_make_stars(Render *re, void (*initfunc)(void),
        else stargrid *= 1.0;                           /* then it draws fewer */
        
        if(re) MTC_Mat4Invert(mat, re->viewmat);
+       else MTC_Mat4One(mat);
        
        /* BOUNDING BOX CALCULATION
                * bbox goes from z = loc_near_var | loc_far_var,
@@ -3494,6 +3496,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
        LampRen *lar;
        GroupObject *go;
        float mat[4][4], angle, xn, yn;
+       float vec[3];
        int c;
 
        /* previewrender sets this to zero... prevent accidents */
@@ -3576,8 +3579,9 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
        lar->ray_samp_type= la->ray_samp_type;
        
        lar->adapt_thresh= la->adapt_thresh;
+       lar->sunsky = NULL;
        
-       if( ELEM3(lar->type, LA_SPOT, LA_SUN, LA_LOCAL)) {
+       if( ELEM(lar->type, LA_SPOT, LA_LOCAL)) {
                lar->ray_totsamp= lar->ray_samp*lar->ray_samp;
                lar->area_shape = LA_AREA_SQUARE;
                lar->area_sizey= lar->area_size;
@@ -3607,6 +3611,26 @@ static GroupObject *add_render_lamp(Render *re, Object *ob)
                area_lamp_vectors(lar);
                init_jitter_plane(lar); // subsamples
        }
+       else if(lar->type==LA_SUN){
+               lar->ray_totsamp= lar->ray_samp*lar->ray_samp;
+               lar->area_shape = LA_AREA_SQUARE;
+               lar->area_sizey= lar->area_size;
+
+               if((la->sun_effect_type & LA_SUN_EFFECT_SKY) ||
+                               (la->sun_effect_type & LA_SUN_EFFECT_AP)){
+                       lar->sunsky = (struct SunSky*)MEM_callocN(sizeof(struct SunSky), "sunskyren");
+                       lar->sunsky->effect_type = la->sun_effect_type;
+               
+                       VECCOPY(vec,ob->obmat[2]);
+                   Normalize(vec);
+                   
+                       InitSunSky(lar->sunsky, la->atm_turbidity, vec, la->horizon_brightness, 
+                                       la->spread, la->sun_brightness, la->sun_size, la->backscattered_light);
+                       
+                       InitAtmosphere(lar->sunsky, la->sun_intensity, 1.0, 1.0, la->atm_inscattering_factor, la->atm_extinction_factor,
+                                       la->atm_distance_factor);
+               }
+       }
        else lar->ray_totsamp= 0;
        
 #ifndef DISABLE_YAFRAY
@@ -4447,6 +4471,7 @@ void RE_Database_Free(Render *re)
                freeshadowbuf(lar);
                if(lar->jitter) MEM_freeN(lar->jitter);
                if(lar->shadsamp) MEM_freeN(lar->shadsamp);
+               if(lar->sunsky) MEM_freeN(lar->sunsky);
                curvemapping_free(lar->curfalloff);
        }