public float InterpolatedNoise( float x, float y )
{
int xInt = ( int )Math.Floor( x );
float xFloat = x - xInt;
int yInt = ( int )Math.Floor( y );
float yFloat = y - yInt;
float p00, p01, p10, p11;
switch ( InterpolationMode ) {
case NoiseInterpolationMode.Linear:
p00 = StaticNoise( xInt, yInt );
p01 = StaticNoise( xInt, yInt + 1 );
p10 = StaticNoise( xInt + 1, yInt );
p11 = StaticNoise( xInt + 1, yInt + 1 );
return InterpolateLinear( InterpolateLinear( p00, p10, xFloat ), InterpolateLinear( p01, p11, xFloat ), yFloat );
case NoiseInterpolationMode.Cosine:
p00 = StaticNoise( xInt, yInt );
p01 = StaticNoise( xInt, yInt + 1 );
p10 = StaticNoise( xInt + 1, yInt );
p11 = StaticNoise( xInt + 1, yInt + 1 );
return InterpolateCosine( InterpolateCosine( p00, p10, xFloat ), InterpolateCosine( p01, p11, xFloat ), yFloat );
case NoiseInterpolationMode.Bicubic:
for ( int xOffset = -1; xOffset < 3; xOffset++ ) {
for ( int yOffset = -1; yOffset < 3; yOffset++ ) {
points[xOffset + 1, yOffset + 1] = StaticNoise( xInt + xOffset, yInt + yOffset );
}
}
p00 = InterpolateCubic( points[0, 0], points[1, 0], points[2, 0], points[3, 0], xFloat );
p01 = InterpolateCubic( points[0, 1], points[1, 1], points[2, 1], points[3, 1], xFloat );
p10 = InterpolateCubic( points[0, 2], points[1, 2], points[2, 2], points[3, 2], xFloat );
p11 = InterpolateCubic( points[0, 3], points[1, 3], points[2, 3], points[3, 3], xFloat );
return InterpolateCubic( p00, p01, p10, p11, yFloat );
case NoiseInterpolationMode.Spline:
for ( int xOffset = -1; xOffset < 3; xOffset++ ) {
for ( int yOffset = -1; yOffset < 3; yOffset++ ) {
points[xOffset + 1, yOffset + 1] = StaticNoise( xInt + xOffset, yInt + yOffset );
}
}
p00 = InterpolateSpline( points[0, 0], points[1, 0], points[2, 0], points[3, 0], xFloat );
p01 = InterpolateSpline( points[0, 1], points[1, 1], points[2, 1], points[3, 1], xFloat );
p10 = InterpolateSpline( points[0, 2], points[1, 2], points[2, 2], points[3, 2], xFloat );
p11 = InterpolateSpline( points[0, 3], points[1, 3], points[2, 3], points[3, 3], xFloat );
return InterpolateSpline( p00, p01, p10, p11, yFloat );
default:
throw new ArgumentException();
}
}