Archived

This topic is now archived and is closed to further replies.

supagu

D3DFVF_XYZRHW

Recommended Posts

im trying to draw 2d hud elements using D3DFVF_XYZRHW apparently i dont the points i generate are actuall screen coordinated. the sdk says my vertex should be like this: FLOAT x, y, z, rhw; what is the rhw? what should it be set to, and is x=0, y=0 the top left of the screen, and what value is the bottom right of the screen? thanks.

Share this post


Link to post
Share on other sites
The bottom right of the screen will be your resolutions width -1, and your resolutions height -1. Remember you start with (0,0) not (1,1).

For example, in 800x600 the bottom right will be (799, 599).

RHW stands for Reciprocal of Homogeneous W.

Hope that helps,


Michael Bartman
CEO, Lead Programmer
Dark Omen Studios
http://www.darkomenstudios.com/

Share this post


Link to post
Share on other sites
okay, ive done some experimentation, and i cant get them to show up, is there anything special i must do?

i tryed turning off the z buffer, and culling but i only get some thin little strip down the side of the screen :-/

Share this post


Link to post
Share on other sites
rhw is set to 1. If you''ve set it to 0 then it shouldn''t show up, so that''s proabably your problem. I know that doesn''t help all that much with understanding. There''s an NVidia OpenGL sample somewhere on their site that demonstrates its effect.

Good Luck

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Set RHW to 1. Basically, all the other values (x,y,z) will be multiplied by the RHW in the transform (if you send it through the regular pipe).

What coordinates the screen are depends on your projection matrix. In most computer graphics, y=0 means BOTTOM, and y=positive means UP. Thus, the bottom-left corner is 0,0.

If your projection matrix is entirely vanilla, it may be that the lower-left corner is 0,0, and the upper-right corner is 1,1, and the Z range is 0 through 1.

Share this post


Link to post
Share on other sites
quote:
What coordinates the screen are depends on your projection matrix.

When you use D3DFVF_XYZRHW, the vertices bypass all transformation and lighting, so the projection matrix will have no effect. Basically you''re specifying back buffer pixel coordinates directly (assuming RHW is 1).

Share this post


Link to post
Share on other sites
quote:
so the projection matrix will have no effect


Apart from if the XYZRHW vertices you feed to D3D require clipping and the device doesn''t expose the D3DPMISCCAPS_CLIPTLVERTS cap.

AFAIK, in those cases, any XYZRHW vertices that fall beyond any available guardband area can potentially turn to mush if the projection matrix is screwy.

To clip XYZRHWs that fall past the guard band, D3D needs to unproject back into 3D space (using the info in the current projection matrix!) to perform the clipping, then reproject afterward. Since XYZRHW vertices are most commonly used for sprites, it''s often a good idea to clip primitives using them manually and set D3DRS_CLIPPING to FALSE to avoid any back projection.


supagu:

Remember that the Z value you use in your sprite vertices will determine what gets written to the Z buffer so try setting it to a low value. Also make sure that the Z value is lower than anything else rendered, that you''ve remembered to Clear() the depth buffer, that the depth buffer is enabled etc

--
Simon O''Connor
ex -Creative Asylum
Programmer &
Microsoft MVP

Share this post


Link to post
Share on other sites
the w component is the way the D3D differentiates between the vertex and the vector.for a vertex the w component should be 1,for a vector between two vertices the w component is subtracted from the other w component of the other vertex so the w component of the vector is 0.the rendering of a vector of w=0 in the clip space would be semi infinite i.e. the vertices are extended to infinity.

Share this post


Link to post
Share on other sites
Let me correct myself. The x and y values specify back buffer coordinates and z is the depth value [0..1] -- *regardless* of RHW. I was thinking they are in homogeneous space but they''re not.

RHW is essential for getting perspective-correct interpolation when the vertices have been pre-transformed from 3D space.

And it''s needed for back-transformation when clipping, as Simon describes. (But actually I believe only the viewport transform is used, assuming the clipping is performed in, well, clip space. This is how the docs describe it anyway.)

Share this post


Link to post
Share on other sites