Collision detection with depth buffer as only information

Started by
2 comments, last by spek 13 years, 9 months ago
Hi
I have a depth buffer as the only information of the geometrical constitution of a scene. I would like to know the best way to perform collision detection between an arbitrary object and the scene? Can I use the depth buffer directly or should I generate a collision mesh from it? What is the procedure to create such a mesh?


Thanks
Advertisement
Doing this in real-time will be a huge pain. I can only speculate that if you say wanted to do say a sphere intersection with the depth buffer, you would have to get every pixel in the depth buffer that could potentially have a depth that is with the sphere's range (front of sphere to back of sphere), once that list is compiled, you'd have to create 3d points based off the camera and projection from those pixels which could possibly be in range, then you'd have to see if those 3d points were within the radius of the sphere.

Same would go for a bounding box except you'd just see if the point was inside the box. Either way this is a lot to process per frame, especially when you would be looking for multiple collisions.
Let say that the scene is static except for the objects bouncing around; then the collision mesh didn’t have to be computed in real-time. Is there such algorithms?


If I would look into using depth buffer directly, I do have the beginning of an idea.
• Generate a normal map from the depth buffer.
• Use deferred rendering techniques to mask out the part of the normal map that is intersected with the “colliding object”.
• Use occlusion and/or extent queries to determine if any collisions have occurred.
• If so: The best thing I can think of after this is to proceed on the CPU, read the result from step 2 and compute the new velocity of the object based on the intersected normals and the old velocity?
Maybe this is an option:
- Render your scene with depth
- Render collision results, this can be done on a smaller buffer to gain speed & memory.
Render the object that can collide, turn off Depth-Testing, activate a special shader:
The shader will check if the object pixel is nearby the pixel from the background by comparing the distance. If it's close, give a red pixel(or any other color) as output. Otherwise draw green. A little bit like doing shadowmapping. Eventually use the remaining color channels to encode the object/group/bodypart ID so that you'll know which object collided afterwards. For example:
output.R = collision yes/no
output.GB= 16 bit object ID
output.A = object part ID (head, arm, ...)

- Last, analyse the image. You can boost this by downscaling it further maybe. When doing so, make sure your collision pixels(and ID info) remains intact (don't blur them with "no-collision" neighbour pixels). The smaller the image, the faster the (CPU) analysis, but also the less accurate of course. Read out all pixels, and then loop through it. This should give info about which and where the collisions are.
- Eventually use MRT in the collision-check step to write the exact collision coordinates/normals/forces to a secondary texture.

Keep in mind this doesn't work in scenes with multiple layers of depth (walls behind walls). Once your object is behind (not intersecting) another thing, you won't know what is going on there.

Rick

This topic is closed to new replies.

Advertisement