• Advertisement
Sign in to follow this  

pixel / texel offset ?

This topic is 4402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement