How to define an even / odd texture string in GLSL ES

I need to remove all the odd lines from the texture - this is part of a simple deinterlacer.

In the following code example, instead of getting RGB from the texture, I select the output for white for an odd line and red for an even line - so I can visually check if the result is what I expected.

_texcoord is passed from the vertex shader and has a range of [0, 1] for x and y

uniform sampler2D sampler0; /* not used here because we directly output White or Red color */
varying highp vec2 _texcoord;
void main() {
    highp float height = 480.0; /* assume texture has height of 480 */
    highp float y = height * _texcoord.y;
    if (mod(y, 2.0) >= 1.0) {
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); 
    } else {
        gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0); 
    }
}

When displayed on the screen, output is not expected. Vertically this is RRWWWRRWWW But I really expect RWRWRWRW (i.e. alternates between red and white)

My code runs on iOS and targets GLES 2.0, so it shouldn't be different on Android with GLES 2.0

Question: Where did I go wrong?

EDIT

  • Yes, the texture height is correct.
  • , : _texcoord.y, , .
+4
1
void main(void)
{
    vec2 p= vec2(floor(gl_FragCoord.x), floor(gl_FragCoord.y));
    if (mod(p.y, 2.0)==0.0)
        gl_FragColor = vec4(texture2D(tex,uv).xyz ,1.0);
    else
        gl_FragColor = vec4(0.0,0.0,0.0 ,1.0);
}
+4

All Articles