I have asked a similar questions earlier this year and got it working somehow. But obviously, I didn´t (and still do not) understand what I was doing. First, what am I trying to do: calculating the average scene-luminance by downscaling a texture down to 1x1 while applying a box-filter. This is done using two pbuffers in a ping-pong manner, i.e. render full texture A to quarter texture B, then render quarter texture B to 1/16 texture A until I render just one pixel, then containing the average luminance of the scene. I´m trying to exploit the bilinear filter, so averaging 4 neighboured texels is just using 1 texture lookup.
What I obviously don´t get right is how to exactly match rendered pixels with texels fetched.
Lets assume, we are in the last step of the process, we want to average the lower left 4 pixels of texture A to the lower left pixel/texel of texture B.
I was trying to achieve this using these coordinates:
glTexCoord2d(xtexel, ytexel); glVertex2d(0, 0); glTexCoord2d(xtexel, ytexel); glVertex2d(1.0/256.0, 0); glTexCoord2d(xtexel, ytexel); glVertex2d(1.0/256.0, 1.0/256.0); glTexCoord2d(xtexel, ytexel); glVertex2d(0, 1.0/256.0);
xtexel and ytexel are 1.0/texturewidth and 1.0/textureheight. The destination coordinate
The projection matrix was setup with this call:
The texture sampling should occur central between the 4 lower left texels of the source texture (at the top right corner of the lower left texel), the rendered quad should only consist of 1 pixel.
The problem is, it doesn´t work right.
There´s a document “Mapping texels to pixels in D3D”, but I didn´t find a similar one for GL.
So, how is it done the right way in GL?
thx in advance