| Computers Forum Index » Computer - Graphics - API (Opengl) » shader for interlacing textures |
|
Page 1 of 1 |
|
| Author |
Message |
| Guest |
Posted: Fri Apr 22, 2005 3:03 pm |
|
|
|
|
Hi,
I'm trying to write a shader that will interlace two pictures.
I could use stencil but them I would loose half of the resolution.
Here is what the shader is supposed to do:
fragment column 0 = texture0 column 0
fragment column 1 = texture1 column 0
fragment column 2 = texture0 column 1
fragment column 3 = texture0 column 1
Is it possible to do it only with a fragment shader or do I need to
write the vertex as well? I thought about rendering the textures using
quads, twice, in the same place:
glActiveTexture(GL_TEXTURE0);
glBegin(GL_QUADS);
....
glEnd();
glActiveTexture(GL_TEXTURE0);
glBegin(GL_QUADS);
...
glEnd();
And then use the shader:
uniform sampler2D Texture0;
uniform sampler2D Texture1;
uniform int height;
void main(void)
{
int rest = fract(gl_FragCoord.y * 0.5) * 2;
vec4 color;
if (rest)
{
color = texture2D( Texture0, gl_TexCoord[0].st );
}
else
{
color = texture2D( Texture1, gl_TexCoord[1].st );
}
gl_FragColor = color;
}
Am I still loosing the pixels ?
Thanks.
wpr |
|
|
| Back to top |
|
|
|
| Guest |
Posted: Mon Apr 25, 2005 11:02 am |
|
|
|
|
Hi,
I thought about it again and I was wrong. I wrote the following shader
now:
float texel = 1.0 / textureSize;
int x_coord = floor(gl_FragCoord.x / 2 );
vec2 coord = vec2(texel * x_coord, gl_TexCoord[0].t);
glFragColor = texture2D(texture0, coord);
Now it will copy the texture. If the window is too small, it will be
cropped. If it's too big it will repeat in the horizontal.
In the vertical everything stays as it is.
I think now it's right, at least it looks like.
wpr |
|
|
| Back to top |
|
|
|
|