Pixel Perfect Picking in OpenGL 4.2

Hey everyone!

[youtube_sc url=S3f4oy-EFUQ width=240]

This video is long overdue 😉 I implemented picking in the fall of last year 😉 But for the video to look nice, I wanted to show that we could pick through transparent objects.
So I had to implement those first, since we didn’t support alpha rendering yet 😛 We still don’t support translucency btw. More on that later 😉

Aside from transparency, we now also support additive blending on object level, and emissive rendering on object level. This allows for more visual effects, which our scripters love 😉

But back to picking! We first cast a 3D ray through the scene to see which objects we potentially hit. We then render the objects that intersect with the ray, to an offscreen frame buffer object, using some very basic shaders. In this buffer object, we encode an identifier for the object, so that if 2 objects are hit by the ray, we can later figure out which one was rendered in front of the other. We also render the distance from the pixel we render, to the camera, in the frame buffer, so we can calculate the exact world coordinate of the point where we “hit” the object.

We also use a scissor technique to only render the single pixel we hit on the screen. This makes the picking “query” very efficient.
We then read the pixel value back from our frame buffer, to see if the object was hit, and where it was hit. The system does support multiple cameras, view ports and scenes overlapping without issue.

Hope you like the video!


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment


Creative Commons License
This work by piko3d.net is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License
Powered by WordPress