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

## Recommended Posts

Nearly every geometry shader reference says that GS can create or destroy primitives, and gives examples on how to add or change geometries, but few of them show how to discard primitives. Could anyone offer some hint on this? thanks.

##### Share on other sites
[code]
[maxvertexcount(3)]
void GS(
triangle VS_OUT vertices[3],
inout TriangleStream<GS_OUT> outStream,
)
{
if (someCondition) // someCondition is a boolean that represents your condition
{
outStream.Append(vertices[0]);
outStream.Append(vertices[1]);
outStream.Append(vertices[2]);
}
else
{
// do not append to outStream, effectively discarding the output
}
}
[/code]

##### Share on other sites
It is worth noting that you can evaluate the "someCondition" on the GS logic itself; for example, calculate the geometric normal of the current triangle and compare it to some direction in which you want to do custom culling against. Edited by Nik02

##### Share on other sites
[quote name='Nik02' timestamp='1355687078' post='5011331']
[code]
[maxvertexcount(3)]
void GS(
triangle VS_OUT vertices[3],
inout TriangleStream<GS_OUT> outStream,
)
{
if (someCondition) // someCondition is a boolean that represents your condition
{
outStream.Append(vertices[0]);
outStream.Append(vertices[1]);
outStream.Append(vertices[2]);
}
else
{
// do not append to outStream, effectively discarding the output
}
}
[/code]
[/quote]
Thanks. I'll try the method.

##### Share on other sites
The key point here is that you explicitly need to append the primitives to your output stream to get anything out of GS to begin with. If you simply do not do the appending, the results of the current GS invocation will effectively be discarded.

##### Share on other sites
[quote name='Nik02' timestamp='1355744110' post='5011642']
The key point here is that you explicitly need to append the primitives to your output stream to get anything out of GS to begin with. If you simply do not do the appending, the results of the current GS invocation will effectively be discarded.
[/quote]
Thanks. It works.

##### Share on other sites

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