# 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.

## 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 on other sites
Why aren't you just doing this using the tessellation shaders?

##### Share on other sites
It's the next chapter of the book and this exercise should be solved without it

##### Share on other sites
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 on other sites
Yeah, I've also realized a little bit after posting that's a max and not exact count

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×