d3dx9具有一个函数
D3DXFloat16To32Array可以实现这个转换。
开源引擎ogre也有类似模块OgreBitwise.h中也有转换函数。这个float16格式是1-5-10;
posted @
2007-09-16 09:23 Sherk 阅读(1351) |
评论 (0) |
编辑 收藏
typedef enum _D3DDECLTYPE
{
D3DDECLTYPE_FLOAT1 = 0, // 1D float expanded to (value, 0., 0., 1.)
D3DDECLTYPE_FLOAT2 = 1, // 2D float expanded to (value, value, 0., 1.)
D3DDECLTYPE_FLOAT3 = 2, // 3D float expanded to (value, value, value, 1.)
D3DDECLTYPE_FLOAT4 = 3, // 4D float
D3DDECLTYPE_D3DCOLOR = 4, // 4D packed unsigned bytes mapped to 0. to 1. range
// Input is in D3DCOLOR format (ARGB) expanded to (R, G, B, A)
D3DDECLTYPE_UBYTE4 = 5, // 4D unsigned byte
D3DDECLTYPE_SHORT2 = 6, // 2D signed short expanded to (value, value, 0., 1.)
D3DDECLTYPE_SHORT4 = 7, // 4D signed short
// The following types are valid only with vertex shaders >= 2.0
D3DDECLTYPE_UBYTE4N = 8, // Each of 4 bytes is normalized by dividing to 255.0
D3DDECLTYPE_SHORT2N = 9, // 2D signed short normalized (v[0]/32767.0,v[1]/32767.0,0,1)
D3DDECLTYPE_SHORT4N = 10, // 4D signed short normalized (v[0]/32767.0,v[1]/32767.0,v[2]/32767.0,v[3]/32767.0)
D3DDECLTYPE_USHORT2N = 11, // 2D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,0,1)
D3DDECLTYPE_USHORT4N = 12, // 4D unsigned short normalized (v[0]/65535.0,v[1]/65535.0,v[2]/65535.0,v[3]/65535.0)
D3DDECLTYPE_UDEC3 = 13, // 3D unsigned 10 10 10 format expanded to (value, value, value, 1)
D3DDECLTYPE_DEC3N = 14, // 3D signed 10 10 10 format normalized and expanded to (v[0]/511.0, v[1]/511.0, v[2]/511.0, 1)
D3DDECLTYPE_FLOAT16_2 = 15, // Two 16-bit floating point values, expanded to (value, value, 0, 1)
D3DDECLTYPE_FLOAT16_4 = 16, // Four 16-bit floating point values
D3DDECLTYPE_UNUSED = 17, // When the type field in a decl is unused.
} D3DDECLTYPE;
可能大部分都很少用到。
最近发现老外常用D3DDECLTYPE_FLOAT16_2,D3DDECLTYPE_UBYTE4N,
应该可以节约几何带宽,比较数据小了很多,相比较float4而言。
其中这个UBYTE4N,就是你的app提供byte类型,在提交给shader处理时,驱动自动帮你除255.0f转换成浮点数。蛮好,蛮好。
posted @
2007-09-16 09:18 Sherk 阅读(484) |
评论 (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 @
2007-09-15 11:09 Sherk 阅读(1005) |
评论 (3) |
编辑 收藏
row_major float4x4 mWorldViewProj;
//
float3 pos=mul(mWorldViewProj,vPosition);
对应指令为:
dp3 oPos.x, c0, v0
dp3 oPos.y, c1, v0
dp3 oPos.z, c2, v0
column_major float4x4 mWorldViewProj;
//
float3 pos=mul(vPosition,mWorldViewProj);
对应指令为:
dp3 oPos.x, v0, c0
dp3 oPos.y, v0, c1
dp3 oPos.z, v0, c2
原因是:
对于mul指令
Performs matrix multiplication between x and y.
If x is a vector, it treated as a row vector.
If y is a vector, it is treated as a column vector.
posted @
2007-09-14 11:51 Sherk 阅读(232) |
评论 (0) |
编辑 收藏
posted @
2006-12-07 19:59 Sherk 阅读(215) |
评论 (1) |
编辑 收藏