View Full Version : passing data in textures - GL_NEAREST?
03-23-2007, 10:31 PM
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)?
03-24-2007, 01:38 AM
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).
03-24-2007, 05:18 AM
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)?
03-24-2007, 06:13 AM
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.
03-24-2007, 06:53 AM
So does the mag/min filter affect the operation of texture2D in the FS?
03-24-2007, 08:44 AM
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.
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.
03-24-2007, 09:43 AM
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?
03-24-2007, 11:59 AM
Yes that is no problem. Each texture has it's own set of texture parameters.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.