Bug #17912: fix for some SSS floating point precision issues, and also
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 1 Nov 2008 17:07:24 +0000 (17:07 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 1 Nov 2008 17:07:24 +0000 (17:07 +0000)
fix a divide by zero in the subsurf code found in the process.

source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/render/intern/source/sss.c

index ce4458b43070bf3596549a7d6cd000c4a2717fc7..cee032f364eb74c78a70b84f40ffe057c306b2f0 100644 (file)
@@ -1245,9 +1245,11 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        }
                }
 
-               avgSharpness /= sharpCount;
-               if (avgSharpness>1.0) {
-                       avgSharpness = 1.0;
+               if(sharpCount) {
+                       avgSharpness /= sharpCount;
+                       if (avgSharpness>1.0) {
+                               avgSharpness = 1.0;
+                       }
                }
 
                if (seam && seamEdges < 2)
@@ -1543,9 +1545,11 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                }
                        }
 
-                       avgSharpness /= sharpCount;
-                       if (avgSharpness>1.0) {
-                               avgSharpness = 1.0;
+                       if(sharpCount) {
+                               avgSharpness /= sharpCount;
+                               if (avgSharpness>1.0) {
+                                       avgSharpness = 1.0;
+                               }
                        }
 
                        if (seam && seamEdges < 2)
index 9fb48a08503ec88c87213c239f0fd968ab453649..9bde66757983302f849294428e215a60ad719458 100644 (file)
@@ -451,13 +451,13 @@ static void compute_radiance(ScatterTree *tree, float *co, float *rad)
        VECCOPY(rdsum, result.rdsum);
        VECADD(backrdsum, result.rdsum, result.backrdsum);
 
-       if(rdsum[0] > 0.0f) rad[0]= tree->ss[0]->color*rad[0]/rdsum[0];
-       if(rdsum[1] > 0.0f) rad[1]= tree->ss[1]->color*rad[1]/rdsum[1];
-       if(rdsum[2] > 0.0f) rad[2]= tree->ss[2]->color*rad[2]/rdsum[2];
+       if(rdsum[0] > 1e-16f) rad[0]= tree->ss[0]->color*rad[0]/rdsum[0];
+       if(rdsum[1] > 1e-16f) rad[1]= tree->ss[1]->color*rad[1]/rdsum[1];
+       if(rdsum[2] > 1e-16f) rad[2]= tree->ss[2]->color*rad[2]/rdsum[2];
 
-       if(backrdsum[0] > 0.0f) backrad[0]= tree->ss[0]->color*backrad[0]/backrdsum[0];
-       if(backrdsum[1] > 0.0f) backrad[1]= tree->ss[1]->color*backrad[1]/backrdsum[1];
-       if(backrdsum[2] > 0.0f) backrad[2]= tree->ss[2]->color*backrad[2]/backrdsum[2];
+       if(backrdsum[0] > 1e-16f) backrad[0]= tree->ss[0]->color*backrad[0]/backrdsum[0];
+       if(backrdsum[1] > 1e-16f) backrad[1]= tree->ss[1]->color*backrad[1]/backrdsum[1];
+       if(backrdsum[2] > 1e-16f) backrad[2]= tree->ss[2]->color*backrad[2]/backrdsum[2];
 
        rad[0]= MAX2(rad[0], backrad[0]);
        rad[1]= MAX2(rad[1], backrad[1]);
@@ -504,20 +504,20 @@ static void sum_leaf_radiance(ScatterTree *tree, ScatterNode *node)
                }
        }
 
-       if(node->area > 0) {
+       if(node->area > 1e-16f) {
                inv= 1.0/node->area;
                node->rad[0] *= inv;
                node->rad[1] *= inv;
                node->rad[2] *= inv;
        }
-       if(node->backarea > 0) {
+       if(node->backarea > 1e-16f) {
                inv= 1.0/node->backarea;
                node->backrad[0] *= inv;
                node->backrad[1] *= inv;
                node->backrad[2] *= inv;
        }
 
-       if(totrad > 0.0f) {
+       if(totrad > 1e-16f) {
                inv= 1.0/totrad;
                node->co[0] *= inv;
                node->co[1] *= inv;
@@ -578,20 +578,20 @@ static void sum_branch_radiance(ScatterTree *tree, ScatterNode *node)
                node->backarea += subnode->backarea;
        }
 
-       if(node->area > 0) {
+       if(node->area > 1e-16f) {
                inv= 1.0/node->area;
                node->rad[0] *= inv;
                node->rad[1] *= inv;
                node->rad[2] *= inv;
        }
-       if(node->backarea > 0) {
+       if(node->backarea > 1e-16f) {
                inv= 1.0/node->backarea;
                node->backrad[0] *= inv;
                node->backrad[1] *= inv;
                node->backrad[2] *= inv;
        }
 
-       if(totrad > 0.0f) {
+       if(totrad > 1e-16f) {
                inv= 1.0/totrad;
                node->co[0] *= inv;
                node->co[1] *= inv;