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