[osg-users] תשובה: GL_LINEAR

Guy guy at dvp.co.il
Mon Sep 8 02:29:48 PDT 2008


Never mind, I think I found the problem.

 

If it interest anyone, the linear interpolation uses the four nearest pixel. Therefore, when the texture coordinates is very small, one of the neighbors is the border pixel, or the edge.

 

In order to use only values from the texture, the texture coordinate value which is in [0,1] should be mapped to the range [1/2n,(2n-1)/2n] where n is the texture size at each direction.

 

I'd be happy to hear remarks, since I'm not entirely sure this solution is correct.

 

Thanks,

 Guy.

 

________________________________

מאת: osg-users-bounces at lists.openscenegraph.org [mailto:osg-users-bounces at lists.openscenegraph.org] בשם Guy
נשלח: Monday, September 08, 2008 11:42 AM
אל: OpenSceneGraph Users
נושא: [osg-users] GL_LINEAR

 

Hello,

 I have a problem with GL_LINEAR filtering of a float texture.

 

I created a 2D float image with the values

 

100 100

200 200

 

I stretched this image over 300x300 float buffer.

 

The results are defiantly not a linear interpolation of these values.

 

1.       The upper and lower quarters of the image are constants. The constant value is the value that should have been only in the upper most and lower most rows. It seems the interpolation of a pixel with 0.001 coordinates for example, takes into consideration values with negative texture coordinates. (I can't find any other explanation).

2.       Between these quarters, the image SEEMS to be linearly interpolated, but it is not. I would expect the differences between two sequential pixels to be constant, but the differences are not the same.

 

 

I had this problem both with OSG1.2 and OSG2.0. I don't believe it has anything to do with the OSG code, but with the hardware implementation.

 

I used the following code to create the texture:

 

                  image->setImage(  width, 

                                    height,

                                    1,

                                    GL_RGBA16F_ARB, 

                                    GL_RGBA, 

                                    GL_FLOAT,

                                    (unsigned char*)(new float[4*width*height]),

                                    osg::Image::USE_NEW_DELETE);

 

 

                  osg::Texture2D* rtexture = new osg::Texture2D;

                  //------------------------------------------------------------------------

                  // make the texture float texture

                  //------------------------------------------------------------------------

                  rtexture->setInternalFormat(GL_RGBA16F_ARB);

                  rtexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE);

                  rtexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE);

      

                  rtexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);

                  rtexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

                  rtexture->setSourceFormat(GL_RGBA);

                  rtexture->setSourceType(GL_FLOAT);

                  //========================================================================

                  rtexture->setImage(image);

                  rtexture->setTextureSize(image->s(), image->t());

                  rtexture->setResizeNonPowerOfTwoHint(false);

                  

I also tried it with 32 bit float image.

 

I'm using windows XP and nvidia 8800.

 

Any ideas how to apply a true linear mapping for textures?

 

Thanks,

 Guy.

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080908/4d99b56b/attachment-0002.htm>


More information about the osg-users mailing list