Color Picking Method for selecting primitives..

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

Well, the first thing I think of is that you can draw and pick for each object separately

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.

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

or using the idea inside Inferred Lighting, which could restore 4 object layers for each pixel.

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.

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?

Cool. Please let me know how it goes.

Take care,
Patrick

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?

Cool. Please let me know how it goes.

Take care,
Patrick [/QUOTE]

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.

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’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