Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

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


Sign up now

Discard primitives in geometry shader

4: Adsense

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.


  • You cannot reply to this topic
5 replies to this topic

#1 leonard2012   Members   

167
Like
1Likes
Like

Posted 16 December 2012 - 08:12 AM

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.

#2 Nik02   Members   

4312
Like
0Likes
Like

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


#3 Nik02   Members   

4312
Like
0Likes
Like

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


#4 leonard2012   Members   

167
Like
0Likes
Like

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 Nik02   Members   

4312
Like
0Likes
Like

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


#6 leonard2012   Members   

167
Like
0Likes
Like

Posted 17 December 2012 - 08:42 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.

Thanks. It works.




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.