Jump to content
  • Advertisement
Sign in to follow this  
pickups

OpenGL Emulating bi-linear filtering in pixel shaders

This topic is 4828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I want to emulate bi-linear filtering on floating point textures. So i need to write a function to do it for me, right? I think i know how to do it, but the d3d way of handling tex coords seems very non efficient, so i just wanted to make sure what i know is correct: The tex coords are between 0 to 1, so in order to do bi-linear filtering i need to pass to the shader the texel size, and the texture resolution, or at least on of them, right? In openGl the texcoords are 0 to width/height, and thats easier to work with. Am i right?

Share this post


Link to post
Share on other sites
Advertisement
Nobody knows? Hmm, it is quiet necessary to do bilinear filtering on floating point textures. Maybe in d3d9 the limitation of no filtering doesn't exist? I looked for some info of it on the docs, but couldn't find.

Share this post


Link to post
Share on other sites
It's been a while since I played with OpenGL, but if I remember correctly, texture coordinates in OpenGL are also 0..1. The difference is that in OpenGL, (0,0) is the bottom left and in D3D, (0,0) is the upper left.

In any case, you'll need to know the width and height of a texel (1.0/width and 1.0/height) to be able to offset your texture coordinates. In your pixel shader, you can use these values to sample the neighboring texels of your texture. Once you've got the samples you need, performing the bilinear filtering operation is pretty simple.

neneboricua

Share this post


Link to post
Share on other sites
Right, i can sample the neighbours, but in order to perform bilinear filtering, i need to sample the texture at the four closest texels, and then interp to find the colour where i want, between them. In order to find these four closest texels i need the tex resolution no?

About openGl, i also havn't used it for quiet a while, but i saw a cg program that treats the coords as 0 to width, and not 0 to 1.

Share this post


Link to post
Share on other sites
Quote:
but i saw a cg program that treats the coords as 0 to width, and not 0 to 1.


It was probably using rectangle textures (an extension with its own set of quirks). Tex coords in GL are 0..1, just like in D3D.

Share this post


Link to post
Share on other sites
Hi,

Yes, you have to pass either the texel size or the size of the texture. Look at this for an example (the blur pixel shader):
http://www.gamedev.net/reference/articles/article2193.asp

kp

Share this post


Link to post
Share on other sites
Right, i forgot this extension. No way to do it in d3d? What are the advantages of using 0 to 1 tex coords?

Share this post


Link to post
Share on other sites
The advantange of using 0 - 1 texel coords is that you can change the size of the texture without changing your vertex data (or your shader).

Anyway, you'll have to pass in some information like the size of a texel in [0,1] space as others have said. The filtering operation is pretty easy when you have that information; write it just like you would in C.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!