Budric
10-12-2007, 12:23 PM
Hi,
I have rendered something into a texture and now need to access that pixel in the fragment shader. The problem is I don't know how to get the coordinates.
First gl_FragCoord doesn't seem to work at all. The following runs at 5 frames per second in ShaderDesigner cube rendering:
gl_FragColor = (gl_FragCoord + 1.0) / 2.0; And the cube is of uniform white colour, so the coordinates aren't changing according to fragment.
Second, I tried doing:
varying vec4 pos;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
pos = gl_Position.xyzw;
}
varying vec4 pos;
void main()
{
vec2 texc = ((pos.xy / pos.z) + 1.0) / 2.0;
...
}The code above works, however only when I set the near clipping plane to 0, which is not what I want to do. I'm not sure why that is.
Thanks.
I have rendered something into a texture and now need to access that pixel in the fragment shader. The problem is I don't know how to get the coordinates.
First gl_FragCoord doesn't seem to work at all. The following runs at 5 frames per second in ShaderDesigner cube rendering:
gl_FragColor = (gl_FragCoord + 1.0) / 2.0; And the cube is of uniform white colour, so the coordinates aren't changing according to fragment.
Second, I tried doing:
varying vec4 pos;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
pos = gl_Position.xyzw;
}
varying vec4 pos;
void main()
{
vec2 texc = ((pos.xy / pos.z) + 1.0) / 2.0;
...
}The code above works, however only when I set the near clipping plane to 0, which is not what I want to do. I'm not sure why that is.
Thanks.