Skip to main content
GameDev.net gamedev.net
🔒 Locked

Occlusion query as collision test

Started by iliak Jun 17, 2010 at 9:57 AM 0 replies 1.4k views
Original Post
iliak
iliak
I managed to use Occlusion Query to do 2d per pixel collision test on the GPU (ARB_Occlusion_Query). It works really well but now I want to go further. I want to know where on the sprite (it's a 2d app) the collision occured.

Here's an example : Let's imagine a space shuttle inside an horizontal tunnel like this :



I know when the sprite collide with the tunnel, but I don't know if it's the upper side or the lower side who collided...

Any idea ?
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
samoth
samoth
Although occlusion queries are not intended for that, you could get what you want like this:
1. begin query, draw upper wall, end query
3. begin query, draw lower wall, end query
4. enable z-buffering
5. draw ship and be sure to give it a non-null z coordinate
6. disable color writes, use most trivial pixel shader possible
7. begin query, draw upper wall again, end query
8. begin query, draw lower wall again, end query

If the result of the query in (7) is smaller than the result of (1), the ship hit the upper wall. If the result of (8) is smaller than the result of (2), the ship hit the lower wall. In any other case, it is somewhere in between.
Note that disabling color writes in (6) to save some fillrate is possible because occlusion queries count the fragments that passed the depth test, it is not necessary to actually write them out (although you could do that anyway).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.