I know I could use gl_Position
to get every vertex's position, but if it's possible to get every pixel's position in fragment shader ?
I want to change the alpha value of some pixel area.
I know I could use gl_Position
to get every vertex's position, but if it's possible to get every pixel's position in fragment shader ?
I want to change the alpha value of some pixel area.
It will return you position of the fragment on the screen in pixels. If you pass uniform
vec2 screenResolution
then you could play with that two values to determine where exactly on the screen is pixel, in which part and such.This is a built-in variable, so you can use it whenever you want in fragment shader.
Here's one example of usage just to demonstrate: http://goo.gl/AG7UO
If you want woorld coordinate of the fragment, then you should use
varying
variable.Vertex shader:
Fragment shader:
Hope this helps.