Sign in to follow this  
conciliator

Working directly in projection space?

Recommended Posts

First of all, I'm really new to DX10D3, so please bare with me. Background: in order to learn this neat API, I was thinking about writing some 3D GUI that I later could incorporate into minor game projects. Question: can I skip the world and/or view transformations, and take my objects straight to projection space? After all, I shouldn't need to place GUI elements in the world, as they are not part of it. Does this make sense? Could anyone point me in the right direction regarding skipping the world and view transformations? I've been playing with the MS D3D10 tutorial 4 (3D spaces), turning off the world and view transform in the vertex shader in tutorial04.fx. This, however, turns out pretty disappointing... (Blank screen). What am I missing? Thanks! :)

Share this post


Link to post
Share on other sites
as a fast solution, you could use an identity-matrix as world-view-matrix, so you can define positions in normalized device coordinates which ranges only from (-1,-1,0) to (1, 1, 1) - so your passed coordinates must be within this range.

to be honest i doubt that this is the best way to do a 3D GUI but i also dont know anything better - never tried anything like that yet

Share this post


Link to post
Share on other sites
Since you're using shaders, it's not a problem to write a shader that doesn't transform, but simply passes the coordinates as is. As mancubit said, remember that you need to output X and Y in the -1 to 1 range to make them visible. If you want something else, you can transform from any space you want to this space in your shader.

Share this post


Link to post
Share on other sites
Thanks for the quick reply, guys.

BTW: ET3D; you say "since you're using shaders...". I just started to read the documentation, but thus far have been under the impression that one had to use vertex shaders specified in HLSL to render. Are there other ways to render than using HLSL?

Share this post


Link to post
Share on other sites
Your on the right track, but dont even think in terms of 'projection', thats is just another martix.

Is the pixel shaders, the points on the screen are normalized to -1 through 1 (both x & y). So If you submit a point at 0,0, it's the center pixel, at 1,1 I think thats bottom right.

If you want to have elements that are 3D, you will probably need to have a projection matrix. It would be immposible to have a 3D object that all the verticeis fall within the -1 to 1 range and everything looks right.

However, to give you something to chew on. I've designed a shader function to render 'FLAT' images onto the screen. Specifically for doing GUI stuff. I will post the function below but to explain it. All I'm doing is submitting points at are defined in screen space, 0,0 is the upper left then it goes all the way to the screen resolution, say 800x600. So a point at 400,300 would be at the center. But this is only because of how the function nomalizes the coordinate. Take a look below.

_____________________

vOut_InFlat VS_FLAT(vIn_InFlat input)
{

vOut_InFlat result = (vOut_InFlat)0;

float4 vector4_position = float4(input.vPosition, 1.0f);
float4 vWorldPos = mul(vector4_position, M_Matrix1);

result.vPosition.x = (vWorldPos.x / ( ScreenX / 2.0)) -1;
result.vPosition.y = -(vWorldPos.y / ( ScreenY / 2.0)) + 1;
result.vPosition.z = input.vPosition.z;
result.vPosition.w = vWorldPos.w;

result.vTCoords = input.vTCoords;

return result;

}
_____________________________________

You can see the function also sets the z position, but this is only for occlusion of stuff behine it.

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