DOF node: clamp blurring the zdepth radius buffer by the blur max. This could doo...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 8 Aug 2012 16:14:56 +0000 (16:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 8 Aug 2012 16:14:56 +0000 (16:14 +0000)
source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp
source/blender/nodes/composite/nodes/node_composite_defocus.c

index e3f95eac3b4f1c150744e64189313f0cd1b4f338..e005232ec008ca33d54e363ae74c10204716ca47 100644 (file)
@@ -53,9 +53,11 @@ float ConvertDepthToRadiusOperation::determineFocalDistance()
                        normalize_m4(obmat);
                        invert_m4_m4(imat, obmat);
                        mult_m4_m4m4(mat, imat, camera->dof_ob->obmat);
-                       return (float)fabs(mat[3][2]);
+                       return fabsf(mat[3][2]);
+               }
+               else {
+                       return camera->YF_dofdist;
                }
-               return camera->YF_dofdist;
        }
 }
 
@@ -71,7 +73,7 @@ void ConvertDepthToRadiusOperation::initExecution()
        this->m_dof_sp = (float)minsz / (16.f / this->m_cam_lens);    // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov);
        
        if (this->m_blurPostOperation) {
-               m_blurPostOperation->setSigma(m_aperture * 128.0f);
+               m_blurPostOperation->setSigma(min(m_aperture * 128.0f, this->m_maxRadius));
        }
 }
 
index d9ee067efe3a9084cae3b66f690ea35d009de083..45d070ba8d2604468bc2d9ce01ac1a63090f4af1 100644 (file)
@@ -166,17 +166,17 @@ static void IIR_gauss_single(CompBuf *buf, float sigma)
        // see "Recursive Gabor Filtering" by Young/VanVliet
        // all factors here in double.prec. Required, because for single.prec it seems to blow up if sigma > ~200
        if (sigma >= 3.556f)
-               q = 0.9804f*(sigma - 3.556f) + 2.5091f;
+               q = 0.9804f * (sigma - 3.556f) + 2.5091f;
        else // sigma >= 0.5
-               q = (0.0561f*sigma + 0.5784f)*sigma - 0.2568f;
-       q2 = q*q;
-       sc = (1.1668 + q)*(3.203729649  + (2.21566 + q)*q);
+               q = (0.0561f * sigma + 0.5784f) * sigma - 0.2568f;
+       q2 = q * q;
+       sc = (1.1668 + q) * (3.203729649  + (2.21566 + q) * q);
        // no gabor filtering here, so no complex multiplies, just the regular coefs.
        // all negated here, so as not to have to recalc Triggs/Sdika matrix
-       cf[1] = q*(5.788961737 + (6.76492 + 3.0*q)*q)/ sc;
-       cf[2] = -q2*(3.38246 + 3.0*q)/sc;
+       cf[1] = q * (5.788961737 + (6.76492 + 3.0 * q) * q) / sc;
+       cf[2] = -q2 * (3.38246 + 3.0 * q) / sc;
        // 0 & 3 unchanged
-       cf[3] = q2*q/sc;
+       cf[3] = q2 * q / sc;
        cf[0] = 1.0 - cf[1] - cf[2] - cf[3];
 
        // Triggs/Sdika border corrections,
@@ -336,7 +336,7 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf,
                // fast blur...
                // bug #6656 part 1, probably when previous node_composite.c was split into separate files, it was not properly updated
                // to include recent cvs commits (well, at least not defocus node), so this part was missing...
-               wt = aperture*128.f;
+               wt = minf(nqd->maxblur, aperture * 128.0f);
                IIR_gauss_single(crad, wt);
                IIR_gauss_single(wts, wt);