1
\$\begingroup\$

I'm currently using a geometry shader to generate grass blades out of single root points that are layed out in a grid. For each root point, I generate a grass blade with, right now, a constant number of vertices.

However, for level of detail, I would like to generate a number of vertices depending on the distance to the camera. Now, since there are no dynamic arrays, I tried to declare multiple techniques which call the geometry shader with the number of vertices.

I would then be able to divide my grass into patches/smaller grids, calculate the distance to the camera for this patch and then call the technique with the appropriate number of vertices.

The HLSL part looks something like this:

[maxvertexcount(24)]
void GS_LOD1(point GEO_IN points[1], inout TriangleStream<GEO_OUT> output) 
{
    GS_Shader(points, 8, output);
}

[maxvertexcount(24)]
void GS_LOD2(point GEO_IN points[1], inout TriangleStream<GEO_OUT> output)
{
    GS_Shader(points, 16, output);
}

technique LevelOfDetail1
{
    pass Pass1
    {
        VertexShader = compile vs_4_0 VS_Shader();
        GeometryShader = compile gs_4_0 GS_LOD1();
        PixelShader = compile ps_4_0 PS_Shader();
    }
}

technique LevelOfDetail2
{
    pass Pass1
    {
        VertexShader = compile vs_4_0 VS_Shader();
        GeometryShader = compile gs_4_0 GS_LOD2();
        PixelShader = compile ps_4_0 PS_Shader();
    }
}

And the definition of the GS function:

void GS_Shader(point GEO_IN points[1], in const int realVertexCount, inout TriangleStream<GEO_OUT> output) 
{
  [...]
  GEO_OUT v[realVertexCount];

However, even this way the compiler complains:

array dimensions must be literal scalar expressions

Is this possible in any way? I guess what would is just writing several geometry shaders that basically do the same thing but with a already defined number of vertices - this sounds a bit messy though.

Thanks!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ in openGL you can stop emitting primitives in the geom shader even when the amount of vertices is below the number specified in the output \$\endgroup\$ Commented Nov 16, 2014 at 13:07
  • \$\begingroup\$ Thanks! I tried this yesterday and didn't have any success because of another error - this is actually working now. Now I just need to check if it makes more sense to calculate the LOD for patches on the CPU or for each primitive in the geometry shader, guess I will try. \$\endgroup\$ Commented Nov 16, 2014 at 15:14

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.