ジオメトリシェーダの使用には非常に奇妙な問題があります。私はポイントをとり、それを三角形に変換する非常に単純なジオメトリシェーダを作った。ジオメトリシェーダは原点に余分なポイントを受け取ります
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つはouに出ていますtput ..
これはどうして起こるのでしょうか?私はそれがバッファによって割り当てられている余分なメモリに関連する可能性があります恐れて...しかし、私は正確にどこに問題があるかを把握していないようです。
ありがとうございます!
は、頂点数のために4つ以上を使用して描画呼び出しですか?もしそうなら、過去のどの頂点(描画数 - バッファサイズ)でも値は0になり、余分な三角形は0の中央に置かれます。 –
そうです!これは実際に描画されたものなので12の頂点を置いていましたが、実際には4つの頂点しかGPUに送られないので、それほど賢明ではないと思います。どうもありがとうございました!私はそれを受け入れることができるように答えとしてそれを入れたいですか? –
ようこそ。定数のバッファでも同じ問題が発生します(余分な値は0になります)。 –