PDA

View Full Version : Deinterlace from one texture to another using GLS



Lathoub
12-20-2010, 10:58 PM
Hi

[Context: application with PAL video output]

I rendered a full frame of graphics (720 x 576), but the video output
card expects fields (720 x 288).
So i need to deinterlace it first from the full frame texture to the
half size texture, alternating the odd and the even rows.

The full frameis loaded in texture0; i have another texture ready at
half the size.

GLEW_OML_interlace would have been a perfect solution to deinterlace
using glReadPixels, but that is no longer implemented by modern cards
:-( So i guess using GLSL shader is a good option. The shader will be
executed when i draw the full frame to the screen.

I'm new to shaders but I think the vertex shader is not relevant (?)
for deinterlacing, as i'm moving fragments.
According to the documentation i can only set color information in the
fragment shader, not the position.
I looked at gl_FragCoord, but that is read only; i cant set it.

Question: what is the best way to implement what i need to accomplish?

pseudo code (eg for odd field):

if (mod(gl_FragCoord.y, 2.0)) // or use texcoord0.y ?
{
fieldRow = row / 2;
gl_FragColor of field texture = gl_FragColor of frame texture
}

So:
Line 0, not copied
Line 1 of texture0, copied to line 0 in texture1 Line 2, not copied
Line 3 of texture0, copied to line 1 in texture1 Line 4, not copied
Line 5 of texture0, copied to line 2 in texture1 Line 6, not copied
Line 7 of texture0, copied to line 3 in texture1 Line 8, not copied
...

Thanks
Bart