DirectX SDK

Transformed and Lit Vertices

If you include the D3DFVF_XYZRHW flag in your vertex format description, you are telling the system that your application is using transformed and lit vertices. This means that Direct3D doesn't transform your vertices with the world, view, or projection matrices, nor does it perform any lighting calculations; it assumes that your application has already taken care of these steps. (This fact makes transformed and lit vertices common when porting existing 3-D applications to Direct3D Immediate Mode.) In short, Direct3D does not modify transformed and lit vertices at all; it passes them directly to the driver to be rasterized.

The vertex format flags associated with untransformed vertices and lighting (D3DFVF_XYZ and D3DFVF_NORMAL) are not allowed if D3DFVF_XYZRHW is present. For more about flag dependencies and exclusions, see Flexible Vertex Format Flags.

The system requires that the vertex position you specify be already transformed. The x and y values must be in screen coordinates, and z must be the depth value of the pixel to be used in the z-buffer. Z values can range from 0.0 to 1.0, where 0.0 is the closest possible position to the viewer, and 1.0 is the farthest position still visible within the viewing area. Immediately following the position, transformed and lit vertices must include an RHW value (reciprocal of homogeneous W) value. RHW is the reciprocal of the W coordinate from the homogeneous point (x,y,z,w) at which the vertex exists in projection space. (This value often works out to be the distance from the eyepoint to the vertex, taken along the z-axis.)

Other than the position and RHW requirements, this vertex format is similar to an untransformed and lit vertex. To recap:

[C++]

Applications written in C++ can still use the legacy D3DTLVERTEX structure for transformed and lit vertices. The d3dtypes.h header file defines the following helper macro that you can use to describe the vertex format declared by the D3DTLVERTEX structure:

#define D3DFVF_TLVERTEX ( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | \
  D3DFVF_TEX1 ) 

It's possible that the D3DTLVERTEX structure doesn't include the fields you need. If this is the case, define another structure that does, but make sure that the vertex components are ordered properly. The following code declares a valid transformed and lit vertex, with diffuse and specular vertex colors, and one set of texture coordinates:

//
// The vertex format description for this vertex 
// would be: (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | 
//    D3DFVF_SPECULAR | D3DFVF_TEX1)
//
typedef struct _TRANSLITVERTEX {
    float x, y;   // screen position
    
    float z;      // Z-buffer depth
    
    float rhw;    // reciprocal homogeneous W
    
    DWORD dwDiffuseRGBA;  // diffuse color
    
    DWORD dwSpecularRGBA; // specular color
    
    float tu1,    // texture coordinates
  tv1;
} TRANSLITVERTEX, *LPTRANSLITVERTEX; 

The vertex description for the preceding structure would be a combination of the D3DFVF_XYZRHW, D3DFVF_DIFFUSE, D3DFVF_SPECULAR, and D3DFVF_TEX1 flexible vertex format flags. The rendering methods, such as IDirect3DDevice7::DrawPrimitive, accept the address of a vertex array as a void pointer, so remember to cast your vertex array pointer to the LPVOID data type when you call the rendering methods.

For more information, see About Vertex Formats.

[Visual Basic]

Visual Vasic applications can use the D3DTLVERTEX type for transformed and lit vertices. It's possible that the D3DTLVERTEX type doesn't include the fields you need. If this is the case, define another type that does, but make sure that the vertex components are ordered properly. The following code declares a valid transformed and lit vertex, with diffuse and specular vertex colors, and one set of texture coordinates:

'
' The vertex format description for this vertex
' would be: (D3DFVF_XYZRHW Or D3DFVF_DIFFUSE Or
'    D3DFVF_SPECULAR Or D3DFVF_TEX1)
'
Type TRANSLITVERTEX
    x As Single ' screen position
    y As Single
    
    z As Single ' Z-buffer depth
    
    rhw As Single ' reciprocal homogeneous W
    
    DiffuseRGBA As Long ' diffuse color
    
    dwSpecularRGBA As Long ' specular color
    
    tu1 As Single ' texture coordinates
    tv1 As Single
End Type

The vertex description for the preceding type would be a combination of the D3DFVF_XYZRHW, D3DFVF_DIFFUSE, D3DFVF_SPECULAR, and D3DFVF_TEX1 flexible vertex format flags. The rendering methods, such as Direct3DDevice7.DrawPrimitive, accept the first element of a vertex array as type Any, to accommodate all types of vertex formats.

For more information, see About Vertex Formats.