POV-Ray : Newsgroups : povray.general : Feature requests : Re: Feature requests Server Time
5 Aug 2024 20:23:40 EDT (-0400)
  Re: Feature requests  
From: Marcus Fritzsch
Date: 11 Sep 2002 10:56:26
Message: <3D7F595A.9090908@fritschy.de>
Hi,

Slime schrieb:
> Hmm, that picture *does* show cubic interpolation blurring the pixels
> together too much.
> 
> I always thought bi-cubic interpolation was really just bi-linear
> interpolation with the points interpolated between in a smoother manner.
> Like, if you graphed a row of pixels interpolated with bi-linear
> interpolation, you'd have a bunch of points connected with straight lines,
> but if you graphed it with bi-cubic interpolation, you'd have a bunch of
> points connected with curves that match the curve
> 
> y = -2*x^3 + 3*x^2 = x^2*(3-2*x)
I implemented cubic-interpolation for a perlin noise ... here is some code:

----+----+----+----+---- interpolatedNoise2d ----+----+----+----+----
         int IntX = ( int )x;
         int IntY = ( int )y;

         double FractX = x - IntX;
         double FractY = y - IntY;

         // to store all the numbers
         double  cv0,  cv1,  cv2,  cv3,  cv4,  cv5,  cv6,  cv7,
                 cv8,  cv9, cv10, cv11, cv12, cv13, cv14, cv15;
         double  ci0,  ci1,  ci2,  ci3;
         int IntX1, IntY1, IntX2, IntY2, IntX3, IntY3, IntX4, IntY4;

         // some variables....
         IntX1 = IntX - 1;
         IntX2 = IntX;
         IntX3 = IntX + 1;
         IntX4 = IntX + 2;
         IntY1 = IntY - 1;
         IntY2 = IntY;
         IntY3 = IntY + 1;
         IntY4 = IntY + 2;

         // smoothedNoise2d( x, y ); returns a noise for these
         // coordinates
         cv0   = smoothedNoise2d( IntX1, IntY1 );
         cv1   = smoothedNoise2d( IntX2, IntY1 );
         cv2   = smoothedNoise2d( IntX3, IntY1 );
         cv3   = smoothedNoise2d( IntX4, IntY1 );
         cv4   = smoothedNoise2d( IntX1, IntY2 );
         cv5   = smoothedNoise2d( IntX2, IntY2 );
         cv6   = smoothedNoise2d( IntX3, IntY2 );
         cv7   = smoothedNoise2d( IntX4, IntY2 );
         cv8   = smoothedNoise2d( IntX1, IntY3 );
         cv9   = smoothedNoise2d( IntX2, IntY3 );
         cv10  = smoothedNoise2d( IntX3, IntY3 );
         cv11  = smoothedNoise2d( IntX4, IntY3 );
         cv12  = smoothedNoise2d( IntX1, IntY4 );
         cv13  = smoothedNoise2d( IntX2, IntY4 );
         cv14  = smoothedNoise2d( IntX3, IntY4 );
         cv15  = smoothedNoise2d( IntX4, IntY4 );

         ci0   = cubicInterpolate(  cv0,  cv1,  cv2,  cv3, FractX );
         ci1   = cubicInterpolate(  cv4,  cv5,  cv6,  cv7, FractX );
         ci2   = cubicInterpolate(  cv8,  cv9, cv10, cv11, FractX );
         ci3   = cubicInterpolate( cv12, cv13, cv14, cv15, FractX );

         return  cubicInterpolate(  ci0,  ci1,  ci2,  ci3, FractY );
----+----+----+----+---- cubicInterpolate ----+----+----+----+----
         double p = ( v3 - v2 ) - ( v0 - v1 );
         double q = ( v0 - v1 ) - p;
         double r = v2 - v0;
         double s = v1;

         return p * pow( x, 3 ) + q * pow( x, 2 ) + r * x + s;
----+----+----+----+----
If someone can knows to add this to povray... feel free to use this code :o)

here is the tutorial from where i learned about:

http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

i also wrote some code for cubic-interpolation in 3-dimensions, it's 
very long, but works well...

greetings, Marcus


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.