Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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
hlsl
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 )
{
    //Test geometry shader
    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:

C#
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:

C#
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.
Posted
Updated 11-Feb-13 3:46am
v2
Comments
CHill60 11-Feb-13 8:57am    
If you post the code that wouldn't produce the output you're more likely to get someone to help you
CHill60 11-Feb-13 17:00pm    
Good one IDominator. Wish I could help in detail but not my area of expertise. At least now no-one can moan at you for not trying :-) It also pops your question back up in the list. Good Luck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900