WikiFilter.h

From Odwiki

Jump to: navigation, search
/****************************************************************************
           File:  wikiFilter.h
        Authors:  The od[wiki] community at
                  http://www.odforce.net/wiki
 
    Description:  Filter size estimation.
 
                  Only meaningful in contexts that provide the functions
                  Du() and Dv() -- currently, that's all shading contexts.
 
 -----------------------------------------------------------------------------
    Part of the small but growing od[wiki] library of VEX functions...
    This software is placed in the public domain and is provided as is
    without express or implied warranty.
 *****************************************************************************/
 
 
 
 #ifndef wikiFilter_h__GUARD
 #define wikiFilter_h__GUARD
 
 
 // The minimum filter width we'll allow
 #define  MINFILTWIDTH   1.0e-6
 
 //----------------------------------------------------------------------------
 // Filterwidth
 //----------------------------------------------------------------------------
 //
 // Note: If you're using vcc to compile your OP (as opposed to
 // building it in Vex Builder), then you need to define WM_HAVE_DERIVS
 // somewhere in your files like this:
 //
 // #define WM_HAVE_DERIVS
 //
 // or by including one of the wikiOp[optype].h files, like this:
 //
 // #include <wikiOpShader.h>
 //
 // If, however, you're including this file directly in an OP that you're
 // building in Vex Builder, you don't have to do anything special.
 //
 //----------------------------------------------------------------------------
 
 #if defined(VOP_SHADING) || defined(VOP_COP2) || defined(WM_HAVE_DERIVS)
 
    // Float Attributes
    float filterwidthX(float x) {
       return max (abs(Du(x)) + abs(Dv(x)), MINFILTWIDTH);
    }
 
    // 2D Float pairs (like s,t)
    float filterwidthST(float ss,tt) {
       return max(filterwidthX(ss),filterwidthX(tt));
    }
 
    // 3D Vector
    float filterwidthP(vector p) {
       return max(sqrt(area(p)), MINFILTWIDTH);
    }
 
    // 4D Vector4
    float filterwidthP4(vector4 pT) {
       vector p3 = set(pT.x,pT.y,pT.z);
       return max(sqrt(area(p3)), MINFILTWIDTH);
    }
 
 #else
 
    // Fallback functions for contexts that don't provide derivs.
    float filterwidthX(float x) {
       return 0.0025;
    }
    float filterwidthST(float ss,tt) {
       return 0.0025;
    }
    float filterwidthP(vector p) {
       return 0.0025;
    }
    float filterwidthP4(vector4 pT) {
       return 0.0025;
    }
 
 #endif
 
 
 
 //----------------------------------------------------------------------------
 // Fadeout
 //----------------------------------------------------------------------------
 
 #define fadeout(g,g_avg,featuresize,filtwidth) \
         lerp(g, g_avg, smooth(0.2,0.6,fwidth/featuresize))
 
 
 
 #endif // End wikiFilter_h__GUARD
© 2009 od[force].net | advertise