Geometry 屏幕空间方形在PIX中看起来失真

Geometry 屏幕空间方形在PIX中看起来失真,geometry,directx,slimdx,direct3d11,pix,Geometry,Directx,Slimdx,Direct3d11,Pix,我有一个简单的函数,可以创建一个覆盖整个屏幕的正方形,我使用它来应用后期处理效果,但是据我所知,它是导致无数错误的原因 当我在PIX中运行我的代码时,我得到了以下网格,但是正方形应该是直的并且覆盖了屏幕,不是吗 我的顶点着色器不进行变换,只是将位置信息传递给像素着色器 创建正方形的函数如下所示: private void InitializeGeometry() { meshes = new Dictionary<Vector3, Mesh>();

我有一个简单的函数,可以创建一个覆盖整个屏幕的正方形,我使用它来应用后期处理效果,但是据我所知,它是导致无数错误的原因

当我在PIX中运行我的代码时,我得到了以下网格,但是正方形应该是直的并且覆盖了屏幕,不是吗

我的顶点着色器不进行变换,只是将位置信息传递给像素着色器

创建正方形的函数如下所示:

private void InitializeGeometry()
    {
        meshes = new Dictionary<Vector3, Mesh>();
        //build array of vertices for one square
        ppVertex[] vertexes = new ppVertex[4];
        //vertexes[0].Position = new Vector3(-1f, -1f, 0.25f);

        vertexes[0].Position = new Vector3(-1, -1, 1f);
        vertexes[1].Position = new Vector3(-1, 1, 1f);
        vertexes[2].Position = new Vector3(1, -1, 1f);
        vertexes[3].Position = new Vector3(1, 1, 1f);

        vertexes[0].TexCoords = new Vector2(0, 0);
        vertexes[1].TexCoords = new Vector2(0, 1);
        vertexes[2].TexCoords = new Vector2(1, 0);
        vertexes[3].TexCoords = new Vector2(1, 1);

        //build index array for the vertices to build a quad from two triangles
        short[] indexes = { 0, 1, 2, 1, 3, 2 };

        //create the data stream to push the vertex data into the buffer
        DataStream vertices = new DataStream(Marshal.SizeOf(typeof(Vertex)) * 4, true, true);
        //load the data stream
        vertices.WriteRange(vertexes);
        //reset the data position
        vertices.Position = 0;

        //create the data stream to push the index data into the buffer
        DataStream indices = new DataStream(sizeof(short) * 6, true, true);
        //load the data stream
        indices.WriteRange(indexes);
        //reset the data position
        indices.Position = 0;

        //create the mesh object
        Mesh mesh = new Mesh();

        //create the description of the vertex buffer
        D3D.BufferDescription vbd = new BufferDescription();
        vbd.BindFlags = D3D.BindFlags.VertexBuffer;
        vbd.CpuAccessFlags = D3D.CpuAccessFlags.None;
        vbd.OptionFlags = ResourceOptionFlags.None;
        vbd.SizeInBytes = Marshal.SizeOf(typeof(Vertex)) * 4;
        vbd.Usage = ResourceUsage.Default;
        //create and assign the vertex buffer to the mesh, filling it with data
        mesh.VertexBuffer = new D3D.Buffer(device, vertices, vbd);

        //create the description of the index buffer
        D3D.BufferDescription ibd = new BufferDescription();
        ibd.BindFlags = D3D.BindFlags.IndexBuffer;
        ibd.CpuAccessFlags = D3D.CpuAccessFlags.None;
        ibd.OptionFlags = ResourceOptionFlags.None;
        ibd.SizeInBytes = sizeof(short) * 6;
        ibd.Usage = ResourceUsage.Default;
        //create and assign the index buffer to the mesh, filling it with data
        mesh.IndexBuffer = new D3D.Buffer(device, indices, ibd);

        //get vertex and index counts
        mesh.vertices = vertexes.GetLength(0);
        mesh.indices = indexes.Length;

        //close the data streams
        indices.Close();
        vertices.Close();

        meshes.Add(new Vector3(0), mesh);
    }
编辑:我添加了正在运行的顶点着色器

cbuffer EveryFrame : register(cb0)
{
    float3 diffuseColor : packoffset(c0);
    float3 lightdir : packoffset(c1);
};

cbuffer EveryMotion : register(cb1)
{
    float4x4 WorldViewProjection : packoffset(c0);
    float4x4 LightWorldViewProjection : packoffset(c4);
};

struct VS_IN
{
    float3 position : POSITION;
    float3 normal : NORMAL;
    float4 col : TEXCOORD;
};

struct PS_IN
{
    float4 position : SV_POSITION;
    float4 col : TEXCOORD;
    float3 normal : NORMAL;
};

PS_IN VS(VS_IN input)
{
    PS_IN output;
    output.position = float4(input.position,1);
    output.col = input.col;
    output.normal = input.normal;
    return output;
}
这是PIX的顶点输出

上一篇:

PostV:

这是我选择调试vertex 0时生成的disassembly PIX

//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
//
// Input signature:
//
// Name             Index   Mask Register SysValue Format   Used
// ---------------- ----- ------ -------- -------- ------ ------
// POSITION             0   xyz         0     NONE  float   xyz 
// NORMAL               0   xyz         1     NONE  float   xyz 
// TEXCOORD             0   xyzw        2     NONE  float       
//
//
// Output signature:
//
// Name             Index   Mask Register SysValue Format   Used
// ---------------- ----- ------ -------- -------- ------ ------
// SV_POSITION          0   xyzw        0      POS  float   xyzw
// TEXCOORD             0   xyzw        1     NONE  float   xyzw
// NORMAL               0   xyz         2     NONE  float   xyz 
//
vs_4_0
dcl_input v0.xyz
dcl_input v1.xyz
dcl_output_siv  o0.xyzw , position
dcl_output o1.xyzw
dcl_output o2.xyz
mov o0.xyz, v0.xyzx
mov o0.w, l(1.000000)
mov o1.xyzw, l(1.000000, 1.000000, 1.000000, 1.000000)
mov o2.xyz, v1.xyzx
ret 
// Approximately 5 instruction slots used
我还添加了输入汇编程序:

private void SetPPInputAssembler(Shader shader)
        {
            InputElement[] elements = new[] {
                new InputElement("POSITION",0,Format.R32G32B32_Float,0),
                new InputElement("NORMAL",0,Format.R32G32B32_Float,12,0),
                new InputElement("TEXCOORD",0,Format.R32G32_Float,24,0),
            };

            InputLayout layout = new InputLayout(device, shader.InputSignature, elements);

            context.InputAssembler.InputLayout = layout;
            context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
        }

显然,顶点输入位置与要提供的值不匹配

对于第一个顶点,值看起来很好,直到纹理坐标的z坐标。 您正在程序顶点结构中定义Vector2D,但Vertexshader顶点结构中的Vector4D和其他内容会混淆

只需将VS_更改为:

struct VS_IN
{
    float3 position : POSITION;
    float3 normal : NORMAL;
    float2 col : TEXCOORD; // float2 instead of float4
};
但我不确定你是否真的想要颜色,或者更确切地说是texcoords。如果你真的想有颜色浮动4将是正确的,但你必须改变

vertexes[0].TexCoords = new Vector2(0, 0);
进入


无论哪种情况,其中一个变量命名错误,这可能是造成混淆的原因。

很明显,顶点输入位置与要提供的值不匹配

对于第一个顶点,值看起来很好,直到纹理坐标的z坐标。 您正在程序顶点结构中定义Vector2D,但Vertexshader顶点结构中的Vector4D和其他内容会混淆

只需将VS_更改为:

struct VS_IN
{
    float3 position : POSITION;
    float3 normal : NORMAL;
    float2 col : TEXCOORD; // float2 instead of float4
};
但我不确定你是否真的想要颜色,或者更确切地说是texcoords。如果你真的想有颜色浮动4将是正确的,但你必须改变

vertexes[0].TexCoords = new Vector2(0, 0);
进入


无论如何,其中一个变量命名错误,可能是混淆的原因。

你的顶点着色器是什么样子的?我添加了顶点着色器代码,包括当前未使用的cbuffer。在Pix中顶点输入值是什么样子的?我为你添加了顶点输入值。嗯,这很奇怪。您的输入看起来是正确的。您的输出看起来是正确的。如果你在DirectXDev上发布你的顶点着色器是什么样子的,你可能会得到更好的答案。我已经添加了顶点着色器代码,包括当前未使用的cbuffer。在Pix中顶点输入值是什么样子的?我已经为你添加了顶点输入值。嗯,这很奇怪。您的输入看起来是正确的。您的输出看起来是正确的。你可以通过在DirectXDev上发帖得到更好的答案。我试图改变这一点,但恐怕没有效果。当然这与实际的顶点输入位置有关,而不是这个无关的col变量?修复了它,你是对的,只是有点错误。我在draw函数中留下了一个轻微的输入错误,调用了错误的结构。享受你的赏金吧我试着改变了,但恐怕没有效果。当然这与实际的顶点输入位置有关,而不是这个无关的col变量?修复了它,你是对的,只是有点错误。我在draw函数中留下了一个轻微的输入错误,调用了错误的结构。享受你的赏金吧