pixel / texel offset ?

Started by
0 comments, last by Soiled 18 years, 3 months ago
I posted this question in the DirectX thread but no one responded, maybe someone here could help. If you’ve already seen the other post then I apologize for the repost. Now, back to the question. My understanding is that to align texels with pixels precisely, the geometry must be offset by half a pixel. This is because the position is actually the center of the pixel. In my case I am trying to render a screen aligned quad using a vertex shader that does not transform the verticies. The question is, if I render a full screen quad (-1,1) (1,-1) must I offset these by half a pixel? If they must be offset is this the correct formula for the offset value? Size offset = Size(0.5, 0.5) / renderTarget.Size(); Finally, should the offset be subtracted from the upper left and added to the lower right?
Advertisement
The 'pixel_offset' is actually (-1.0f/viewportWidth, 1.0f/viewportHeight) for Direct3D.
Direct3D's viewport transform is (x',y') = (X + viewportWidth/2 + (x/w) * viewportWidth/2, Y + viewportHeight/2 - (y/w) * viewportHeight/2) where (X,Y) is pixel coordinate of upper-left of viewport and (x/w,y/w) is the post-transformed vertex position - which is (-1,1),(1,-1) for fullscreen quad as you mentioned.
Replacing (x/w,y/w) with ((x/w)+pixel_offset,(y/w)+pixel_offset) in the viewport transform gives (x' - 0.5, y' - 0.5) which is what Direct3D specifies on its "Directly Mapping Texels to Pixels" page in the docs.

Also I do what's described on this site as a general framework so I never have to worry about it again... http://www.sjbrown.co.uk/?article=directx_texels

This topic is closed to new replies.

Advertisement