Merged changes in the trunk up to revision 36408.
[blender.git] / source / blender / render / intern / source / shadeoutput.c
index c4634b261af7ff6e6ae802e4c0598da0a755c684..b0a7fdd1b362c98f762c1fc1d5d377045f41852c 100644 (file)
@@ -726,7 +726,7 @@ static float Toon_Diff( float *n, float *l, float *v, float size, float smooth )
 /* in latter case, only last multiplication uses 'nl' */
 static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough )
 {
-       float i, nh, nv, vh, realnl, h[3];
+       float i/*, nh*/, nv, vh, realnl, h[3];
        float a, b, t, A, B;
        float Lit_A, View_A, Lit_B[3], View_B[3];
        
@@ -735,8 +735,8 @@ static float OrenNayar_Diff(float nl, float *n, float *l, float *v, float rough
        h[2]= v[2]+l[2];
        normalize_v3(h);
        
-       nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */
-       if(nh<0.0f) nh = 0.0f;
+       /* nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; */ /* Dot product between surface normal and half-way vector */
+       /* if(nh<0.0f) nh = 0.0f; */
        
        nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
        if(nv<=0.0f) nv= 0.0f;
@@ -1523,19 +1523,19 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
                        
                        if(lar->shb || (lar->mode & LA_SHAD_RAY)) {
                                visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist);
+                               ir+= 1.0f;
+
                                if(visifac <= 0.0f) {
-                                       if (shi->mat->shadowonly_flag == MA_SO_OLD) {
-                                               ir+= 1.0f;
+                                       if (shi->mat->shadowonly_flag == MA_SO_OLD)
                                                accum+= 1.0f;
-                                       }
+
                                        continue;
                                }
                                inpr= INPR(shi->vn, lv);
                                if(inpr <= 0.0f) {
-                                       if (shi->mat->shadowonly_flag == MA_SO_OLD) {
-                                               ir+= 1.0f;
+                                       if (shi->mat->shadowonly_flag == MA_SO_OLD)
                                                accum+= 1.0f;
-                                       }
+
                                        continue;
                                }
 
@@ -1543,11 +1543,9 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
 
                                if (shi->mat->shadowonly_flag == MA_SO_OLD) {
                                        /* Old "Shadows Only" */
-                                       ir+= 1.0f;
                                        accum+= (1.0f-visifac) + (visifac)*rgb_to_grayscale(shadfac)*shadfac[3];
                                }
                                else {
-                                       ir+= lar->energy;
                                        shaded += rgb_to_grayscale(shadfac)*shadfac[3] * visifac * lar->energy;
 
                                        if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
@@ -1563,9 +1561,6 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
                                accum = 1.0f - accum/ir;
                        }
                        else {
-                               shaded/= ir;
-                               lightness/= ir;
-
                                if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
                                        if (lightness > 0.0f) {
                                                /* Get shadow value from between 0.0f and non-shadowed lightness */
@@ -1581,10 +1576,11 @@ static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
                        }}
 
                        shr->alpha= (shi->alpha)*(accum);
+                       if (shr->alpha<0.0f) shr->alpha=0.0f;
                }
                else {
                        /* If "fully shaded", use full alpha even on areas that have no lights */
-                       if (shi->mat->shadowonly_flag == MA_SO_SHADED) shr->alpha=1.0f;
+                       if (shi->mat->shadowonly_flag == MA_SO_SHADED) shr->alpha=shi->alpha;
                        else shr->alpha= 0.f;
                }
        }