lion0406 / angleproject

Automatically exported from code.google.com/p/angleproject
Other
0 stars 0 forks source link

Incorrect translation of GLSL function texture2D. #333

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

When working with WebGL (Chrome, Windows), was seen the following error:

When accessing the pixel with the number N (texture 2D, NEAREST, without 
FLIP_Y), we must apply to the indices
float x = floor (N / width); / / width - texture width in pixels
float y = mod (N, width);

vec4 color = texture2D (sampler_2d, vec2 (1./width * x, 1./height * y)); / / we 
expect to get the desired pixel

but due to the fact that texture2D translates to:

float4 gl_texture2D (sampler2D s, float2 t)
{
   return tex2Dlod (s, float4 (t.x, 1 - t.y, 0, 0));
}

When accessing the pixel [0, 1](or any other) we obtain tex2Dlod (s, float4 (0. 
1. - 1. * (1 / height)), 0, 0) -> which corresponds to a pixel [0, 0]
, Ie. to obtain the desired pixel, we must address, for example, [0, 1.0000001].

Of course, when using native GL, all references are correct,  and the addition 
of 0.00001 is not needed.

Original issue reported on code.google.com by vantuzi...@gmail.com on 30 May 2012 at 10:40

GoogleCodeExporter commented 9 years ago
Sampling at (x / width, y / height) is a location right in between texels, and 
there are no strong guarantees which texel will be retrieved. You should sample 
at texel centers instead, by adding (0.5 / width, 0.5 / height) to the texture 
coordinates.

Original comment by nicolas....@gmail.com on 31 May 2012 at 9:01