PDA

View Full Version : FBO and GLSL



mcbastian
08-31-2006, 03:24 AM
Hi,

just a short question, because I found lots of different oppinions about it.

When rendering to a FBO texture, can I use gl_FragCoord in my Fragment Shader to get the x and y pixel screencoordinate? (FBO texture is same size as OpenGL-Window)

I heard about that it should give unpredictable results....


Greetings,
Sebastian

Vexator
08-31-2006, 08:02 AM
gl_FragCoord will return the texture coordinates you assigned to the vertex you're processing - as usual.

Zengar
08-31-2006, 02:40 PM
Since when gl_FragCoord return texture coordinates? oO
I thought it will return window-space coordinates, actually (I would still prefer the device-independent coordinates). No idea how it works with FBO, why won't you try it out?

brtnrdr
08-31-2006, 02:55 PM
gl_FragCoord returns the pixel position of a fragment even with FBO's. In order to turn this into a normalized texture coordinate you would need to divide by the dimensions of the screen aligned quad you rendered (if that's how you generated fragments). It doesn't sound like you care about that though.

Vexator
08-31-2006, 03:24 PM
d'oh i misread sry -.-

Humus
08-31-2006, 07:01 PM
Of course, using gl_FragCoord to get texture coordinates is usually not recommended, especially on previous generation hardware. Use an interpolator instead.