Rong Yao

08-25-2003, 11:26 AM

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?

View Full Version : Interpolation in Texture Mapping

Rong Yao

08-25-2003, 11:26 AM

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?

al_bob

08-25-2003, 11:36 AM

What do you want to interpolate again?

Rong Yao

08-25-2003, 11:57 AM

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?

Originally posted by al_bob:

What do you want to interpolate again?

1234!

08-25-2003, 12:12 PM

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.

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

Hope thats helps.

al_bob

08-25-2003, 01:37 PM

Are you planning to interpolate:

- texels?

- texture coordinates?

- other vertex attributes?

Is it bilinear or trilinear interpolation, or something else?

- texels?

- texture coordinates?

- other vertex attributes?

Is it bilinear or trilinear interpolation, or something else?

Rong Yao

08-26-2003, 05:15 AM

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.

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.

Deiussum

08-26-2003, 06:02 AM

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).]

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).]

Rong Yao

08-26-2003, 06:33 AM

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

marcus256

08-28-2003, 11:33 AM

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_FILTE R,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 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_FILTE R,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...

Thr33d

09-02-2003, 12:24 PM

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

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

dorbie

09-04-2003, 12:31 AM

Yes you can do this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Deiussum

09-04-2003, 05:31 AM

Originally posted by dorbie:

Yes you can do this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

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.

Yes you can do this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

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.

bumby

09-04-2003, 06:59 AM

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

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

gardener

09-09-2003, 02:59 PM

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:

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

Originally posted by Thr33d:

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

Rong Yao

09-09-2003, 03:07 PM

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?

Thr33d

09-11-2003, 06:32 AM

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'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

Thr33d

09-11-2003, 07:18 AM

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)

http://mjgoeke.members.easyspace.com/cellular/Exp3.jpg

Modified Cellular Functions (http://mjgoeke.members.easyspace.com/cellular)

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).]

(EDIT: Example Image)

http://mjgoeke.members.easyspace.com/cellular/Exp3.jpg

Modified Cellular Functions (http://mjgoeke.members.easyspace.com/cellular)

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).]

Rong Yao

09-15-2003, 12:16 PM

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

Originally posted by Thr33d:

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

Originally posted by Thr33d:

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

Thr33d

09-15-2003, 01:12 PM

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

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.