converted more mixed tab/space indentations to tabs. only whitespace changes.
[blender.git] / source / blender / render / intern / source / pixelshading.c
index ef723eea6b5a137717454e7633c8fbe7fc3e8c11..2d42938f6ac94fce80dbfec15d0af1cf3c959d58 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  * ***** END GPL LICENSE BLOCK *****
  */
 
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/render/intern/source/pixelshading.c
+ *  \ingroup render
+ */
+
+
 #include <float.h>
 #include <math.h>
 #include <string.h>
 #include <float.h>
 #include <math.h>
 #include <string.h>
-#include "BLI_arithb.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
 
 /* External modules: */
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
 
 /* External modules: */
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"
-#include "MTC_matrixops.h"
-#include "MTC_vectorops.h"
 
 #include "DNA_camera_types.h"
 #include "DNA_group_types.h"
 
 #include "DNA_camera_types.h"
 #include "DNA_group_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_lamp_types.h"
 
 #include "DNA_texture_types.h"
 #include "DNA_lamp_types.h"
 
+#include "BKE_colortools.h"
 #include "BKE_image.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_global.h"
+#include "BKE_material.h"
 #include "BKE_texture.h"
 #include "BKE_texture.h"
-#include "BKE_utildefines.h"
+
 
 /* own module */
 #include "render_types.h"
 
 /* own module */
 #include "render_types.h"
@@ -57,6 +64,7 @@
 #include "rendercore.h"
 #include "shadbuf.h"
 #include "pixelshading.h"
 #include "rendercore.h"
 #include "shadbuf.h"
 #include "pixelshading.h"
+#include "shading.h"
 #include "sunsky.h"
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 #include "sunsky.h"
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -152,7 +160,7 @@ static void render_lighting_halo(HaloRen *har, float *colf)
                                        
                                        /* rotate view to lampspace */
                                        VECCOPY(lvrot, lv);
                                        
                                        /* rotate view to lampspace */
                                        VECCOPY(lvrot, lv);
-                                       MTC_Mat3MulVecfl(lar->imat, lvrot);
+                                       mul_m3_v3(lar->imat, lvrot);
                                        
                                        x= MAX2(fabs(lvrot[0]/lvrot[2]) , fabs(lvrot[1]/lvrot[2]));
                                        /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */
                                        
                                        x= MAX2(fabs(lvrot[0]/lvrot[2]) , fabs(lvrot[1]/lvrot[2]));
                                        /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */
@@ -282,14 +290,14 @@ int shadeHaloFloat(HaloRen *har,  float *col, int zz,
        int a;
    
        if(R.wrld.mode & WO_MIST) {
        int a;
    
        if(R.wrld.mode & WO_MIST) {
-       if(har->type & HA_ONLYSKY) {
-           /* stars but no mist */
-           alpha= har->alfa;
-       }
-       else {
-           /* a bit patchy... */
-           alpha= mistfactor(-har->co[2], har->co)*har->alfa;
-       }
+               if(har->type & HA_ONLYSKY) {
+                       /* stars but no mist */
+                       alpha= har->alfa;
+               }
+               else {
+                       /* a bit patchy... */
+                       alpha= mistfactor(-har->co[2], har->co)*har->alfa;
+               }
        }
        else alpha= har->alfa;
        
        }
        else alpha= har->alfa;
        
@@ -510,7 +518,7 @@ static void fillBackgroundImage(float *collector, float fx, float fy)
 }
 
 /* Only view vector is important here. Result goes to colf[3] */
 }
 
 /* Only view vector is important here. Result goes to colf[3] */
-void shadeSkyView(float *colf, float *rco, float *view, float *dxyview)
+void shadeSkyView(float *colf, float *rco, float *view, float *dxyview, short thread)
 {
        float lo[3], zen[3], hor[3], blend, blendm;
        int skyflag;
 {
        float lo[3], zen[3], hor[3], blend, blendm;
        int skyflag;
@@ -534,22 +542,22 @@ void shadeSkyView(float *colf, float *rco, float *view, float *dxyview)
                /* the fraction of how far we are above the bottom of the screen */
                blend= fabs(0.5+ view[1]);
        }
                /* the fraction of how far we are above the bottom of the screen */
                blend= fabs(0.5+ view[1]);
        }
