PDA

View Full Version : Color Picking Method for selecting primitives..



rakesh_thp
11-12-2009, 04:39 AM
Hello,

I am using color picking method to select a primitive in my application.. At present it is picking only single object.. I just wanted to clarify few doubts..

It is working fine when i click on a single object.. I mean if there are two objects lying on the same pixel.. And if i click that pixel, then i get only one object.. How can i get both the objects, using this method..?? Is it possible..??

THanks in advance

AdrianPi
11-12-2009, 06:54 AM
Well, the first thing I think of is that you can draw and pick for each object separately

pjcozzi
11-12-2009, 07:42 AM
You are only getting the top most object, which won the depth test. A straightforward way to get all objects under the pixel is to remove the object that was picked, then render the scene again. Continue this process until no objects are left (e.g. you get the clear color). Alternatively, you can render each object individually and do the sort on the CPU, which I've done here (http://blogs.agi.com/insight3d/index.php/2008/03/05/picking-using-the-depth-buffer/).

If you are interested, shrink the view frustum to fit around the pixel(s) and perform culling to provide a significant performance gain.

Regards,
Patrick

LangFox
11-12-2009, 05:53 PM
or using the idea inside Inferred Lighting, which could restore 4 object layers for each pixel.

Heiko
11-13-2009, 02:53 AM
You are only getting the top most object, which won the depth test. A straightforward way to get all objects under the pixel is to remove the object that was picked, then render the scene again. Continue this process until no objects are left (e.g. you get the clear color). Alternatively, you can render each object individually and do the sort on the CPU, which I've done here (http://blogs.agi.com/insight3d/index.php/2008/03/05/picking-using-the-depth-buffer/).

If you are interested, shrink the view frustum to fit around the pixel(s) and perform culling to provide a significant performance gain.

Regards,
Patrick

Just read your article and read the comments on how to use one pixel for each object. I was wondering whether it might be possible to use the geometry shader to draw each pickable object that falls within the frustum to a different layer in a 3d texture / array of textures.

I'll probably gonna implement your technique and maybe I'll have a go at the possible improvement I came up with.

pjcozzi
11-13-2009, 05:37 AM
I was wondering whether it might be possible to use the geometry shader to draw each pickable object that falls within the frustum to a different layer in a 3d texture / array of textures.
Interesting idea. How large would you make the depth of the 3d texture (or equivalently the length of the array)? How would you know which texture to write to?


I'll probably gonna implement your technique and maybe I'll have a go at the possible improvement I came up with.
Cool. Please let me know how it goes.

Take care,
Patrick

Heiko
11-13-2009, 01:47 PM
I was wondering whether it might be possible to use the geometry shader to draw each pickable object that falls within the frustum to a different layer in a 3d texture / array of textures.
Interesting idea. How large would you make the depth of the 3d texture (or equivalently the length of the array)? How would you know which texture to write to?


I'll probably gonna implement your technique and maybe I'll have a go at the possible improvement I came up with.
Cool. Please let me know how it goes.

Take care,
Patrick

I was thinking about handing over a uniform integer value for each object that is possibly picked. This integer tells the geometry shader in which layer to draw. After reading back the texture the same integer will be used to read out the right pixel for the right object.

I've never tried writing to different layers in the geometry shader though, but I was told that it is possible a while ago. So I have to look into it what is and what isn't possible.

pjcozzi
11-14-2009, 09:01 AM
I was thinking about handing over a uniform integer value for each object that is possibly picked. This integer tells the geometry shader in which layer to draw.
Keep in mind that the maximum number of objects needs to be reasonable. What is the biggest dimension for textures on recent hardware? 8K? Perhaps, you know an upper bound and you can just allocate a texture array once. Otherwise, consider using two passes: In the first pass shrink the view frustum to fit around the pixel(s) and perform culling to determine your potentially visible objects. Then allocate a texture array based on the number of potentially visible objects, which is likely to be much less than the number of total objects. Now render the potentially visible objects.


I've never tried writing to different layers in the geometry shader though, but I was told that it is possible a while ago. So I have to look into it what is and what isn't possible.
I'm not sure either. I'm looking forward to hearing your results. I'm curious to hear if the extra complexity is worthwhile, especially if you need to do the multipass approach I mention above.

Regards,
Patrick