views:

291

answers:

2

I'm writing a shader in GLSL and I need to pass it a certain amount of information. The only practical way to pass this information is using a 1-D texture.
I'm creating the texture and setting GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER to GL_NEAREST
Now from the shader I need to access the texture so I'll be able to exactly index each and every number 3-value vector I put into it.
What is a sure-fire way to do this easily?
What I'm looking for is a formula which takes the size of the array and the index I want and give me the number in [0,1] which corresponds to the texel I want.

+2  A: 
idx/(size-1)

perhaps? Just make sure idx and size are floats first.

Jay Kominek
While that works (thanks to nearest neighbor), the correct way should be (idx + 0.5) / size.
Maurice Gilden
+2  A: 

Just found out that OpenGL 3.0 makes this need obsolete with the introduction of the texelFetch() functions which are also available with the extension GL_EXT_gpu_shader4

shoosh