-       
-       hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb;
-       zen[0]= R.wrld.zenr; zen[1]= R.wrld.zeng; zen[2]= R.wrld.zenb;
-       
+
+       VECCOPY(hor, &R.wrld.horr);
+       VECCOPY(zen, &R.wrld.zenr);
+
        /* Careful: SKYTEX and SKYBLEND are NOT mutually exclusive! If           */
        /* SKYBLEND is active, the texture and color blend are added.           */
        if(R.wrld.skytype & WO_SKYTEX) {
                VECCOPY(lo, view);
                if(R.wrld.skytype & WO_SKYREAL) {
                        
        /* Careful: SKYTEX and SKYBLEND are NOT mutually exclusive! If           */
        /* SKYBLEND is active, the texture and color blend are added.           */
        if(R.wrld.skytype & WO_SKYTEX) {
                VECCOPY(lo, view);
                if(R.wrld.skytype & WO_SKYREAL) {
                        
-                       MTC_Mat3MulVecfl(R.imat, lo);
+                       mul_m3_v3(R.imat, lo);
                        
                        SWAP(float, lo[1],  lo[2]);
                        
                }
                        
                        SWAP(float, lo[1],  lo[2]);
                        
                }
-               do_sky_tex(rco, lo, dxyview, hor, zen, &blend, skyflag);
+               do_sky_tex(rco, lo, dxyview, hor, zen, &blend, skyflag, thread);
        }
        
        if(blend>1.0) blend= 1.0;
        }
        
        if(blend>1.0) blend= 1.0;
@@ -569,47 +577,46 @@ void shadeSkyView(float *colf, float *rco, float *view, float *dxyview)
 }
 
 /* shade sky according to sun lamps, all parameters are like shadeSkyView except sunsky*/
 }
 
 /* shade sky according to sun lamps, all parameters are like shadeSkyView except sunsky*/
-void shadeSunView(struct SunSky *sunsky, float *colf, float *rco, float *view, float *dxyview)
+void shadeSunView(float *colf, float *view)
 {
 {
-       float colorxyz[3];
-       float scale;
+       GroupObject *go;
+       LampRen *lar;
+       float sview[3];
+       int do_init= 1;
+       
+       for(go=R.lights.first; go; go= go->next) {
+               lar= go->lampren;
+               if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)){
+                       float sun_collector[3];
+                       float colorxyz[3];
                        
                        
-       /**
-       sunAngle = sqrt(sunsky->sunSolidAngle / M_PI);
-
-       sunDir[0] = sunsky->toSun[0];
-       sunDir[1] = sunsky->toSun[1];
-       sunDir[2] = sunsky->toSun[2];
-       */
+                       if(do_init) {
+                               
+                               VECCOPY(sview, view);
+                               normalize_v3(sview);
+                               mul_m3_v3(R.imat, sview);
+                               if (sview[2] < 0.0)
+                                       sview[2] = 0.0;
+                               normalize_v3(sview);
+                               do_init= 0;
+                       }
                        
                        
-       Normalize(view);
-       MTC_Mat3MulVecfl(R.imat, view);
-       if (view[2] < 0.0)
-               view[2] = 0.0;
-       Normalize(view);
-       GetSkyXYZRadiancef(sunsky, view, colorxyz);
-       scale = MAX3(colorxyz[0], colorxyz[1], colorxyz[2]);
-       colorxyz[0] /= scale;
-       colorxyz[1] /= scale;
-       colorxyz[2] /= scale;
-       
-       xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &colf[0], &colf[1], &colf[2]);
-
-       ClipColor(colf);
+                       GetSkyXYZRadiancef(lar->sunsky, sview, colorxyz);
+                       xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &sun_collector[0], &sun_collector[1], &sun_collector[2], 
+                                          lar->sunsky->sky_colorspace);
+                       
+                       ramp_blend(lar->sunsky->skyblendtype, colf, colf+1, colf+2, lar->sunsky->skyblendfac, sun_collector);
+               }
+       }
 }
 
 
 /*
   Stuff the sky color into the collector.
  */
 }
 
 
 /*
   Stuff the sky color into the collector.
  */
