I've a texture (2048 x 2048) Pixels. I am looking for an algorithm to transform the normalized texture coordinate [0 1] to pixel coordinate [0 2047]. This should be a perfect fit...
So when the texture sampler has a GL_NEAREST interpolation the following code should output the same:
ivec2 texSize = textureSize(tex); vec2 normalizedCoordinate = someValue; ivec2 pixelCoordinate = AlgorithmIamLookingFor; vec4 color = texture(tex, normalizedCoordinate); vec4 color2 = texelFetch(tex, pixelCoordinate, 0);
color2 should have the same value.
I've tried the following:
pixelCoordinate.x = int(normalizedCoordinate * 2047)
But the last pixel (2047) will not show up or be extremely small.