[#18837] if a sunlamp is set to a too high energy, speculars turn black
authorCampbell Barton <ideasman42@gmail.com>
Wed, 26 Aug 2009 16:05:01 +0000 (16:05 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 26 Aug 2009 16:05:01 +0000 (16:05 +0000)
shr->spec values could be greater then 1.0, causing negative color when using (1.0-shr->spec[i]) as a blending factor.

When shr->spec[i] is 1.0 the mircol is ignored, so only mix the mircol when needed (like clamping the spec).

source/blender/render/intern/source/rayshade.c

index 75b9557f3374fbe6ce142cb57152d817c704a155..182e60365a614cafb39f6dcfd767205e0c34173a 100644 (file)
@@ -1239,15 +1239,18 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr)
                        }
                        
                        if(shi->combinedflag & SCE_PASS_REFLECT) {
+                               /* values in shr->spec can be greater then 1.0.
+                                * in the case when it is 1.0 diff */
                                
-                               f= fr*(1.0f-shr->spec[0]);      f1= 1.0f-i;
-                               diff[0]= f*mircol[0] + f1*diff[0];
+                               f1= 1.0f-i;
                                
-                               f= fg*(1.0f-shr->spec[1]);      f1= 1.0f-i;
-                               diff[1]= f*mircol[1] + f1*diff[1];
+                               diff[0] *= f1;
+                               diff[1] *= f1;
+                               diff[2] *= f1;
                                
-                               f= fb*(1.0f-shr->spec[2]);      f1= 1.0f-i;
-                               diff[2]= f*mircol[2] + f1*diff[2];
+                               if(shr->spec[0]<1.0f)   diff[0] += mircol[0] * (fr*(1.0f-shr->spec[0]));
+                               if(shr->spec[1]<1.0f)   diff[1] += mircol[1] * (fg*(1.0f-shr->spec[1]));
+                               if(shr->spec[2]<1.0f)   diff[2] += mircol[2] * (fb*(1.0f-shr->spec[2]));
                        }
                }
        }