9
我目前正在嘗試使用DirectX API,我想知道在DirectX 11中渲染精靈的常用方法(例如,用於俄羅斯方塊克隆)。在DirectX 11中渲染精靈的最佳實踐是什麼?
是否有一個類似於ID3DX10Sprite
的接口?如果沒有,這將是在DirectX 11中繪製精靈的常用方法?
編輯:這是對我工作的HLSL代碼(投影的座標計算可以做的更好):
struct SpriteData
{
float2 position;
float2 size;
float4 color;
};
struct VSOut
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
cbuffer ScreenSize : register(b0)
{
float2 screenSize;
float2 padding; // cbuffer must have at least 16 bytes
}
StructuredBuffer<SpriteData> spriteData : register(t0);
float2 GetVertexPosition(uint VID)
{
[branch] switch(VID)
{
case 0:
return float2(0, 0);
case 1:
return float2(1, 0);
case 2:
return float2(0, 1);
default:
return float2(1, 1);
}
}
float4 ComputePosition(float2 positionInScreenSpace, float2 size, float2 vertexPosition)
{
float2 origin = float2(-1, 1);
float2 vertexPositionInScreenSpace = positionInScreenSpace + (size * vertexPosition);
return float4(origin.x + (vertexPositionInScreenSpace.x/(screenSize.x/2)), origin.y - (vertexPositionInScreenSpace.y/(screenSize.y/2)), 1, 1);
}
VSOut VShader(uint VID : SV_VertexID, uint SIID : SV_InstanceID)
{
VSOut output;
output.color = spriteData[SIID].color;
output.position = ComputePosition(spriteData[SIID].position, spriteData[SIID].size, GetVertexPosition(VID));
return output;
}
float4 PShader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}
你能給我一個短的代碼示例嗎?我努力開始使用緩衝區。 – 2010-10-07 23:15:59
查看DXSDK中的所有D3D11樣本,並仔細查看它們如何創建緩衝區,綁定它們,更新它們等。 – Stringer 2010-10-08 12:38:39
哇,謝謝。這真的幫助我開始:) – 2010-10-08 21:28:18