0,0 in UV space maps to the lower left corner of the lower
left texel, assuming you're loading a lower scanline first bitmap (it's
the upper left corner of the upper left texel if you're loading an upper
scanline first bitmap manually without conversion).
The center of the lower-left texel is at 0.5/Wt, 0.5/Ht,
where Wt is texture width, and Ht is texture height, for the texture MIP
level that you're sampling from. This means that different MIP levels need
different amounts of bias to find the center of a texel.
0,0 in homogenous screen space maps to the center of the
centermost pixel in Direct3D9. When the width of the render target is
even, I don't know which particular pixel it chooses.A corner of a pixel, which
should coincide with a U/V of 0,0, is at a multiple of N where X,Y is
(2N+1)/Ws,(2N+1)/Hs, where Ws is width of screen in pixels, and Hs is
height of screen in pixels. Note that, because of the "0,0 is a pixel
center" rule, you don't hit 1.0 perfectly at the edges of the homogenous
space. Here, I think OpenGL is better, in that it maps 0,0 to the
intersection betwen the four center pixels, so it's analogous to
texturing.
The fact that 0,0 is in the center of a pixel comes from
how the viewport transform goes after the projective divide, and the
requirement that pixel centers are at integer coordinates (in viewport
coordinates). Unfortunately, there is no "Direct3D Specification" similar
to the OpenGL specification, so you have to figure this out the hard way,
by reading the available documentation and drawing conclusions.
Finally, rasterization of a pixel happens when the center
of that pixel falls within the rasterized triangle, or exactly on the
upper or leftmost edges of that triangle. I believe that a "topmost" edge
that slants dowards to the right does not count as "upper", because the
dual edge on a connecting triangle would count that as "leftmost" -- but,
again, there's no firm spec accessible to people without the REF source
code.
I have found these rules to largely be followed by modern
drivers for modern hardware. The main exception are some ATI graphics
cards, which have a control panel option for "alternate texel center,"
which would screw up these rules when enabled. By default, this checkbox
is not enabled, and the rasterization follows these above rules.
In general, to map a one texel texture to one pixel, you
want to plug U/V of 0,0 through 1,1 into the quad texture coordinates,
and plug screen coordinates of -1/Ws,-1/Hs and 1/Ws,1/Hs into the quad
position coordinates.
I hope this helps, and if I've drawn an erroneous
conclusion somewhere, I'd like to be informed of it. However, following
the above rules in Direct3D has always given me 1:1 texel/pixel
alignment, so I'm of the belief that the above is correct.
|