Shadder and Effect - Declaration of 2.1 Vertex

zhaozj2021-02-16  51

2.1 Vertical Declaration

Read this article shows that you have agreed to the statement

To now, we have used the free vertex format (FLEXible Vertex Format, FVF) to describe the various components in the vertex structure. However, in the programmable line, our vertex data can contain many more data that can be expressed by FVF. Therefore, we usually use more expressive and stronger vertex statements (Vertex Declaration).

Note: We can still use FVF in the programmable pipeline - if our vertex format can be described. Anyway, this is just for convenience, because FVF will be converted to a vertex declaration internally.

2.1.1 Description Vertical Declaration

We describe a vertex statement as an array of D3dvertExElement9 structures. Each element in the D3DvertExElement9 array describes a vertex component. So if your vertex structure has three components (for example: position, normal, color), then its corresponding vertex declaration will be described by a D3DvertExElement9 structure array. This D3DVERTEXEEMENT9 structure is defined as follows:

Typedef struct _d3dvertexelement9 {

BYTE stream;

BYTE OFFSET;

BYTE TYPE;

BYTE METHOD;

BYTE USAGE;

Byte usageIndex;

} D3DVERTEXELEMENT9;

n stream - Specify the stream of association to vertex

n Offset - Offset, start with the start of the vertex component relative to the vertex structure member. For example, if the vertex structure is:

Struct Vertex

{

D3DXVECTOR3 POS;

D3DXVECTOR3 NORMAL;

}

... The offset of the POS component is 0 because it is the first component; the offset of the NORMAL component is 12 because SizeOf (POS) == 12. In other words, Normal components start with Vertex's 12th byte.

n Type - Specifies the data type. It can be any member of the D3DDeclType enumeration type; a full list See the documentation. The common type is as follows:

l D3DDECLTYPE_FLOAT1 - Floating point value

l D3DDECLTYPE_FLOAT2 - 2D floating point vector

l D3DDECLTYPE_FLOAT3 - 3D floating point vector

l D3DDECLTYPE_FLOAT4 - 4D floating point vector

l D3DDECLTYPE_D3DCOLOR-D3DCOLOR type, it extends to RGBA floating point color vectors (R g B A), each component is normalized to interval [0, 1].

n method - Specify a grid method. We think this parameter is advanced, so we use the default value to identify D3DDECLMethod_Default ..

n usage - Specifies the use of the scheduled to the vertex component. For example, is it ready for a location vector, normal vector, texture coordinate, etc. Effective Use Identifier is the type of D3DDECLUSAGE:

Typedef enum _d3ddeclusage {

D3DDECLUSAGE_POSITION = 0, // position.

D3DDECLUSAGE_BLENDWEIGHTS = 1, // Blending Weights.

D3DDECLUSAGE_BLENDINDINDICES = 2, // blending indes.d3ddeclusage_normal = 3, //

Normal

Vector.

D3DDECLUSAGE_PSIZE = 4, // Vertex Point Size.

D3DDECLUSAGE_TEXCOORD = 5, // Texture Coordinates.

D3DDECLUSAGE_TANGENGENT = 6, // Tangent Vector.

D3DDECLUSAGE_BINORMAL = 7, // binormal vector.

D3DDECLUSAGE_TESSFACTOR = 8, // Tessellation Factor.

D3DDECLUSAGE_POSITIONT = 9, // Transformed Position.

D3DDECLUSAGE_COLOR = 10, // color.

D3DDECLUSAGE_FOG = 11, // fog Blend Value.

D3DDECLUSAGE_DEPTH = 12, // defth value.

D3DDECLUSAGE_SAMPLE = 13 // Sampler Data.

} D3DDECLUSAGE;

The D3DDECLUSAGE_PSIZE type is used to specify the size of a point of a vertex. It is used for some elves, so we can control its size based on each vertex. The vertex statement of a D3DDeclusage_Position member means that this vertex has been transformed, it notifies the graphics card not to send this vertex to the vertex processing phase (deformed and illuminated).

Note: Usage Type is not mentioned in this book, such as BlendWeights, Blend Indices, Tangent, Binormal, and TestFactor

n usageIndex - a vertex component used to identify multiple identivers. This use index is an integer located between the interval [0, 15]. For example, suppose we have three purposes for D3DDeclusage_normal. We can index the first specified use of 0, index of the second specified use of 1, and index of the third specified use of 2. In this way, we can identify each particular normal through its use index.

Example of vertex description declaration: Suppose we want to describe the vertex format consisting of position vectors and three normal vector. The vertex statement can be specified as follows:

D3DVERTEXELEMENT9 DECL [] =

{

{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_

Position, 0},

{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_

Normal, 0},

{0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_

Normal

, 1},

{0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_

Normal, 2},

D3DDECL_END ()

}

The D3DDECL_END macro is used to initialize the last vertex element of the D3DvertExElement9 array. The same, pay attention to the use index tag of the normal vector.

2.1.2 Creating a vertex statement

Once you describe a vertex declaration as a D3DvertExElement9 array, we can use the following method to get an IDirect3dvertexDeclaration9 interface pointer: hResultiRect3ddevice9 :: CreateVertexDeclaration

Const d3dvertexelement9 * pvertexelements,

IDirect3dvertExDeclaration9 ** PPDECL

);

n pVertexelements - D3DVERTEXELEMENT9 structure array, which describes the vertex declaration we want to create.

n PPDECL - Used to return the creative IDirect3dvertexDeclaration9 interface pointer

Example call, where DECL is a D3DVertexElement9 array:

IDirect3dvertexDeclaration9 * _decl = 0;

HR = _Device-> CreateVertexDeclaration (DECL, & _DECL);

2.1.3 Allow a vertex statement

Memolive: Free vertex format is a convenient feature and is converted to a vertex statement internally. Therefore, when using the vertex statement directly, we no longer need to call:

Device-> setfvf (fVF);

Instead, we call:

Device-> setvertexDeclaration (_DECL);

Among them, _decl is an IDirect3dvertExDeclaration9 interface pointer.

[Declaration]: Introduction to 3D Game Programming With DirectX 9.0 "in this article, it is limited to the translator level, and it is inevitable that there is a mistake in the text. Welcome all netizen criticism; this article is only used for learning exchange and reference usage, not to use In any form of commercial use; if you need to reprint the author's own and translator's consent, maintain the integrity of the article, indicate the author, translator and source, for the consequences of violating the above terms, the translator Do not bear any responsibility. My email address is raymond_king123@hotmade.com, welcome 3D graphics and games, and friends with a certain graphical programming experience to communicate.

转载请注明原文地址:https://www.9cbs.com/read-23176.html

New Post(0)