I need to remove all odd lines from a texture - this is part of a simple deinterlacer.
In the following code sample, instead of getting the RGB from texture, I choose to output white colour for odd line and red colour for even line - so I can visually check if the result is what I expected.
_texcoord is passed in from vertex shader and has a range of [0, 1] for both 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 render to screen, the output isn't expected. Vertically it's RRWWWRRWWW But I am really expecting RWRWRWRW (i.e. alternate between red and white color)
My code run on iOS and target to GLES 2.0 so it should be no different on Android with GLES 2.0
Question: Where did I do wrong?
EDIT
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With