What are the steps taken by this GLSL code?

Posted by user827992 on Game Development See other posts from Game Development or by user827992
Published on 2012-09-01T19:53:17Z Indexed on 2012/09/01 21:50 UTC
Read the original article Hit count: 204

Filed under:
|
 1 void main(void)
 2 {
 3     vec2 pos = mod(gl_FragCoord.xy, vec2(50.0)) - vec2(25.0);
 4     float dist_squared = dot(pos, pos);
 5 
 6     gl_FragColor = (dist_squared < 400.0) 
 7         ? vec4(.90, .90, .90, 1.0)
 8         : vec4(.20, .20, .40, 1.0);
 9 }

taken from http://people.freedesktop.org/~idr/OpenGL_tutorials/03-fragment-intro.html

Now, this looks really trivial and simple, but my problem is with the mod function.

This function is taking 2 vec2 as inputs but is supposed to take just 2 atomic arguments according to the official documentation, also this function makes an implicit use of the floor function that only accepts, again, 1 atomic argument.

Can someone explain this to me step by step and point out what I'm not getting here?

It's some kind of OpenGL trick? OpenGL Math trick? in the GLSL docs i always find and explicit reference to the type accepted by the function and vec2 it's not there.

© Game Development or respective owner

Related posts about math

Related posts about glsl