Jump to content
  • Advertisement
Sign in to follow this  
~Helgon

How can I call the Geometry Shader twice?

This topic is 2148 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I wan't to execute my GS dependent of the distance to the object. If the object is very close i want to execute the GS twice.

My thoughts (and the problems that occurs while trial and error) are that my maxvertexcount is 8. So i can't generate more points dependent of any variable/value what ever. But how can i call the GS then? I thought to call the GS out of the GS Method. I've tried something like that:


// inside the GeometryShader
VertexOut t[3];
t[0] = v[1];
t[1] = v[2];
t[2] = v[3];
GS(t, stream);


but the error is: Fehler 5 error X3500: 'GS': recursive functions not allowed in gs_5_0 as already expected but at least I've tried it.

My GeometryShder looks like that at the moment.

Does someone has an idea how i can solve the problem?


[maxvertexcount(8)]
void GS(triangle VertexOut gin[3], inout TriangleStream<GeoOut> stream)
{
float distance;
ComputeDistance(gin[0], distance);
[branch]
if(distance < 15.0f)
{
VertexOut v[6];
Subdivide(gin, v);
OutputSubdivision(v, stream);
}
else if(distance > 15.0f &amp;&amp; distance < 30.0f)
{
// here i want to get double tessellation
VertexOut v[6];
Subdivide(gin, v);
OutputSubdivision(v, stream);
}
else if(distance > 30.0f)
{
GeoOut v[3];
for(int i = 0; i < 3; ++i)
{
v.PosW = mul(float4(gin.PosL, 1.0f), gWorld).xyz;
v.NormalW = mul(gin.NormalL, (float3x3)gWorldInvTranspose);
v.PosH = mul(float4(gin.PosL, 1.0f), gWorldViewProj);
v.Tex = mul(gin.Tex, (float3x3)gWorldInvTranspose);
stream.Append(v);
}
}
}


Regards Helgon Edited by ~Helgon

Share this post


Link to post
Share on other sites
Advertisement
How about just setting the maximum vertex count higher? It's a maximum, you don't need to output that many (I think). In any case, a geometry shader which outputs a variable number of vertices is going to be horribly inefficient anyway, so at this point I think it would be OK to do it like that. But if you can compute which geometry shader should be used from the CPU side, you should have multiple shaders and select the right one before starting the frame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!