00001 /************************************************************************ 00002 * filterwidth.h - Some handy macros for filter size estimation 00003 * for antialiasing of shaders. 00004 * 00005 * Author: Larry Gritz (gritzl@acm.org) 00006 * 00007 * Reference: 00008 * _Advanced RenderMan: Creating CGI for Motion Picture_, 00009 * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. 00010 * 00011 * $Revision: 1.1 $ $Date: 2000/08/28 01:30:35 $ 00012 * 00013 ************************************************************************/ 00014 00015 00016 00017 #ifndef FILTERWIDTH_H 00018 #define FILTERWIDTH_H 1 00019 00020 /* Define metrics for estimating filter widths, if none has already 00021 * been defined. This is crucial for antialiasing. 00022 */ 00023 #ifndef MINFILTWIDTH 00024 # define MINFILTWIDTH 1.0e-6 00025 #endif 00026 00027 00028 /* The filterwidth macro takes a float and returns the approximate 00029 * amount that the float changes from pixel to adjacent pixel. 00030 */ 00031 #define filterwidth(x) max (abs(Du(x)*du) + abs(Dv(x)*dv), MINFILTWIDTH) 00032 00033 00034 /* The filterwidthp macro is similar to filterwidth, but is for 00035 * point data. 00036 */ 00037 #define filterwidthp(p) max (sqrt(area(p)), MINFILTWIDTH) 00038 00039 00040 00041 /* Given a function g, its known average g_avg, its high frequency 00042 * feature size, and a filter width, fade to the average as we approach 00043 * the Nyquist limit. 00044 */ 00045 #define fadeout(g,g_avg,featuresize,fwidth) \ 00046 mix (g, g_avg, smoothstep(.2,.6,fwidth/featuresize)) 00047 00048 00049 #endif /* FILTERWIDTH_H */