Interpolation in Texture Mapping

When we do texture mapping, can we ask OpenGL to do some of the interpolation work for us or we have to do the interpolation work by ourselves before we map the data?

What do you want to interpolate again?

Our data are sparse, if no interpolation, it won’t make a smooth bitmap.

Originally posted by al_bob:
What do you want to interpolate again?

If you have a bitmap/texture and want it to be bi-linear interpolated, then the answer is yes, OpenGL can do that for you.

If you want more advanced filtering methods like a bi-cubic interpolation you have to do it on your own.

Hope thats helps.

Are you planning to interpolate:

  • texels?
  • texture coordinates?
  • other vertex attributes?

Is it bilinear or trilinear interpolation, or something else?

Thank you all!

We want to interpolate the bitmap data(color). Bi-linear or even linear is fine with us. How can we ask OpenGL to do the interpolation work? I did not find any parameter in glTexImage2D or gluBuild2DMipmaps that is related to this operation.

Unless there is some extension I haven’t heard of, I don’t think OpenGL will interpolate texture data for you.

Just to make sure I understand what you’re asking for…

Say you have texture data for a 256x256 texture. But you only have values for for a set number of points on the texture, like say (100, 100), (32, 69), etc… And you want OpenGL to interpolate the rest of the texture data for you from these few points?

I don’t think there is anything built into OpenGL to do this. The only way you could probably get OpenGL to do any part of this would be to use those set points, use them as vertices with distinct colors, determine how to use those vertices in some form of polygon, then do a glReadPixels and store that data into a texture. (Or do something similar as a “render to texture” type operation.)

Or… just do the interpolation yourself. It might end up being easier, and most likely would perform better.

[This message has been edited by Deiussum (edited 08-26-2003).]

You are right, Deiussum. We have data at points and we need some data between points to make the bitmap looks smooth.

Hello Rong,

If your points are more or less randomly placed, there is no easy way for OpenGL to help you (you may be able to come up with an algorithm that can be cleverly approximated by some multi-pass OpenGL rendering, but that is probably not what you want).

If your points are ecenly distributed, say at all multiples of (4,4) or so, then you may be able to put your points in a smaller texture and scale it up to your desired area using bi-linear interpolation (using glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)). By the way, bi-linear means linear in two directions (U and V), so it’s 1st order interpolation (not second order, as one may think).

Oterwise, interpolating between sparsely & randomly placed points is not a simple task. My first (intuitive?) solution would be to form a polynomial “3D surface” function, z=f(x,y), which satisfies the condition that it includes all known points (e.g. z1=f(x1,y1), z2=f(x2,y2) etc), where z is the “color” you ar trying to produce. Basically an N:th order polynomial for N+1 known points (at least if it was a 1D problem, not sure about the 2D case).

If you can solve coefficients for the polynomial, you can easily generate your inbetween samples (color=f(x,y), where f is your polynomial). I’m not sure if this is easy/possible/correct/good looking though…

If you are able to get vertex data (x,y,color) and recreate the trianges/polygons for the mesh represented by the data THEN OpenGL will interpolate the color information for you (if you enable smooth vertex coloring.)

The tough part here will be getting the data from the image and reconstructing the faces.

I’m sure there must be some algorithm out there which creates triangle fans or other geometry types out of irregularly spaced data points.

If your data is already verticies in faces, then - you’re in luck!

-Michael

Yes you can do this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Originally posted by dorbie:
[b]Yes you can do this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);[/b]

That will only work if the sparse data is regularly spaced in such a way that you could shrink it down so that the sparse data fills the texture.

If I understand the problem correctly, you want to make a complete bitmap out of an incomplete one.

You could apply some kind of convolution filter (guassian) to smooth out what you have. I have never used the opengl convolution features, but maybe it could work for you.

Jeremy

Actually, I have the data at vertices. But these vertices are not evenly spaced. Could you show me in more detail how to do that? Thanks!

Originally posted by Thr33d:
[b]If you are able to get vertex data (x,y,color) and recreate the trianges/polygons for the mesh represented by the data THEN OpenGL will interpolate the color information for you (if you enable smooth vertex coloring.)

The tough part here will be getting the data from the image and reconstructing the faces.

I’m sure there must be some algorithm out there which creates triangle fans or other geometry types out of irregularly spaced data points.

If your data is already verticies in faces, then - you’re in luck!

-Michael[/b]

By the way, can we map a bitmap to a surface without break the bitmap and surface into pieces in order to do the mapping work piece by piece? I mean if I offer OpenGL a surface function and a bitmap, can I use some OpenGL commands to do the mapping work without the triangle stuffs? I believe OpenGL has some optimized algorithm inside if there are some such commands. Perhaps evaluator can help us? Is there any other way?

Hi, I worked on it and came up with what I think is a viable solution.

I’ve put together a cellular based function which interpolates the verticies values based upon distance from the verts. By adjusting the weight by distance, and stretching the distance exponentially I am able to control how much the data is “smoothed.”

If you pass the data over here I can probably crank out an image for you.

Just tell me what resolution you want the output in.

Btw, I’ll post up some screenshots and psuedo code if anyone wants it.

-Michael

I don’t know if I can directly post screenshots, so here’s a link to a page with results of 7 points psuedo-randomly place within the rectangular area, given psuedo-random color values.
(EDIT: Example Image)

Modified Cellular Functions
In case that link doesn’t work: http://mjgoeke.members.easyspace.com/cellular

Enjoy,
-Michael

EDIT: added image

[This message has been edited by Thr33d (edited 09-11-2003).]

Yes, I am interested in you program. Please post up some psuedo code. Thanks!

Originally posted by Thr33d:
[b]Hi, I worked on it and came up with what I think is a viable solution.

I’ve put together a cellular based function which interpolates the verticies values based upon distance from the verts. By adjusting the weight by distance, and stretching the distance exponentially I am able to control how much the data is “smoothed.”

If you pass the data over here I can probably crank out an image for you.

Just tell me what resolution you want the output in.

Btw, I’ll post up some screenshots and psuedo code if anyone wants it.

-Michael[/b]

Ok, psuedo code isn’t all that clean, but basically, this is just a modification of what’s already been done in cellular textures.

I’d like to point you to this site: http://www.blackpawn.com/texts/cellular/default.html

to learn what cellular textures are.

Please note that the values derived are based purely from distances from points. In my program, I assume the point has a value (actually, a color) associated with it. I then interpolate that color weighted upon it’s part of the sum of the inverse (exponent) distances.

So, (if that made sense) you have something like -
for each pixel in the image
for each vertex in the area
pixel[x,y].color = vertex[i].color * 1/pythagorean_theorem(vertex[i].position - currentposition) ^ some_exponent
next vertex
next pixel

If you don’t know what the pythagorean theorem is, go look it up. some_exponent is just a value (1 is really grayish between points, 2 is ok, 5 is good, 15 is sharp, 20 is starting to challenge float’s precision)
the caret (^) means “to _ power” _ is the value after the caret.

I’ve added some space partitioning and create lists at runtime to speed things up.

That’s the outline, if you really need the data back, just send it off to me and I’ll process it until it’s how you want it.
Or you could wait for me to clean up me exe a little, give me the data specs (for importing) and I could send off the exe to you.

Later,
-Michael