The fragment shader has a built-in value called gl_FragCoord, which provides the pixel coordinates of the target fragment. You must divide this by the width and height of the viewport to get the texture coordinates for the search. Here is a quick example:
uniform vec2 resolution; uniform sampler2D backbuffer; void main( void ) { vec2 position = ( gl_FragCoord.xy / resolution.xy ); vec4 color = texture2D(backbuffer, position);
For a complete working example, try this in a WebGL-compatible browser:
http://glslsandbox.com/e#375.15
emackey
source share