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);
So color
and 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.
int (myFloat)
rounds to zero, why notpixelCoordinate = int(normalizedCoordinate * 2048)
? $\endgroup$color
will output the color of the pixel without any interpolation... $\endgroup$normalizedCoordinate.x
is 1, the output would be 2048, which is outside [0 2047] $\endgroup$clamp
should solve the issue. $\endgroup$