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, inout TriangleStream<GEO_OUT> output)
{
}

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

technique LevelOfDetail1
{
pass Pass1
{
}
}

technique LevelOfDetail2
{
pass Pass1
{
}
}


And the definition of the GS function:

void GS_Shader(point GEO_IN points, 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!

• 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 – ratchet freak Nov 16 '14 at 13:07
• 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. – brdigi Nov 16 '14 at 15:14