0

我知道在顶点着色器中你这样做:

PixelInputType TextureVertexShader(VertexInputType input)
{
        PixelInputType output;

// Change the position vector to be 4 units for proper matrix calculations.
        input.position.w = 1.0f;
// Update the position of the vertices based on the data for this particular instance.
        input.position.x += input.instancePosition.x;
        input.position.y += input.instancePosition.y;
        input.position.z += input.instancePosition.z;
// Calculate the position of the vertex against the world, view, and projection matrices.
        output.position = mul(input.position, worldMatrix);
        output.position = mul(output.position, viewMatrix);
        output.position = mul(output.position, projectionMatrix);

// Store the texture coordinates for the pixel shader.
output.tex = input.tex;

        return output;
}

在几何着色器中使用 instancedPosition 的等价物是什么?就像我想实例化一个由 1 个顶点组成的模型并为每个实例在几何着色器中制作一个四边形并将四边形的位置设置为对应的 instancePosition 的位置实例缓冲区中的实例。

4

1 回答 1

0

为了在几何着色器中传递数据,您可以简单地从 VS 传递到 GS,因此您的 VS 输出结构如下:

struct GS_INPUT
{
    float4 vertexposition :POSITION;
    float4 instanceposition : TEXCOORD0; //Choose any semantic you like here
    float2 tex : TEXCOORD1;
    //Add in any other relevant data your geometry shader is gonna need
};

然后在您的顶点着色器中,直接在几何着色器中传递数据(未转换)

根据您的输入原始拓扑,您的几何着色器将以点、线或完整三角形的形式接收数据,因为您提到要将点转换为四边形,原型看起来像这样

[maxvertexcount(4)]
void GS(point GS_INPUT input[1], inout TriangleStream<PixelInputType> SpriteStream)
{
    PixelInputType output;

    //Prepare your 4 vertices to make a quad, transform them and once they ready, use
    //SpriteStream.Append(output); to emit them, they are triangle strips,
    //So if you need a brand new triangle,
    // you can also use SpriteStream.RestartStrip();       
}
于 2012-09-11T10:27:02.733 回答