Hi folks,
I've been trying to generate shadow volumes with the gpu.
But can't get the geometry shader to produce output.
So how can I create a shader with stream output in slimdx? Can someone give me an example with code in hlsl and slimdx?
Edit:
@ CHill60
here's some code
Shader
struct GSPS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD;
float3 Norm : NORMAL;
};
struct GSPS_INPUTO
{
float4 Pos : SV_POSITION;
};
struct GSPS_OUT
{
float4 Pos : SV_POSITION;
};
GSPS_INPUTO VS(GSPS_INPUT input)
{
GSPS_INPUTO oput;
oput.Pos = input.Pos;
return oput;
}
[maxvertexcount(3)]
void GS( triangle GSPS_INPUTO input[3], inout TriangleStream<GSPS_OUT> TriStream )
{
GSPS_OUT output;
output.Pos = input[0].Pos;
TriStream.Append(output);
output.Pos = input[1].Pos;
TriStream.Append(output);
output.Pos = input[2].Pos;
TriStream.Append(output);
TriStream.RestartStrip();
}
technique10 Technique1
{
pass Pass1
{
SetGeometryShader(ConstructGSWithSO(CompileShader(gs_5_0, GS()), "SV_POSITION.xyzw;"));
SetVertexShader(CompileShader(vs_5_0, VS()));
SetPixelShader(NULL);
}
}
This is the initialization:
ShaderBytecode effectByteCode = ShaderBytecode.CompileFromFile("geoTest.fx", "fx_5_0", ShaderFlags.Debug | ShaderFlags.SkipOptimization, EffectFlags.None);
geoEf = new Effect(_device, effectByteCode);
buffer = new StreamOutputBufferBinding();
BufferDescription bdesc = new BufferDescription()
{
BindFlags = BindFlags.StreamOutput | BindFlags.VertexBuffer,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
SizeInBytes = 1024 * 1024 * 4,
Usage = ResourceUsage.Default
};
buffer.Buffer = new SlimDX.Direct3D11.Buffer(_device, bdesc);
EffectPass p = geoEf.GetTechniqueByIndex(0).GetPassByIndex(0);
L = new InputLayout(_device, p.Description.Signature, new[] {
new InputElement("POSITION", 0, Format.R32G32B32A32_Float, InputElement.AppendAligned, 0,
InputClassification.PerVertexData, 0),
new InputElement("TEXCOORD", 0, Format.R32G32_Float, InputElement.AppendAligned, 0,
InputClassification.PerVertexData, 0),
new InputElement("NORMAL", 0, Format.R32G32B32_Float, InputElement.AppendAligned,0,
InputClassification.PerVertexData, 0)
});
effectByteCode.Dispose();
buffers = new SlimDX.Direct3D11.Buffer[1];
This is the draw call:
device.ImmediateContext.StreamOutput.SetTargets(buffer);
EffectPass m_effectPass = geoEf.GetTechniqueByIndex(0).GetPassByIndex(0);
device.ImmediateContext.InputAssembler.InputLayout = L;
device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
device.ImmediateContext.InputAssembler.SetIndexBuffer(m_indexBuffer2d,
SlimDX.DXGI.Format.R16_UInt, 0);
device.ImmediateContext.InputAssembler.SetVertexBuffers(
0,
new VertexBufferBinding(m_vertexBuffer, Marshal.SizeOf(typeof(Vertex)), 0));
m_effectPass.Apply(device.ImmediateContext);
device.ImmediateContext.DrawIndexed(count, 0, 0);
device.ImmediateContext.StreamOutput.GetTargets(1).CopyTo(buffers, 0);
device.ImmediateContext.StreamOutput.SetTargets(null);
And I ceep getting no stream output.