Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 00:27

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 06.09.2010, 10:06 
Offline

Joined: 26.10.2008, 03:19
Posts: 6
Draw the scene, without any antialias, light or anything, just each node having a different solid color (the color can be just the node number). Then pick the color of the pixel beneath the mouse cursor. This way you can also pick nodes underneath other objects with alpha maps, just clamp the alpha to be 1 or 0.

Then you can get the 3D position of the pick by drawing the object alone with the RGB colors mapped to XYZ position.

Of course, this can be optimized by rendering only the pixel beneath the cursor. Also each node should have a "pickable" flag.

Is it easy to implement?


Top
 Profile  
Reply with quote  
PostPosted: 06.09.2010, 12:29 
Offline

Joined: 08.11.2006, 03:10
Posts: 384
Location: Australia
Yep this is pretty easy to implement. You can access the current node ID in the pixel shader and encode that number to a 32bit render-target. Then you can read-back that render-target to the CPU and decode the 'color'.

This kind of picking has been used a bit for some tools I know of (where you only need one picking operation every few seconds), but it's too slow to use in a game. Rendering the scene incurs quite a large CPU-side cost, and reading back data from the GPU often stalls both the CPU and the GPU.

Another common practice is to use a dedicated collision detection library / physics engine for ray-casting.


Top
 Profile  
Reply with quote  
PostPosted: 06.09.2010, 13:59 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
DiThi wrote:
Is it easy to implement?
It can still be quite tricky to get right. In particular, you need to be very careful about precision and colour space conversions - passing your colour buffer through an sRGB conversion, or an 8-bit colour buffer, may heavily change the colours, to the point that they do not match the colours you specified.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 06.09.2010, 15:34 
Offline

Joined: 26.10.2008, 03:19
Posts: 6
The scene is rendered 10-60 times per second anyway. What if the shader just colors the pixel underneath the cursor instead of rendering the scene again? Then you read the pixel before drawing the cursor and flipping. This way you could have a pick every frame.

edit: Is it possible to have the x/y coordinates of the screen in the fragment shader?
edit2: oh, gl_FragCoord


Top
 Profile  
Reply with quote  
PostPosted: 06.09.2010, 15:58 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
DiThi wrote:
The scene is rendered 10-60 times per second anyway. What if the shader just colors the pixel underneath the cursor instead of rendering the scene again?
Doesn't work like that - to determine the colour to make the pixel under the cursor, you have to render all pickable geometry.

This technique works fine for simple demos, but or anything serious I would recommend integrating a collision/physics library to handle this sort of thing...

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group