<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx</link><description>Ladies and gentlemen, I hereby present my final joke of 2008: Q: what do you get if you cross a stencil buffer with an occlusion query? A: pixel perfect collision detection! Ok, the joke sucks. But I think the technique has merit: Temporarily disable</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9435368</link><pubDate>Fri, 20 Feb 2009 06:28:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9435368</guid><dc:creator>kanno41</dc:creator><description>&lt;p&gt;Is there any way to make this work correctly on the 360 by chance?&lt;/p&gt;
&lt;p&gt;Please email kanno41 (at) gmail.com&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9436232</link><pubDate>Fri, 20 Feb 2009 19:55:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9436232</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;kanno41: I don't understand what you mean? Occlusion queries work fine on Xbox.&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9460381</link><pubDate>Thu, 05 Mar 2009 21:44:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9460381</guid><dc:creator>khayman218</dc:creator><description>&lt;p&gt;I am using the AnimatingSprite class from the RPG starter kit on XNA. &amp;nbsp;When I use this post's method for two of those, it doesn't seem to ignore transparent pixels. &amp;nbsp;The collision count is the overlap of the entire destination rectangle of the animations.&lt;/p&gt;
&lt;p&gt;Is there something I should be doing different if the sprites are animated?&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9460397</link><pubDate>Thu, 05 Mar 2009 21:53:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9460397</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;khayman218: this technique relies on alpha testing being used to reject any pixels that are not supposed to be tested. It won't work if you have alpha testing turned off for some reason, or if your sprites just have fractional alpha values rather than true zero alpha.&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9468754</link><pubDate>Tue, 10 Mar 2009 10:00:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9468754</guid><dc:creator>khayman218</dc:creator><description>&lt;p&gt;Ok, that makes sense. &amp;nbsp;Thanks for the help. &amp;nbsp;Unfortunately, I do have another issue now. &amp;nbsp;The collision detection is working correctly up until the first collision (i.e. when pixels first overlap). &amp;nbsp;After the first one, the query never resets to 0 even when the sprites are drawn on opposite ends of the screen. &amp;nbsp;I suppose my stencil buffer is never being reset entirely, because the pixel collision count is always about the peak number (and subsequent collisions in new areas of the buffer increase the query return value). &amp;nbsp;I even tried disposing and reallocating the query each time, but the return value was always the cumulative peak. &amp;nbsp;What is the best way to ensure my buffer is being cleared between collisions test?&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9468769</link><pubDate>Tue, 10 Mar 2009 10:21:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9468769</guid><dc:creator>khayman218</dc:creator><description>&lt;p&gt;I also tried removing this line: &lt;/p&gt;
&lt;p&gt;GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.None;&lt;/p&gt;
&lt;p&gt;so that I could see where I was testing the collision. &amp;nbsp;When writing to the screen during the collision test it was clear the sprites were not touching, yet the query continued to return the max number of colliding pixels (from when they were visibly touching).&lt;/p&gt;
&lt;p&gt;Just to make things clearer, here is a video of the test app I am using. &amp;nbsp;The vectors are the screen positions of the sprites. &amp;nbsp;The red text is the result from the collision detection query. &amp;nbsp;The detection query is run on every update and displayed when the value returned is not zero.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.youtube.com/watch?v=6Ye0BAFhhZg"&gt;http://www.youtube.com/watch?v=6Ye0BAFhhZg&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9468828</link><pubDate>Tue, 10 Mar 2009 11:41:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9468828</guid><dc:creator>khayman218</dc:creator><description>&lt;p&gt;I was able to get the desired functionality. &amp;nbsp;I had to insert the following code to clear the stencil buffer to 0s before drawing the first sprite to it:&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gDevice.RenderState.StencilFunction = CompareFunction.Always;&lt;/p&gt;
&lt;p&gt;gDevice.RenderState.StencilPass = StencilOperation.Replace;&lt;/p&gt;
&lt;p&gt;gDevice.RenderState.StencilFail = StencilOperation.Keep;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;gDevice.RenderState.ReferenceStencil = 0;&lt;/p&gt;
&lt;p&gt;sbatch.Begin();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sbatch.Draw(TextureManager.Instance.GetTexture(&amp;quot;shadow&amp;quot;), new Rectangle(0, 0, gDevice.Viewport.Width, gDevice.Viewport.Height), Color.White);&lt;/p&gt;
&lt;p&gt;sbatch.End();&lt;/p&gt;
&lt;p&gt;After that I continue your code sample to draw the first sprite for detection. &amp;nbsp;Is this necessary or do I need to read a lot more about the stencil buffer and querying it? &amp;nbsp;Is there possibly a more graceful way to clear the stencil buffer?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
</description></item><item><title>re: Pixel perfect collision detection using GPU occlusion queries</title><link>http://blogs.msdn.com/shawnhar/archive/2008/12/31/pixel-perfect-collision-detection-using-gpu-occlusion-queries.aspx#9469333</link><pubDate>Tue, 10 Mar 2009 20:07:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9469333</guid><dc:creator>ShawnHargreaves</dc:creator><description>&lt;p&gt;GraphicsDevice.Clear can be used to clear the stencil buffer. Just make sure you specify that it should clear stencil (via the ClearOptions parameter).&lt;/p&gt;
</description></item></channel></rss>