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!