I want to make a post-effect where every second column of pixels is colored differently, and I want to implement this as a GLSL fragment shader on GLES2. The question is what is the most effective way to know if a fragment is indeed odd or even in the x direction?
My current ideas revolve around the following three approaches:
1. Integer bit-wise operator
//Pseudo code bool even_w=((int)(viewport_pixels_width*screenspace_x))&1>0; 2. Sinus
//Pseudo code float evenness_w=(sin(viewport_pixels_width*screenspace_x*M_PI)+1.0)*0.5; 3. Texture
//Pseudo code bool even_w = lookupFromMyRepeating2x1CheckerTexture(viewport_pixels_width*screenspace_x); All ideas and feedback are welcome!
gl_FragCoordandfract\$\endgroup\$float2 txc = ScreenPosition.xy; if (fmod(txc.x, 2) < 1) { /*even columns*/ } else {} // odd\$\endgroup\$