-void shadeSkyPixel(float *collector, float fx, float fy) 
+void shadeSkyPixel(float *collector, float fx, float fy, short thread
 {
        float view[3], dxyview[2];
 {
        float view[3], dxyview[2];
-       float sun_collector[3];
-       float suns_color[3];
-       short num_sun_lamp;
-       GroupObject *go;
-       LampRen *lar;
 
        /*
          The rules for sky:
 
        /*
          The rules for sky:
@@ -625,9 +632,8 @@ void shadeSkyPixel(float *collector, float fx, float fy)
        } 
        else if((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) {
                /* 2. solid color */
        } 
        else if((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) {
                /* 2. solid color */
-               collector[0] = R.wrld.horr;
-               collector[1] = R.wrld.horg;
-               collector[2] = R.wrld.horb;
+               VECCOPY(collector, &R.wrld.horr);
+
                collector[3] = 0.0f;
        } 
        else {
                collector[3] = 0.0f;
        } 
        else {
@@ -644,7 +650,7 @@ void shadeSkyPixel(float *collector, float fx, float fy)
                }
                else {
                        calc_view_vector(view, fx, fy);
                }
                else {
                        calc_view_vector(view, fx, fy);
-                       fac= Normalize(view);
+                       fac= normalize_v3(view);
                        
                        if(R.wrld.skytype & WO_SKYTEX) {
                                dxyview[0]= -R.viewdx/fac;
                        
                        if(R.wrld.skytype & WO_SKYTEX) {
                                dxyview[0]= -R.viewdx/fac;
@@ -653,37 +659,12 @@ void shadeSkyPixel(float *collector, float fx, float fy)
                }
                
                /* get sky color in the collector */
                }
                
                /* get sky color in the collector */
-               shadeSkyView(collector, NULL, view, dxyview);
+               shadeSkyView(collector, NULL, view, dxyview, thread);
                collector[3] = 0.0f;
        }
                collector[3] = 0.0f;
        }
-               
-       suns_color[0] = suns_color[1] = suns_color[2] = 0;
-       num_sun_lamp = 0;
-       for(go=R.lights.first; go; go= go->next) {
-               lar= go->lampren;
-               if(lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)){
-
-                       num_sun_lamp ++;
-                       calc_view_vector(view, fx, fy);
-                       Normalize(view);
-
-                       shadeSunView(lar->sunsky, sun_collector, NULL, view, NULL);
-                       suns_color[0] += sun_collector[0];
-                       suns_color[1] += sun_collector[1];
-                       suns_color[2] += sun_collector[2];
-
-               }
-       }
-       if( num_sun_lamp > 0 ){
-               suns_color[0] /= num_sun_lamp;
-               suns_color[1] /= num_sun_lamp;
-               suns_color[2] /= num_sun_lamp;
-
-               collector[0] += suns_color[0];
-               collector[1] += suns_color[1];
-               collector[2] += suns_color[2];
-               ClipColor(collector);
-       }
+       
+       calc_view_vector(view, fx, fy);
+       shadeSunView(collector, view);
 }
 
 /* aerial perspective */
 }
 
 /* aerial perspective */
@@ -692,8 +673,8 @@ void shadeAtmPixel(struct SunSky *sunsky, float *collector, float fx, float fy,
        float view[3];
                
        calc_view_vector(view, fx, fy);
        float view[3];
                
        calc_view_vector(view, fx, fy);
-       Normalize(view);
-       /*MTC_Mat3MulVecfl(R.imat, view);*/
+       normalize_v3(view);
+       /*mul_m3_v3(R.imat, view);*/
        AtmospherePixleShader(sunsky, view, distance, collector);
 }
 
        AtmospherePixleShader(sunsky, view, distance, collector);
 }