I'm trying to convert a shader wich is written using GLSL version 120 into OpenGl ES 2.0 and I came to a problem on how to map this shader correctly.
On the original shader, I'm using texture2DRect and this is not supported on OpenGL ES ( at least not on the target hardware I'm aming for).
The shader has two textures. One is a texture mapped to a quad, the other one is simply a kind of lookup I use to multiply the texel. The lookup is a 128x128 bitmap.
The original shader looks like this:
float xx = mod(gl_FragCoord.x, 5.0);
float yy = mod(gl_FragCoord.y, 15.0);
vec4 color = texture2DRect(tex0, coord0);
vec4 lookup1 = texture2DRect(tex1, vec2(xx, yy));
gl_FragColor = color * lookup1;
I've changed it to:
float xx = mod(gl_FragCoord.x, 5.0) * (1.0/textsize.x);
float yy = mod(gl_FragCoord.y, 15.0) * (1.0/textsize.y);
vec4 color = texture2D(tex0, coord0);
vec4 lookup1 = texture2D(tex1, vec2(xx, yy));
gl_FragColor = color * lookup1;
Where textsize is a vec2 containing the lookup texture size (128x128) I need the exact value of the texel at let's say 50,127 on the lookup. I imagined that this should be (50/128, 127/128). This is however not working as I've expected. What am I missing here?
Additional Information:
Texture parameters:
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE)
Texture declarations:
uniform samplerExternalOES tex0;
uniform sampler2D tex1;
update 2013.03.13:
I've implemented now the following function:
vec4 texelFetch(sampler2D texsampler, vec2 coord) {
vec2 mult=(2.0*coord + 1.0)/(2.0* texWidth); // 128.0
vec4 texel = texture2D(texsampler,mult);
return texel;
}
And changed the code to:
float xx = mod(gl_FragCoord.x, 5.0);
float yy = mod(gl_FragCoord.y, 15.0);
vec4 lookup1 = texelFetch(tex1, vec2(xx, yy));
Still, it does not seems to be working.