PDA

View Full Version : Querying Textue Coordinate in Fragment Shader



Rennie Johnson
10-31-2011, 09:22 AM
I want to do color bayer processing in a GLSL fragment shader. In order to determine whether the texel is red, green or blue, I need to know what the X and Y offsets are.

Is there a function available in a fragment shader that will give me the X and Y position of that texel, or do I have to do this in a vertex shader and pass the information on to the fragment shader in a varying vec2 variable?

Alfonse Reinheart
10-31-2011, 10:33 AM
The fragment shader must have a texture coordinate in order to access a texture. Where it comes from is up to you. You could make one up out of thin air, via some algorithm, or from per-vertex data passed from earlier in the rendering pipeline.

Rennie Johnson
10-31-2011, 11:03 AM
Thanks Alfonse.

If I understand you, the coordinate that I'm looking for is the variable 'gl_TexCoord[0].st' that I use in my Texture Sampler Access function 'texture2D()'.

So if I'm using GL_TEXTURE_2D sampler access, I'll get value 0 - 1 for the X and Y values, and if I use GL_TEXTURE_RECTANGLE, I'll get actual discreet pixel values.

Am I getting warmer?

Thanks.