ジオメトリ シェーダーの使用に関して非常に奇妙な問題があります。ポイントを取得して三角形に変換する非常に単純なジオメトリ シェーダーを作成しました。
ここにシェーダーがあります:
struct GS_OUTPUT
{
float4 pos : SV_POSITION;
};
struct VS_INPUT
{
float3 pos : ANCHOR;
};
VS_INPUT VShader(VS_INPUT input)
{
return input;
}
float4 PShader(float4 position: SV_POSITION) : SV_Target
{
return float4(0.0, 1.0, 0.5, 0.0);
}
[maxvertexcount(3)]
void Triangulat0r( point VS_INPUT input[1], inout TriangleStream<GS_OUTPUT> OutputStream )
{
GS_OUTPUT output;
float3 _input;
_input = input[0].pos;
output.pos = float4(_input.x + 0.1, _input.y - 0.1, _input.z, 1.0);
OutputStream.Append( output );
output.pos = float4(_input.x - 0.1, _input.y - 0.1, _input.z, 1.0);
OutputStream.Append( output );
output.pos = float4(_input.x, _input.y + 0.1, _input.z, 1.0);
OutputStream.Append( output );
}
次のように 4 つの頂点を送信します。
// create test vertex data, making sure to rewind the stream afterward
var vertices = new DataStream(12*4, true, true);
vertices.Write(new Vector3(-0.5f, -0.5f, 0f));
vertices.Write(new Vector3(-0.5f, 0.5f, 0f));
vertices.Write(new Vector3(0.5f, 0.5f, 0f));
vertices.Write(new Vector3(0.5f, -0.5f, 0f));
vertices.Position = 0;
// create the vertex layout and buffer
var elements = new[] { new InputElement("ANCHOR", 0, Format.R32G32B32_Float, 0) };
var layout = new InputLayout(device, inputSignature, elements);
var vertexBuffer = new Buffer(device, vertices, 12 * 4, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
// configure the Input Assembler portion of the pipeline with the vertex data
context.InputAssembler.InputLayout = layout;
context.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, 12, 0));
そして、私はこの出力を取得します:
ご覧のとおり、入力アセンブラーに送信した三角形は 4 つだけで、5 つが出力されています。
なぜこれが起こるのかについてのアイデアはありますか?バッファによって割り当てられている余分なメモリに関連している可能性があるのではないかと心配しています...しかし、問題がどこにあるのか正確にはわかりません。
前もって感謝します!