toneburst

06-05-2010, 02:25 AM

I guess this is more of a conceptual problem that anything else. I'm just struggling with some ideas about interpolation methods. What I'm attempting to do is make a fragment shader to create the transfer function mentioned in this post

http://graphicsrunner.blogspot.com/2009/01/volume-rendering-102-transfer-functions.html

It's basically a cubic interpolation curve between 7 values for alpha spaced across the x-axis of a small 1D texture.

Looking at this page on interpolation methods

http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/

my initial thought was that I needed a simple 1D version of the algorithm.

double CubicInterpolate(

double y0,double y1,

double y2,double y3,

double mu)

{

double a0,a1,a2,a3,mu2;

mu2 = mu*mu;

a0 = y3 - y2 - y0 + y1;

a1 = y0 - y1 - a0;

a2 = y2 - y0;

a3 = y1;

return(a0*mu*mu2+a1*mu2+a2*mu+a3);

}

This I can do fairly easily in a shader, with mu being the x value across the texture, scaled to the 0>1 range between each point.

However, it turns out that only works if the points are equally-spaced along the x, and I need to be able to slide them along the x-axis, so my next thought was that I could try a 2D version, which apparently can be done by simply applying the same algorithm to the two axes independently (in my case, x, and alpha value). I can work out how to apply the cubic interpolation method independently to the x and y values of a set of 2D points (where a point can be placed in an arbitrary position in 2D space, according to a given value of mu), but what I can't work out is how to apply the same thing in a fragment shader program. I'm guessing the equation has to be rearranged in some way, but I've no real idea where to start in doing this.

Any tips, anyone? I'm sure this is really simple stuff to someone with better maths skills than me...

Cheers,

a|x

http://www.machinesdontcare.wordpress.com

I hope I've explained this in a way that makes some sense.

http://graphicsrunner.blogspot.com/2009/01/volume-rendering-102-transfer-functions.html

It's basically a cubic interpolation curve between 7 values for alpha spaced across the x-axis of a small 1D texture.

Looking at this page on interpolation methods

http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/interpolation/

my initial thought was that I needed a simple 1D version of the algorithm.

double CubicInterpolate(

double y0,double y1,

double y2,double y3,

double mu)

{

double a0,a1,a2,a3,mu2;

mu2 = mu*mu;

a0 = y3 - y2 - y0 + y1;

a1 = y0 - y1 - a0;

a2 = y2 - y0;

a3 = y1;

return(a0*mu*mu2+a1*mu2+a2*mu+a3);

}

This I can do fairly easily in a shader, with mu being the x value across the texture, scaled to the 0>1 range between each point.

However, it turns out that only works if the points are equally-spaced along the x, and I need to be able to slide them along the x-axis, so my next thought was that I could try a 2D version, which apparently can be done by simply applying the same algorithm to the two axes independently (in my case, x, and alpha value). I can work out how to apply the cubic interpolation method independently to the x and y values of a set of 2D points (where a point can be placed in an arbitrary position in 2D space, according to a given value of mu), but what I can't work out is how to apply the same thing in a fragment shader program. I'm guessing the equation has to be rearranged in some way, but I've no real idea where to start in doing this.

Any tips, anyone? I'm sure this is really simple stuff to someone with better maths skills than me...

Cheers,

a|x

http://www.machinesdontcare.wordpress.com

I hope I've explained this in a way that makes some sense.