Help understanding trilinear interpolation formula

Started by
2 comments, last by rubicondev 14 years ago
I need to perform trilinear interpolation between two 3 dimensional vectors in my vertex shader. I haven't been able to find well explained formula for doing this. If someone doesn't mind linking me or giving me a brief explanation, that would be appreciated. Up to this point I've just been using the Lerp routines in the vectors. Thanks
Advertisement
Quote:Original post by Jeremy6996
I need to perform trilinear interpolation between two 3 dimensional vectors in my vertex shader.
Are you sure you actually mean tri-linear interpolation? A linear interpolation is done between 2 values (w/o restricting "values" to scalars here, i.e. they can be vectors, too). A bi-linear interpolation is a linear interpolation of 2 already linear interpolated values. And a tri-linear interpolation is a linear interpolation between 2 already bi-linear interpolated values. That said, a tri-linear interpolation is done using 8 values (2x2x2).

Now, you actually have 6 scalar values due to 2 3D vectors. Even if these 6 velues are uncommonly organized in 2 3D vectors (I mean uncommonly w.r.t. the scheme described above), there would be a lack of 2 values.

Hence you probably just want to perform a linear interpolation of 2 3D vectors. Assuming that the vector is defined in Cartesian space, this means to do 3 independent linear interpolation between the 2 scalars of each dimension.
Quote:Original post by haegarr
Quote:Original post by Jeremy6996
I need to perform trilinear interpolation between two 3 dimensional vectors in my vertex shader.
Are you sure you actually mean tri-linear interpolation? A linear interpolation is done between 2 values (w/o restricting "values" to scalars here, i.e. they can be vectors, too). A bi-linear interpolation is a linear interpolation of 2 already linear interpolated values. And a tri-linear interpolation is a linear interpolation between 2 already bi-linear interpolated values. That said, a tri-linear interpolation is done using 8 values (2x2x2).

Now, you actually have 6 scalar values due to 2 3D vectors. Even if these 6 velues are uncommonly organized in 2 3D vectors (I mean uncommonly w.r.t. the scheme described above), there would be a lack of 2 values.

Hence you probably just want to perform a linear interpolation of 2 3D vectors. Assuming that the vector is defined in Cartesian space, this means to do 3 independent linear interpolation between the 2 scalars of each dimension.


Yeah, sorry, I was doing some wiki-ing, and I got confused when it said something about trilinear on 3 dimensional vectors.

Linear is what I'm after. Thanks.

pu = p0 + u(p1 - p0)

So(pseudo code)

float[] vec1 = float[3];float[] vec2 = float[3];float[] interpolatedVec[3];for(int i = 0; i < 3; i++)    interpolatedVec = vec1 + fAmount(vec2 - vec1);
If you're looking for linear interpolation, then I'm not surprised you haven't found it explained in full as it's pretty trivial. I guess its the term that has you confused, not the actual process.

Assuming your interpolator ranges between 0 and 1 (it should), then:

NewVal = Val2*Interpolator + Val1*(1-Interpolator)

What you're saying here is "Gimme a bit from this one, and the rest from the other one".

As long as all three are the same, you can use any types you like for those vals.

EDIT: Just re-read your post. "Lerp" being short for "Linear Interpolation" then you're already right on the money! :)
------------------------------Great Little War Game

This topic is closed to new replies.

Advertisement