• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# How can I call the Geometry Shader twice?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1~Helgon  Members

Posted 01 December 2012 - 05:34 PM

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[i].PosW = mul(float4(gin[i].PosL, 1.0f), gWorld).xyz;
v[i].NormalW = mul(gin[i].NormalL, (float3x3)gWorldInvTranspose);
v[i].PosH = mul(float4(gin[i].PosL, 1.0f), gWorldViewProj);
v[i].Tex = mul(gin[i].Tex, (float3x3)gWorldInvTranspose);
stream.Append(v[i]);
}
}
}


Regards Helgon

Edited by ~Helgon, 01 December 2012 - 05:35 PM.

from time to time i find time

### #2MJP  Moderators

Posted 01 December 2012 - 06:40 PM

Why aren't you just doing this using the tessellation shaders?

### #3~Helgon  Members

Posted 01 December 2012 - 07:57 PM

It's the next chapter of the book and this exercise should be solved without it

from time to time i find time

### #4Bacterius  Members

Posted 02 December 2012 - 04:54 AM

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #5~Helgon  Members

Posted 02 December 2012 - 07:06 AM

Yeah, I've also realized a little bit after posting that's a max and not exact count

from time to time i find time

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.