Jump to content
  • Advertisement
Sign in to follow this  
Eric F.

DirectX 11 and shifting vertices by a half-pixel in 2D rendering.

This topic is 1012 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

Hey all.

 

I read in the MS article about differences between DX 9 and 10/11 that you dont need to add half a pixel when placing your polygons now. I was glad to see this gone, but I am having a super hard time aligning everything properly.

 

For some background, here is how I define the world, view and projection matrices: (Pardon my use of Delphi ;) )

  D3DXMatrixIdentity( World );
  D3DXMatrixLookAtLH( View, D3DXVector3.Create(0, 0, -10), D3DXVector3.Create(0, 0, 0), D3DXVector3.Create(0, 1, 0) );
  D3DXMatrixOrthoOffCenterLH( Projection, 0, DisplaySize.Width, DisplaySize.Height, 0, 1, 100 ); // updated when display size changes.

.

All other objects are setup so that I can draw lines using line lists, draw images using quads, etc. Everything works, except that I seem to have some alignment problem.

 

My problem is as follow. Say for a viewport of 640 x 480 pixels, I need to provide the vertices coordinates 1-based instead of 0-based. As such, if I want to draw a quad that fills the whole viewport, I need to set it from 1, 1 to 640, 480 instead of 0, 0 to 639, 479.

 

Am I doing something wrong? Do I really have to subtract 1 from every vector I pass to the API?

 

I dont want to start fiddling with the projection and move it or kludge my renderer with code that might/can/will break on some platform combo.

 

I could post more code, but I'm not sure what's relevant and after working on this for five+ days, the mapping of the buffer and vertices assignment is pretty straightforward. And I use generic shaders that do not perform any extra processing, based off the Rastertek tutorials.

 

Any suggestions?

 

Thanks!

Edited by e.fortier

Share this post


Link to post
Share on other sites
Advertisement

My problem is as follow. Say for a viewport of 640 x 480 pixels, I need to provide the vertices coordinates 1-based instead of 0-based. As such, if I want to draw a quad that fills the whole viewport, I need to set it from 1, 1 to 640, 480 instead of 0, 0 to 639, 479.


I'm not sure that I understand the requirement to use 1-based coordinates.  It seems that you may be needlessly making things complicated for yourself.

 

Using 0-based coordinates you provide them in e.g the {0,0} to {640,480} range and everything works.

Share this post


Link to post
Share on other sites

I'm not sure where you are getting those numbers from. A (0, 0) to (639, 479) quad cannot possibly fill a (640, 480) viewport - that would be like a (0, 0) to (0, 0) quad filling a (1, 1) viewport. I'm also not sure why you're trying to add one when the offset specifically mentions half pixel.

In DirectX9 your quad was (-0.5, -0.5) to (639.5, 479.5), while in DirectX11 it's (0, 0) to (640, 480). Unless you were dealing with the half-pixel offset in your shaders, in which case you only have to edit your shaders

Edited by Mona2000

Share this post


Link to post
Share on other sites

After reading the replies, I went back to my code and had a good look over, taking what you guys said. Turns out, I didn't follow proper rasterization rules which was causing all manner of problems in my code.

 

This bit from MSDN might help someone having the same problem:

 

"Non-antialiased line rendering rules are exactly the same as those for GDI lines."

https://msdn.microsoft.com/en-us/library/windows/desktop/dd145027(v=vs.85).aspx

 

Thanks!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!