svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22668:22701
[blender.git] / source / blender / render / intern / source / shadeoutput.c
index 5b69323667edce2188c09b7045d5431f0c430a8b..d5c8cf30b3000ec13466bd393144198012f1c701 100644 (file)
@@ -61,12 +61,14 @@ extern struct Render R;
 static ListBase *get_lights(ShadeInput *shi)
 {
        
+       if(R.r.scemode & R_PREVIEWBUTS)
+               return &R.lights;
        if(shi->light_override)
                return &shi->light_override->gobject;
-       else if(shi->mat && shi->mat->group)
+       if(shi->mat && shi->mat->group)
                return &shi->mat->group->gobject;
-       else
-               return &R.lights;
+       
+       return &R.lights;
 }
 
 #if 0
@@ -1005,6 +1007,7 @@ static void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec)
 }
 
 /* pure AO, check for raytrace and world should have been done */
+/* preprocess, textures were not done, don't use shi->amb for that reason */
 void ambient_occlusion(ShadeInput *shi)
 {
        if((R.wrld.ao_gather_method == WO_AOGATHER_APPROX) && shi->mat->amb!=0.0f)
@@ -1020,8 +1023,8 @@ void ambient_occlusion(ShadeInput *shi)
 void ambient_occlusion_to_diffuse(ShadeInput *shi, float *diff)
 {
        if((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX) {
-               if(shi->mat->amb!=0.0f) {
-                       float f= R.wrld.aoenergy*shi->mat->amb;
+               if(shi->amb!=0.0f) {
+                       float f= R.wrld.aoenergy*shi->amb;
 
                        if (R.wrld.aomix==WO_AOADDSUB) {
                                diff[0] = 2.0f*shi->ao[0]-1.0f;
@@ -1179,7 +1182,7 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
 {
        Material *ma= shi->mat;
        VlakRen *vlr= shi->vlr;
-       float lv[3], lampdist, lacol[3], shadfac[4];
+       float lv[3], lampdist, lacol[3], shadfac[4], lashdw[3];
        float i, is, i_noshad, inp, *vn, *view, vnor[3], phongcorr=1.0f;
        float visifac;
        
@@ -1219,7 +1222,12 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
        lacol[1]= lar->g;
        lacol[2]= lar->b;
        
-       if(lar->mode & LA_TEXTURE)  do_lamp_tex(lar, lv, shi, lacol);
+       lashdw[0]= lar->shdwr;
+       lashdw[1]= lar->shdwg;
+       lashdw[2]= lar->shdwb;
+       
+       if(lar->mode & LA_TEXTURE)      do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE);
+       if(lar->mode & LA_SHAD_TEX)     do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX);
 
                /* tangent case; calculate fake face normal, aligned with lampvector */ 
                /* note, vnor==vn is used as tangent trigger for buffer shadow */
@@ -1342,13 +1350,13 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
                                        if((lar->mode & LA_ONLYSHADOW) && i>0.0) {
                                                
                                                shadfac[3]= i*lar->energy*(1.0f-shadfac[3]);
-                                               shr->shad[0] -= shadfac[3]*shi->r;
-                                               shr->shad[1] -= shadfac[3]*shi->g;
-                                               shr->shad[2] -= shadfac[3]*shi->b;
+                                               shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]);
+                                               shr->shad[1] -= shadfac[3]*shi->g*(1.0f-lashdw[1]);
+                                               shr->shad[2] -= shadfac[3]*shi->b*(1.0f-lashdw[2]);
                                                
-                                               shr->spec[0] -= shadfac[3]*shi->specr;
-                                               shr->spec[1] -= shadfac[3]*shi->specg;
-                                               shr->spec[2] -= shadfac[3]*shi->specb;
+                                               shr->spec[0] -= shadfac[3]*shi->specr*(1.0f-lashdw[0]);
+                                               shr->spec[1] -= shadfac[3]*shi->specg*(1.0f-lashdw[1]);
+                                               shr->spec[2] -= shadfac[3]*shi->specb*(1.0f-lashdw[2]);
                                                
                                                return;
                                        }
@@ -1366,6 +1374,10 @@ static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int
                                else
                                        add_to_diffuse(shr->shad, shi, is, i*lacol[0], i*lacol[1], i*lacol[2]);
                        }
+                       /* add light for colored shadow */
+                       if (i_noshad>i && !(lashdw[0]==0 && lashdw[1]==0 && lashdw[2]==0)) {
+                               add_to_diffuse(shr->shad, shi, is, lashdw[0]*(i_noshad-i)*lacol[0], lashdw[1]*(i_noshad-i)*lacol[1], lashdw[2]*(i_noshad-i)*lacol[2]);
+                       }
                        if(i_noshad>0.0f) {
                                if(passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW)) {
                                        if(ma->mode & MA_SHADOW_TRA)
@@ -1451,10 +1463,10 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
                LampRen *lar;
                GroupObject *go;
                float inpr, lv[3];
-               float *vn, *view, shadfac[4];
+               float *view, shadfac[4];
                float ir, accum, visifac, lampdist;
                
-               vn= shi->vn;
+
                view= shi->view;
 
                accum= ir= 0.0f;
@@ -1559,7 +1571,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
                shr->col[2]= shi->b*shi->alpha;
                shr->col[3]= shi->alpha;
 
-               if((ma->sss_flag & MA_DIFF_SSS) && !has_sss_tree(&R, ma)) {
+               if((ma->sss_flag & MA_DIFF_SSS) && !sss_pass_done(&R, ma)) {
                        if(ma->sss_texfac == 0.0f) {
                                shi->r= shi->g= shi->b= shi->alpha= 1.0f;
                                shr->col[0]= shr->col[1]= shr->col[2]= shr->col[3]= 1.0f;
@@ -1701,7 +1713,7 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
                        shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra);
                        
                /* note: shi->mode! */
-               if(shi->mode & (MA_ZTRA|MA_RAYTRANSP)) {
+               if(shi->mode & MA_TRANSP) {
                        if(shi->spectra!=0.0f) {
                                float t = MAX3(shr->spec[0], shr->spec[1], shr->spec[2]);
                                t *= shi->spectra;
@@ -1713,16 +1725,17 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
        shr->alpha= shi->alpha;
        
        /* from now stuff everything in shr->combined: ambient, AO, radio, ramps, exposure */
-       if(!(ma->sss_flag & MA_DIFF_SSS) || !has_sss_tree(&R, ma)) {
+       if(!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) {
                shr->combined[0]+= shi->ambr;
                shr->combined[1]+= shi->ambg;
                shr->combined[2]+= shi->ambb;
 
+               /* removed
                if(shi->combinedflag & SCE_PASS_RADIO) {
                        shr->combined[0]+= shi->r*shi->amb*shi->rad[0];
                        shr->combined[1]+= shi->g*shi->amb*shi->rad[1];
                        shr->combined[2]+= shi->b*shi->amb*shi->rad[2];
-               }
+               }*/
                
                /* add AO in combined? */
                if(R.wrld.mode & WO_AMB_OCC) {
@@ -1761,7 +1774,21 @@ void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
        if(shi->combinedflag & SCE_PASS_SPEC)
                VECADD(shr->combined, shr->combined, shr->spec);
 
+       /* modulate by the object color */
+       if((ma->shade_flag & MA_OBCOLOR) && shi->obr->ob) {
+               if(!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) {
+                       float obcol[4];
+
+                       QUATCOPY(obcol, shi->obr->ob->col);
+                       CLAMP(obcol[3], 0.0f, 1.0f);
+
+                       shr->combined[0] *= obcol[0];
+                       shr->combined[1] *= obcol[1];
+                       shr->combined[2] *= obcol[2];
+                       shr->alpha *= obcol[3];
+               }
+       }
+
        shr->combined[3]= shr->alpha;
 }
 
-