Pixel Perfect OpenGL Picking

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
4,053
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Dec 20, 2008

I was frustrated with GL_SELECT and with the way I was implementing picking prior to today. So I decided to rewrite picking in my graphics engine.

Now a ray is generated by using gluUnProject with the mouse coordinates. This ray is then checked against a quadtree for intersections. The quadtree recursively searches through the tree until all the intersected objects are found. Then the objects that are intersected (via AABB intersection test) are drawn in a shader that outputs a color to the screen. This color is then read back using glReadPixels to get the correct object.

In this video you can see the picking going on behind the scenes. Then I switch on AABB drawing, which allows you to see the bounding boxes. Finally I switch on the shader drawing so that you can see how the shader outputs a color per model. The color is set via a shader attribute.

Sorry for the random music. I was listening to VLC and didn't realize Fraps captured that audio.

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (Giawa)

  • Why was GL_SELECT frustrating you?

  • GL_SELECT worked for me, but was extremely slow. I did some research and it seems like newer cards do not do a good job of running in GL_SELECT mode. I was seeing a drop from 1200fps to around 120 fps. This was too big of a hit to take in performance.

    I tried the code on an older GeForce 5600 and hardly noticed any drop in frame rate. So somewhere between the 5600 series and the 9800 series, the GL_SELECT method became somewhat 'obsolete' (for lack of a better term).

  • Smooth technique :)! I'm having to do with picking in my game as well, but the projection is axonometric. I'll try and implement something simpler.

  • Thanks for the comment :) Your physics engine work is very impressive. I like the style.

  • Can you share the source code to what you did as an alternative to the GL_SELECT

  • Hi meddeco1. I'm not able to share the entire source code. However I'm working on writing up a tutorial on how it works along with some code samples. Maybe one day I'll make it open source. I'll let you know when I make that tutorial available. Until then, the information on the video describes the process I use quite in-depth. Good luck!

see all

All Comments (9)

Sign In or Sign Up now to post a comment!
  • @zeusLT for example if you develop your own game and are at 1200 fps and add 1000 triangles to your scene you may drop to 200 fps instantly while it would only drop to 59fps if you were at 60fps. Frame rate is exponent, you have to know that when you work with anything that involve frame rate if you dont want any surprise.

  • @zeusLT i dont see what this has to do with the comment i left.... the difference between 120 fps and 1200 fps is still about the same as the difference between 59fps and 60fps

  • @UnIXbLueStar

    think about the difference when computer can run max 1200 fps with this method, and 120 fps with GL_SELECT..

  • @Giawa the difference between 1200 and 120 fps is about the same as the difference between 60 and 59fps.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more