Skip to main content
gamedev.net
🔒 Locked

Picking method and how to implement - backbuffer

Started by ktuluorion Mar 7, 2004 at 8:53 PM 5 replies 950+ views
Original Post
ktuluorion
ktuluorion
OK, someone had told me that a good way to do your picking is to render the scene twice, once to display, then once on the backbuffer with different colors representing each pickable item, then testing a click against the backbuffer to see if you have a hit. Can anyone point me to which DX 9.0 commands I would need to implement this? I mean, how do you render to the backbuffer? How do you get what color lies at a certain spot on the backbuffer? Does anyone have a link that explains this process? Thanks!
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
TreborZehn
TreborZehn
I''m pretty new to this stuff but I think everything you render will render to the backbuffer (if you''ve initialized to have a backbuffer) the "Present" function is what finally moves the image to the front buffer.

As for the suggestion to re-render each scene to the back-buffer that seems like a lot of overhead. You''d probably be better off making approximations such as surrounding an object by a sphere/box and then doing some math to check for intersections.

(I don''t know how to pick a color from the backbuffer.)
"Good code will come and go, but bad code sticks around."
Teric
Teric
Have you tried true 3D picking? It''s actually not that difficult. Take a look at the 3D Pick example in the DX9 sample browser.

Be aware, however, that the example only tells you how to pick a mesh that is located at the origin (0,0,0). You''ll need to transform your pick ray into object space in order to pick a translated/rotated object.
I am always open to feedback, positive or negative...
ktuluorion
ktuluorion
The method actually shouldn''t be all that bad, because I will implement it in this way:

First of all, I will render the geometry with no lighting, no textures, etc. Just colors, with one color value seperating them. i.e. I will start with 1,0,0. The next will be 2,0,0. Then 3,0,0. Etc.

Also, I will probably do the backbuffer like once every second, instead of each time the scene is rendered.

Really though, I need a way to grab the backbuffer, and a way to check what the pixel in a spot is.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
neneboricua19
neneboricua19
Reading data from the back buffer is *very* slow. But if you''re dead set on doing it this way, then you''ll need to call GetBackBuffer. You will get back a pointer to a surface. You''ll then need to lock this surface to read the actual pixels stored there. Remember to do this before you call Present.

neneboricua
ktuluorion
ktuluorion
quote:
Original post by neneboricua19
Reading data from the back buffer is *very* slow. But if you''re dead set on doing it this way, then you''ll need to call GetBackBuffer. You will get back a pointer to a surface. You''ll then need to lock this surface to read the actual pixels stored there. Remember to do this before you call Present.

neneboricua


10-4

Thanks! I''ll post back here if I encounter any problems, but I believe I can do that.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest o
Nik02
Nik02
Note that locking the backbuffer decreases rendering efficiency by at least 25% (depending on how many cached frames the driver keeps). This happens because the device doesn't have access to the locked data, and cannot use it to render things (and this, in turn, breaks parallelism - otherwise known as simultaneous calculations with gpu and cpu).
I'm a faithful believer of the fact that when dealing with modern cards and processors, true 3d picking is the faster method.

-Nik

EDIT: The inefficiency I mentioned is in addition to the fact that it is slow to read back from the card altogether.

[edited by - Nik02 on March 9, 2004 1:27:04 AM]
Niko Suni

Topic Locked

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

Sign in to reply to this topic.