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.
Discard primitives in geometry shader
Started by leonard2012, Dec 16 2012 08:12 AM
5 replies to this topic
Ad:
#2 Members - Reputation: 1988
Posted 16 December 2012 - 01:44 PM
[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
}
}
Niko Suni
Software developer
Software developer
#3 Members - Reputation: 1988
Posted 16 December 2012 - 01:47 PM
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, 16 December 2012 - 01:48 PM.
Niko Suni
Software developer
Software developer
#4 Members - Reputation: 145
Posted 16 December 2012 - 08:55 PM
[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
}
}
Thanks. I'll try the method.
#5 Members - Reputation: 1988
Posted 17 December 2012 - 05:35 AM
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.
Niko Suni
Software developer
Software developer
#6 Members - Reputation: 145
Posted 17 December 2012 - 08:42 AM
Thanks. It works.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.






