fixed some issues with the new "shadow only + shading" code.
authorM.G. Kishalmi <lmg@kishalmi.net>
Tue, 26 Apr 2011 15:29:12 +0000 (15:29 +0000)
committerM.G. Kishalmi <lmg@kishalmi.net>
Tue, 26 Apr 2011 15:29:12 +0000 (15:29 +0000)
patch from MiikaH.

source/blender/render/intern/source/shadeoutput.c

index 97c6c5620287c7dcdba2ab50b5ad1e011312ac75..5a5de938e43da29337b51d8b878d942cc1ff122a 100644 (file)
@@ -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;
                }
        }