Skip to main content
gamedev.net
🔒 Locked

using transformed data

Started by iota1410 Nov 10, 2004 at 2:42 PM 16 replies 1.6k views
Original Post
iota1410
iota1410
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]
turnpast
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.
DBX
DBX
You'd have to transform the coords into homogenous clip space since that's what the shader outputs. The projection is applied after the vertex shader.
iota1410
iota1410
How would I transform the coords into homogenous clip space?
DBX
DBX
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.
iota1410
iota1410
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]
iota1410
iota1410
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]
iota1410
iota1410
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.
iota1410
iota1410
How can I convert from screen coordinates to untransformed coordinates? (640,480) = (1,-1)
or am I looking at this complety wrong.

[Edited by - iota1410 on November 11, 2004 2:20:50 PM]
DBX
DBX
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)
DBX
DBX
When I say view transform, I meant viewport, but you know what I mean.
I would edit, but I'm denied access apparantly.
iota1410
iota1410
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.
Codarki
Codarki
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.
DBX
DBX
Use GetViewport to retrieve the viewport from the device.
iota1410
iota1410
I used D3DXMatrixOrthoOffCenterLH and that worked. Now I just need to turn Y axis upside down? I am trying to adjust view matrix, but I am having difficulty
Codarki
Codarki
flip the min and max y parameters in that function
iota1410
iota1410
It is amazing how we overlook the obvious answer. Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.