Sign in to follow this  
leonard2012

Discard primitives in geometry shader

Recommended Posts

leonard2012    167
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 this post


Link to post
Share on other sites
Nik02    4348
[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 this post


Link to post
Share on other sites
Nik02    4348
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 this post


Link to post
Share on other sites
leonard2012    167
[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 this post


Link to post
Share on other sites
Nik02    4348
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 this post


Link to post
Share on other sites
leonard2012    167
[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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this