Sign in to follow this  
raytracer03

how to get a sharp 2D in 3D world

Recommended Posts

I am trying to use a 2D sprite in 3D. If I set the sampler state to D3DTEXF_NONE, it's sharp, but after zooming in to twice size, i can see jaggy edges. If I set it to D3DTEXF_LINEAR, the scaling is acceptable, but it's blurred even without scaling. The original picture size, the texture size and the projected size on the window are all the same. How should I config it to get a sharp display with fine scaling? I know that windows xp uses D3D as the renderer to play movies, so there must be some way.

Share this post


Link to post
Share on other sites
You didn't say if you were using ID3DXSprite or if you've developed your own sprite renderer.

The D3DX code should handle it fine, but if you rolled your own then you need to get the texture coordinates correct - see the "Directly Mapping Texels To Pixels" document in the SDK [smile]

hth
Jack

[Edited by - jollyjeffers on April 23, 2006 4:40:39 PM]

Share this post


Link to post
Share on other sites
I'm not using any D3DX code.
I implemented the 2D function according to online samples like this:
http://www.andypike.com/tutorials/directx8/011.asp
And the matrix is right.

From the document you mentioned, do you mean that I should change the
texture coordinate of the triangle strip vertexes?
I can't find any sample of "2D in 3D" considering that.

Share this post


Link to post
Share on other sites
I just had a quick glance through that tutorial...

I'm not sure about this part:
//Set the positions of the vertices
pVertices[0].x = -(m_nWidth) / 2.0f;
pVertices[0].y = -(m_nHeight) / 2.0f;

pVertices[1].x = -(m_nWidth) / 2.0f;
pVertices[1].y = m_nHeight / 2.0f;

pVertices[2].x = (m_nWidth) / 2.0f;
pVertices[2].y = -(m_nHeight) / 2.0f;

pVertices[3].x = (m_nWidth) / 2.0f;
pVertices[3].y = m_nHeight / 2.0f;
Unless the height/width is even then you're going to get it rasterizing to 1/2 pixel locations. Even then I'm not 100% sure whether the exact coordinate going into this vertex will be the exact 2D coordinate coming out post-projection. You can check this fairly easy with a screenshot though.

And this part definitely doesn't follow what I originally posted:
//Set the texture coordinates of the vertices
pVertices[0].u = 0.0f;
pVertices[0].v = 1.0f;

pVertices[1].u = 0.0f;
pVertices[1].v = 0.0f;

pVertices[2].u = 1.0f;
pVertices[2].v = 1.0f;

pVertices[3].u = 1.0f;
pVertices[3].v = 0.0f;
Changing this as per my original post might well yield the results you desire. Read this thread for a bit more discussion...

Cheers,
Jack

Share this post


Link to post
Share on other sites
Good to hear you got it sorted.

Quote:
Original post by raytracer03
MS should put that article in a more obvious place of DXSDK, I think.
[lol] Well its become a bit of a running joke with anyone who answers forums/newsgroups questions on a regular basis. If the DirectX MVP's got a £/$/€ for every time we mentioned that article we'd all be millionaires!!

Cheers,
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this