Useful Interpolation Functions for Noise Development

Interpolation functions allow us to calculate a transition between discreet points.  They are used in noise development.   Here are some common types.

Smooth interpolation of a linear input from 0.0 to 1.0

This is a very common interpolation function.  It calculates a smooth transition from 0.0 to 1.0 as the input increases linearly from 0.0 to 1.0.  By smooth I mean the gradient is 0.0 at 0.0, 0.0 at 1.0 and positive in between.  An example is the GLSL function SmoothStep().

Ken Perlin uses a cubic hermite curve in his original classic noise.  It is of the form f(x) = 3x^2-2x^3.  A problem is that the 2nd derivative is non-zero at 0.0 and 1.0.  This can result in a sharp transition when the noise is used to calculate a normal for shading.  Ken solved the problem with a quintic hermite curve of the form f(x) = 6x^5-15x^4+10x^3.  This new function has both 1st and 2nd derivatives of 0.0 at 0.0 and 1.0.  More details can be found in his paper.  http://mrl.nyu.edu/~perlin/paper445.pdf

The cubic curve is said to be 1st derivative continuous ( C1 for short ).  The quintic curve is said to be 1st and 2nd derivative continuous ( C2 for short ).

Here are 4 implementations of this interpolation function.  The first two are the previously mentioned cubic and quintic curves.  The third is a more efficient C2 interpolation function which contains 1 less multiply than Perlin’s quintic curve.  The forth is a C3 interpolation function.  Their graph can be seen here.

//
//    Interpolation functions
//    ( smoothly increase from 0.0 to 1.0 as x increases linearly from 0.0 to 1.0 )
//

//    Cubic Hermine Curve.  Same as SmoothStep().  As used by Perlin in Original Noise.
//    3x^2-2x^3
float Interpolation_C1( float x ) { return x * x * (3.0 - 2.0 * x); }

//    Quintic Hermite Curve.  As used by Perlin in Improved Noise.  http://mrl.nyu.edu/~perlin/paper445.pdf
//    6x^5-15x^4+10x^3
float Interpolation_C2( float x ) { return x * x * x * (x * (x * 6.0 - 15.0) + 10.0); }

//    Faster than Perlin Quintic.  Not quite as good shape.
//    7x^3-7x^4+x^7
float Interpolation_C2_Fast( float x ) { float x3 = x*x*x; return ( 7.0 + ( x3 - 7.0 ) * x ) * x3; }

//    C3 Interpolation function.  If anyone ever needs it... : )
//    25x^4-48x^5+25x^6-x^10
float Interpolation_C3( float x ) { float xsq = x*x; float xsqsq = xsq*xsq; return xsqsq * ( 25.0 - 48.0 * x + xsq * ( 25.0 - xsqsq ) ); }

Smooth falloff of a squared input from 0.0 to 1.0

A smooth falloff function is a function which decreases from 1.0 to 0.0 as its input increases from 0.0 to 1.0.  To say that it operates on x-squared means that it accepts a squared input rather than a linear one.  They can be used to efficiently fade out from a point due to the avoidance of a sqrt() call.

Listed here are two which are commonly used.  A graph of the functions can be seen here.  Included in the comments are some smooth interpolating functions also defined in x-squared.  Their graph can be seen here.

//
//    Falloff defined in XSquared
//    ( smoothly decrease from 1.0 to 0.0 as xsq increases from 0.0 to 1.0 )
//

// ( 1.0 - x*x )^2 ( Used by Humus for lighting falloff in Just Cause 2. GPUPro 1 )
float Falloff_Xsq_C1( float xsq ) { xsq = 1.0 - xsq; return xsq*xsq; }
// ( 1.0 - x*x )^3. NOTE: 2nd derivative is 0.0 at x=1.0, but non-zero at x=0.0
float Falloff_Xsq_C2( float xsq ) { xsq = 1.0 - xsq; return xsq*xsq*xsq; }

//
//  For interest here are some smooth interpolation functions defined in x-squared
//
//  C1:      f(x) = 1.0 - ( 1.0 - x*x )^2
//  C2:      f(x) = 9x^4-16x^6+9x^8-x^12
//  C2 Fast: f(x) = 5x^4-5x^6+x^10  or  f(x) = 3x^4-3x^8+x^12
//  C3:      f(x) = 10x^4-20x^6+15x^8-4x^10
//
Advertisements

About briansharpe

Computer games and graphics programmer interested in procedural modeling and texturing techniques. Current Work: Weta Digital. Work history: Sidhe Interactive, Sony London (SCEE), Pandromeda,
This entry was posted in Uncategorized. Bookmark the permalink.

One Response to Useful Interpolation Functions for Noise Development

  1. Pingback: Hermite Noise | briansharpe

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s