Passing data in textures - GL_NEAREST?

I am trying to pass an array of bytes to my fragment shader. Originally I was trying to work with uniform arrays but gave up when I realised you can’t use a variable index to access the data (what exactly is their use then?)

I’m now trying to do it using a texture and storing the data in the RGB components. I’m unsure what exactly the texture2D function does when you pass it texture coordinates - does it always use a GL_NEAREST approach, or does it depend on what the current state is?

Ie, is there a chance that my data will be smoothed (and therefore corrupted)?

If you are accessing them in the FS, then yes, put GL_NEAREST for mag and min filters.

On SM 3 hw, you can access texture in the VS, but GL_NEAREST is a must. Also, it must be of some float format (nVidia).

Yes, i’m using them in the FS.

What do I do then if I want to create a smooth GL_LINEAR texture, but want to access data from a texture (which from what you’re saying would require GL_NEAREST)?

GL_LINEAR is not the smoothness of the data stored in the texture. It simply tells the program what to do when you are reading from in-between texels. So GL_LINEAR will n-dimensional linear interpolation, as opposed to nearest neighbour, for instance. n is the dimension of your texture, i.e. 1D, 2D or 3D.

So does the mag/min filter affect the operation of texture2D in the FS?

It depends on the resulting size (in pixels) of the polygon you want to apply the texture to. If it is e.g. a quad, having the same size ( in pixels, on the screen ) as the texture, then there will be no magnification or minification. So the filters don’t affect FS. Otherwise filters will be used.
Simple example:
Tex: 512x512 pixels
Viewport: 512x512 pixels
Drawing a quad, which fills the viewport results in a 1:1 mapping from texture to screen -> no filters used.

Tex: 256x256 pixels
Viewport: 512x512 pixels
Drawing a quad, which fills the viewport results in a 1:2 mapping from texture to screen (magnification). Filter will affect FS value.

For example, I have two textures,
TextureA: contains the data (want this to be GL_NEAREST)
TextureB: contains image data (want this to be GL_LINEAR)

The return colour comes from TextureB, but depends on the value I get from TextureA.

Can I do this? Can the mag/min filters be different for each texture?

Yes that is no problem. Each texture has it’s own set of texture parameters.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.