2
votes

I'm trying extend a renderer (for TressFX) with a Geometry Shader, and therefore I'm taking babysteps in order to see that everything works as it should. Therefore I've created a simpel pass-through Geometry Shader, which works for triangles, but for some reason does not work for lines or points (transforming the triangle to lines and points), since I can't see the output. Result link

I would be glad if someone could point out why it doesn't work for lines and points.

code

ASetPrimitiveTopology is set to D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST

Vertex Shader

struct PS_INPUT_HAIR_AA
{
    float4 Position : SV_POSITION;
    float4 Tangent  : Tangent;
    float4 p0p1     : TEXCOORD0;
};

PS_INPUT_HAIR_AA VS_RenderHair( uint vertexId : SV_VertexID )
{
    PS_INPUT_HAIR_AA Output = (PS_INPUT_HAIR_AA)0;

    Calculate position etc... 

    Output.Position = mul(float4(v, 1), g_mViewProj);
    Output.Tangent  = float4(t, ratio);
    Output.p0p1     = float4( v.xy, g_HairVertexPositions[vertexId+1].xy );

    return Output;
}

Geometry Shader for triangles (which works)

[maxvertexcount(64)] // more than enough
void GS_RenderHairPassThrough( triangle PS_INPUT_HAIR_AA input[3], inout TriangleStream<PS_INPUT_HAIR_AA> OutputStream )
{   
    PS_INPUT_HAIR_AA output = (PS_INPUT_HAIR_AA)0;

    for(uint i = 0; i < 3; ++i) {
        output.Position = input[i].Position;
        output.Tangent  = input[i].Tangent;
        output.p0p1     = input[i].p0p1;
        OutputStream.Append( output );
    }
    OutputStream.RestartStrip();
}

Geometry Shader for points and lines (which does not work)

[maxvertexcount(64)] // more than enough
void GS_RenderHairPassThrough( triangle PS_INPUT_HAIR_AA input[3], inout PointStream<PS_INPUT_HAIR_AA> OutputStream )
{   
    PS_INPUT_HAIR_AA output = (PS_INPUT_HAIR_AA)0;

    for(uint i = 0; i < 3; ++i) {
        output.Position = input[i].Position;
        output.Tangent  = input[i].Tangent;
        output.p0p1     = input[i].p0p1;
        OutputStream.Append( output );
        OutputStream.RestartStrip(); // Not sure if I need this
    }
}

[maxvertexcount(64)] // more than enough
void GS_RenderHairPassThrough( triangle PS_INPUT_HAIR_AA input[3], inout LineStream<PS_INPUT_HAIR_AA> OutputStream )
{   
    PS_INPUT_HAIR_AA output = (PS_INPUT_HAIR_AA)0;

    for(uint i = 0; i < 3; ++i) {
        output.Position = input[i].Position;
        output.Tangent  = input[i].Tangent;
        output.p0p1     = input[i].p0p1;
        OutputStream.Append( output );
    }
    OutputStream.RestartStrip();
}

However, if I hard code the output.Position in the Point/Line pass-through Geometry Shader I can manage to get an output which I can see on the screen.

1

1 Answers

0
votes

I don't think you can change the primitive topology in geometry shader. to render the mesh as lines/points, you might want to set that in your render function as below.

g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);
or
g_pd3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_POINTLIST);

another thing is if you want to change the primitive type in geometry shader, you should use

void GS_RenderHairPassThrough( line PS_INPUT_HAIR_AA input[3], inout PointStream<PS_INPUT_HAIR_AA> OutputStream )
or
void GS_RenderHairPassThrough( point PS_INPUT_HAIR_AA input[3], inout PointStream<PS_INPUT_HAIR_AA> OutputStream )

I see you use triangle for both of them as the first argument of GS_RenderHairPassThrough