posts - 25,  comments - 21,  trackbacks - 0
关于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)  编辑 收藏 引用

FeedBack:
# re: 最近整shader,记录一些容易误解的东西。。。
2007-09-15 11:10 | Sherk
At draw time, Direct3D looks for the same "usage - usage index" combination in the current vertex declaration and the current vertex shader function. When the combination is found, the register from shader function DCL is used as the destination for the vertex element.
When a vertex element in the current vertex declaration has a usage which is not found in the current vertex shader, that vertex element is ignored.
When using a vertex shaders version less than 2.0, all semantics mentioned in the shader code need to be present in the declaration bound at draw time. When using vertex shaders 2.0 and above, this restriction that allows applications to use different vertex declarations with the same vertex shader does not exist. This is useful when a vertex shader reads input data based on static conditions. Vertex shader registers not initialized because of this will have undefined values.  回复  更多评论
  
# re: 最近整shader,记录一些容易误解的东西。。。
2007-09-15 11:17 | Sherk
D3DVERTEXELEMENT9 decl[] =
{
{0 ,0 ,D3DDECLTYPE_SHORT4N ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_POSITION ,0},
{0 ,8 ,D3DDECLTYPE_UBYTE4 ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_BLENDINDICES ,0},
{0 ,12 ,D3DDECLTYPE_UBYTE4N ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_BLENDWEIGHT ,0},
{0 ,16 ,D3DDECLTYPE_UBYTE4N ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_NORMAL ,0},
{0 ,20 ,D3DDECLTYPE_UBYTE4N ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_TANGENT ,0},
{0 ,24 ,D3DDECLTYPE_FLOAT16_2 ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_TEXCOORD ,0},
{0 ,12 ,D3DDECLTYPE_FLOAT16_2 ,D3DDECLMETHOD_DEFAULT ,D3DDECLUSAGE_TEXCOORD ,1},
D3DDECL_END()
};


vs_3_0
def c10, 3, 1, 2, -1
dcl_position v0
dcl_normal v1
dcl_tangent v2
dcl_blendindices v3
dcl_texcoord v4
dcl_position o0
dcl_texcoord o1
dcl_texcoord1 o2.xyz
dcl_texcoord2 o3.xy
dcl_texcoord3 o4.xyz
dcl_texcoord4 o5.xyz
dcl_texcoord5 o6.xyz
如果这个样子,实际又是什么意思呢?
其实输入流这个vertex buffer中具有7个members,而vertex shader只使用了其中5个members,其中blendweight和texcoord1被vs忽略掉。简单吧。  回复  更多评论
  
# re: 最近整shader,记录一些容易误解的东西。。。
2007-09-19 20:50 | LAIL
我的游戏不能玩了  回复  更多评论
  
只有注册用户登录后才能发表评论。
<2007年9月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

常用链接

留言簿(3)

随笔档案

相册

好友

搜索

  •  

最新评论

阅读排行榜

评论排行榜