[SOLVED] SharpDX line adjacent vertices

Hi there,
I’ve been experimenting with geometry shaders lately. For that we have to work a little bit around MonoGame. Now I’ve tried to access adjacent vertices in the geometry shader by using lineadj as input. Unfortunately it does not work for me. Here is my code:

[maxvertexcount(6)]
void MainGS(lineadj in VertexShaderOutput vertexData[4], inout TriangleStream<VertexShaderOutput> triStream)
{
    float thickness = 0.06f;

    // The vertices 0 and 1 form a line together. We want to create two triangles that widen this
    // line into a faces.

    VertexShaderOutput tA0 = vertexData[1];
    VertexShaderOutput tA1 = vertexData[1];
    VertexShaderOutput tA2 = vertexData[2];
    VertexShaderOutput tB0 = vertexData[2];
    VertexShaderOutput tB1 = vertexData[2];
    VertexShaderOutput tB2 = vertexData[1];

    // Get vector that points from point A to point B.
    float2 direction = normalize( vertexData[2].Position.xy - vertexData[1].Position.xy );
    float2 normal = float2(-direction.y, direction.x);

    // Extrude from center.
    normal *= thickness / 2.0f;
    normal.x /= vertexData[1].AspectRatio;

    float4 offset = float4( normal, 0, 0);

    tA0.Position += offset;
    tA1.Position -= offset;
    tA2.Position += offset;

    tB0.Position -= offset;
    tB1.Position += offset;
    tB2.Position -= offset;

    tA0.Color = float4(1,0,0,1);
    tA1.Color = float4(0,1,0,1);
    tA2.Color = float4(0,0,1,1);

    tB0.Color = float4(1,0,0,1);
    tB1.Color = float4(0,1,0,1);
    tB2.Color = float4(0,0,1,1);

    triStream.Append(tA0);
    triStream.Append(tA1);
    triStream.Append(tA2);
    triStream.Append(tB0);
    triStream.Append(tB1);
    triStream.Append(tB2);
}

By this I try to draw lines. When using line and only two vertices, this works.

Does anybody know if this functionality has been even fully implemented in SharpDX?

Cheers,
Georg

There seems to be a bug in SharpDX. It’s code is ported over from SlimDX, but using the original SlimDX Shader Code Loading, it works:

var graphicsDevice = PiXServices.GetService<IGraphicsDeviceService>()
    .GraphicsDevice;
//var compiledGS = ShaderBytecode
//  .CompileFromFile( geometryShaderFilePath, "MainGS", "gs_5_0" );
var compiledGS = SlimDX.D3DCompiler.ShaderBytecode.CompileFromFile(
    geometryShaderFilePath, "MainGS", "gs_5_0", ShaderFlags.None, EffectFlags.None );
var code = new SharpDX.D3DCompiler.ShaderBytecode( compiledGS.Data );

_GeometryShader = new GeometryShader( ( Device ) graphicsDevice.Handle, code );

Edit: Sorry. After re-building it does not work anymore. I guess the old, working variant one was cached somewhere.

Turns out it has to be provided to the GraphicsDevice as PrimitiveType. Unfortunately MonoGame does not support GeometryShaders and I guess therefore does not support `PrimitiveType.LineListAdj.

That means this can’t be easily done without forking MonoGame and changing GraphicsDevice, PrimitiveType and GraphicsDevice::ToPrimitiveTopology.

Added a comment on a Pull Request that adds Geometry and Hull Shaders to MonoGame.

That’s already under construction i believe if you can’t wait you can look to this thread.

Same Problem there - no adjacent vertices. I already commented on the PR :wink: Thank you.