Jump to content
  • Advertisement
Sign in to follow this  
brekehan

Render in screen coordinates

This topic is 3418 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 am so close. 1) I make a view matrix = real view matrix, but with 0 translation. 2) I get a position in screen coordinates, from a 3D position, with D3DXVec3Project. 3) I set the view matrix to identity 4) I create a 2D ortho matrix using
D3DXMatrixOrthoOffCenterLH(&projection,
                              0.0f,
                              static_cast<float>(viewport.Width),
                              0.0f,
                              static_cast<float>(viewport.Height),
                              0.0f,
                              1.0f);


And I get an image that is billboarded in 2D screen coordinates. Almost.... It stays where it should as I turn left to right, but when I rotate the camera up it also move up. When I rotate the camera down, it also moves down. I know my problem is the projection top and bottom are opposites! However, if I switch the top and bottom params, the image no longer gets rendered. I have a feeling this turns the quads inside out, and somehow DirectX now believes my triangles to be drawn counter clockwise instead of clockwise???
I can see in pix that
-------
|\    |
| \   |
|  \  |
|   \ |
-------

became

-------
|    /|
|   / |
|  /  |
| /   |
-------


Is that to be expected? Do I need to change a state in the shader to handle this problem when trying to draw using screen coordinates? What state handles that? What do I set it to?

Share this post


Link to post
Share on other sites
Advertisement
Your current projection matrix has (0, height) in the top left corner and (width, 0) in the bottom right - so +Y is down the way. You should swap the parameters as you said.

As for why it's no longer rendering; your triangles must be specified in counter-clockwise order - which is the default back-facing setting. You want to make sure that all of your vertices are specified in clockwise order.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Your current projection matrix has (0, height) in the top left corner and (width, 0) in the bottom right - so +Y is down the way. You should swap the parameters as you said.

As for why it's no longer rendering; your triangles must be specified in counter-clockwise order - which is the default back-facing setting. You want to make sure that all of your vertices are specified in clockwise order.


That's just it.
I would expect them to have to be specified in clockwise order, but it didn't render. When I specified them in counter-clockwise order it did.

This results in the image showing up:
It has counter clockwise vertices!

queryPositions.push_back(Position( -m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( -m_querySize / 2.0f, m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( m_querySize / 2.0f, m_querySize / 2.0f, 0.0f));

// SNIP...

D3DXMatrixOrthoOffCenterLH(&newProjection,
0.0f,
static_cast<float>(viewport.Width),
static_cast<float>(viewport.Height),
0.0f,
0.0f,
1.0f);





This results in the image _not_ showing up:
It has clockwise vertices!

queryPositions.push_back(Position( -m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( -m_querySize / 2.0f, m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( m_querySize / 2.0f, -m_querySize / 2.0f, 0.0f));
queryPositions.push_back(Position( m_querySize / 2.0f, m_querySize / 2.0f, 0.0f));

// SNIP...

D3DXMatrixOrthoOffCenterLH(&newProjection,
0.0f,
static_cast<float>(viewport.Width),
static_cast<float>(viewport.Height),
0.0f,
0.0f,
1.0f);





The first way works, which makes me happy. I even think I understand why. It just goes against everyone's advise :/

So, I am now believing that backface culling occurs after the shaders, and that the projection matrix into screen space reverses the order of vertices in my vertex shader, because it effectivly rotated the quad 180 degrees about the x axis.

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!