Sign in to follow this  
iota1410

using transformed data

Recommended Posts

I need to use data that I receive which comes in in screen space (i.e. x=100, y=150 not x = -1.0, y = 2.0). But I want to use it in the following format so that it works with my vertex shader. Since this data is already tranformed int screen space, how can I get it to work. struct CUSTOMVERTEX { FLOAT x, y, z; // The transformed, 3D position for the vertex }; #define VERTEX (D3DFVF_XYZ) D3DFVF_XYZRHW does not work due to the need of my vertex shader. D3DDECLUSAGE_POSITIONT does not allow multiple streams, which I need for my application. Using the data as is, it does not show up on the screen. Please help. [Edited by - iota1410 on November 11, 2004 10:05:09 AM]

Share this post


Link to post
Share on other sites
In the shader it is your responsibility to transform the data. If it is already in screen space simply don't transform it, that is don't multiply it by the projection and view mats.

Share this post


Link to post
Share on other sites
Sorry, I was a little unclear. I didn't mean it is projected, rather the viewport transform is applied. You can find all the information in the SDK, under Viewports and Clipping I believe.

Share this post


Link to post
Share on other sites
I am folloing the sample you suggested and i receive an error:
Direct3D9: (ERROR) :Viewport outside the render target surface

I use the following code:


D3DVIEWPORT9 viewData = { 0, 0, 640, 480, 0.0f, 1.0f };
HRESULT hr;
hr = g_pd3dDevice->SetViewport(&viewData);
if(FAILED(hr))
return hr;

What am I missing? I call this during my init calls.


[Edited by - iota1410 on November 11, 2004 7:17:26 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by turnpast
In the shader it is your responsibility to transform the data. If it is already in screen space simply don't transform it, that is don't multiply it by the projection and view mats.


I followed your advice, but with no result. My shader basically just passes the information through, yet still nothing shows up on the screen.

[Edited by - iota1410 on November 11, 2004 10:45:29 AM]

Share this post


Link to post
Share on other sites
Any help here would be greatly appreciated. If I am asking wrong, or what I want is not possable, please let me know. Im theory what I ask seems very simple. I just want to be able to present my data to the screen. I receive my data in screen space coordinates. I do not want to use the XYZRHW format due to shader limitations, so how can I present the picture.

If any code snippets will help please let me know.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think you must tranform your coordinates to the zone (-1, -1)-(1,1) and not output them in the rect (0,0)-(640,480).

Share this post


Link to post
Share on other sites
You multiply by the inverse view transform, since D3D will multiply by the view transform to get into screen space (as you are note using pre transformed geometry).

Essentially you want to do

cx = (x - a)/b

Where
cx = coord in clip space, x = coord in screen space
a = sViewport.X + sViewport.Width / 2.0f
and b = sViewport.Width / 2.0f

This assumes, of course, that w = 1.

(Note: Taken from the Viewport Scaling page in the D3D SDK)

Share this post


Link to post
Share on other sites
Thanks for the help, That was where I was headed. My only question for now, How do I determine viewport.x. I do not make a call to create a viewport. I tried to create one, but could not make it work. Do I have to create one, and if so then why did the code I posted previously not work. It was taken directly from the SDK.

Share this post


Link to post
Share on other sites
Check SDK if you're interested what this function does

D3DXMatrixOrthoOffCenterLH(&D3DXMATRIX_outmatrix,
0.0f, 640.0f, // x
0.0f, 480.0f // y
0.0f, 1.0f // z
);

Use this as projection matrix, use identity to world and view.

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