我有一个不能正确绘制的着色器。它在XNA中工作,但是必须为DX11和SharpDX重新编写,现在使用着色器模型5。没有例外,着色效果编译很好,没有调试层消息来自设备,除了一个无关的(?)默认采样器状态投诉。这是一个正常的,全屏四人做最简单的纹理blit。(使用随机噪声纹理进行测试)

我给顶点着色器一个VertexPositionTexutre,这是一个SharpDX对象,包含:
[VertexElement("SV_Position")]
public Vector3 Position;
[VertexElement("TEXCOORD0")]
public Vector2 TextureCoordinate;我怀疑签名之间是不匹配的。VertexPositionTexture有一个为"SV_Position“定义的Vector3位置组件。
D3D11 定义 "SV_Position“作为float4。它是一个具有具体本机类型的系统值常量。我担心着色器会在float3 of Vector3的末端吃掉一个额外的浮点数。这也解释了为什么我的超视距在几个顶点被打破。
这是我的顶点着色器
struct V2P
{
float4 vPosition : SV_Position;
float2 vTexcoord : TEXCOORD0;
};
V2P VSCopy(float4 InPos : SV_Position,
float2 InTex : TEXCOORD0)
{
V2P Out = (V2P)0;
// transform the position to the screen
Out.vPosition = float4(InPos);
Out.vTexcoord = InTex;
return Out;
}我尝试将VSCopy()的输入从float4更改为float3,结果没有变化。除了重新编译SharpDX VertexPositionTexture之外,我不知道如何解决这个问题,但是SharpDX完全支持DirectX11,所以我肯定做错了一些事情。
我正在定义我的顶点,并将其设置如下:
//using SharpDX.Toolkit.Graphics
[...]//In the initialization
verts = new VertexPositionTexture[]
{
new VertexPositionTexture(
new Vector3(1.0f,-1.0f,0),
new Vector2(1,1)),
new VertexPositionTexture(
new Vector3(-1.0f,-1.0f,0),
new Vector2(0,1)),
new VertexPositionTexture(
new Vector3(-1.0f,1.0f,0),
new Vector2(0,0)),
new VertexPositionTexture(
new Vector3(1.0f,1.0f,0),
new Vector2(1,0))
}
//vb is a Buffer<VertexPositionTexture>
short[] indeces = new short[] { 0, 1, 2, 2, 3, 0 };
vb = SharpDX.Toolkit.Graphics.Buffer.Vertex.New(Game.Instance.GraphicsDevice, verts, SharpDX.Direct3D11.ResourceUsage.Dynamic);
ib = SharpDX.Toolkit.Graphics.Buffer.Index.New(Game.Instance.GraphicsDevice, indeces, dx11.ResourceUsage.Dynamic);
[...] //In the Render method, called every frame to draw the quad
Game.Instance.GraphicsDevice.SetVertexBuffer<VertexPositionTexture>(vb, 0);
Game.Instance.GraphicsDevice.SetIndexBuffer(ib, false);
Game.Instance.GraphicsDevice.DrawIndexed(PrimitiveType.TriangleList, 6);发布于 2014-09-30 15:42:29
SharpDX.Tookit提供了一种将InputLayout指定给顶点着色器的方法。我错过了这个方法,并且错误地试图通过属性设置顶点输入布局:
SharpDX.Direct3D11.ImmediateContext.InputAssembler.InputLayout必须通过SharpDX.Toolkit.Graphics.GraphicsDevice.SetVertexInputLayout();方法设置输入布局。
https://stackoverflow.com/questions/26090129
复制相似问题