Processing screen co-ordinates to GLSL
in
Programming Questions
•
2 months ago
Finally had some time to start digging into Processing 2 and the shader API, and I've managed to get some simple shaders going. Is there any way to work out the screen co-ordinates of the fragment that the shader is operating on?
Say I want to have the shader colour every even numbered Y co-ordinate red, and every odd Y co-ordinate green.
The shader's main() method would, I guess, be something like this (in pseudo-ish code):
- void main(){
- vec2 pos= vec2(xpos, ypos); //this line is fiction
- if(mod(pos.y, 2.0) == 0.0){
- gl_FragColor= vec4(1.0, 0.0, 0.0, 1.0);
- }
- else
- gl_FragColor= vec4(0.0, 1.0, 0.0, 1.0);
- }
- }
So far, so reasonably straightforward, but how do I convert from the co-ordinates the shader knows about to ones I can use? I thought it would be a simple case of passing in the values of width and height and mapping them to vertTexCoord or gl_FragCoord but I can't seem to make that work. Any hints appreciated.
1