关于Vertex Declaration和vs输入相关联的问题:
app的定义的顶点数据格式,和输入给vertex shader处理顶点,是怎么关联的呢,一开始误以为是按照内存分布,就如c++中的结构体,其实不是,app的vertex是通过Usage Semantics 跟shader function对应来关联,也就是相同的sematic相关联。
// A structure for our custom vertex type. We added texture coordinates
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The position
D3DCOLOR color; // The color
FLOAT tu, tv; // The texture coordinates
};
//
D3DVERTEXELEMENT9 decl[] =
{
{0 ,0 ,D3DDECLTYPE_FLOAT3 , D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_POSITION ,0},
{0 ,12 ,D3DDECLTYPE_D3DCOLOR ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_COLOR , 0},
{0 ,16 ,D3DDECLTYPE_FLOAT2 , D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_TEXCOORD ,0},
D3DDECL_END()
};
//在shader中
struct VertexShaderInput
{
float2 Texcoord :TEXCOORD0;
float4 VertexColor :COLOR0;
float4 Position :POSITION;
};
struct VertexShaderInput
{
float2 Texcoord :TEXCOORD0;
float4 Position :POSITION;
float4 VertexColor :COLOR0;
};
上述三个成员可以随便交换,重要的sematic的修饰。
posted on 2007-09-15 11:09
Sherk 阅读(1005)
评论(3) 编辑 收藏 引用