Aeva / m.grl

Midnight Graphics & Recreation Library
http://mgrl.midnightsisters.org
GNU Lesser General Public License v3.0
44 stars 3 forks source link

Improve object picking performance #192

Closed Aeva closed 7 years ago

Aeva commented 8 years ago

An interesting performance bottleneck was made evident by #189, wherein when static drawing a largish number of objects, performance would be about 60fps until a picking pass was invoked, at which the frame rate would drop very sharply.

Picking performance could be improved in a lot of ways:

wijnen commented 8 years ago

Also, I'm not sure how much overhead the location info costs, but given that it must be switched on, I take it that it's significant.

From a practical standpoint it seems to me that this should be defined per object, not as a global setting. For example, in a board game it may be useful to get coordinates when clicking on the board, but you don't care when clicking on one of the pieces.

So perhaps you should consider moving skip_location_info from graph.picking to every (leaf) node.

Aeva commented 8 years ago

The idea for having it per graph is that you likely would be using simplified geometry for the picking pass. so one would use a different graph for rendering vs picking.

Location info currently requires a 3rd pass on top of object picking, though now that I have a mechanism for multiple render targets in place, the two could be consolidated on systems that support it.

wijnen commented 8 years ago

Yes, I expected that a 3rd pass was required, that's why I suggested to make it object-based; then the 3rd pass can be skipped if the object doesn't need it.

If both passes are bundled, there is no need for that, of course.

Aeva commented 8 years ago

the reason why it draws the entire scene instead of just the individual objects needed for picking is because if a pickable object is occluded by another object (pickable or otherwise), then it should not be something you can select.

wijnen commented 8 years ago

For the third pass this is not relevant; it was established in the second pass that the click did land on the object. Rendering only that object may be wrong for other pixels, but you're only going to look at the same pixel as in the second pass, and that pixel is guaranteed to be visible.

This isn't what I was talking about though. I'll give an example to hopefully be more clear. I made a game with 16 pieces and a board. Players click on a piece to select it, or on the board to place it. When a piece is clicked, I do not care about the location of the click. If the board was clicked, I need to know which square was clicked.

In the current system, because the board needs to know the location, I must set graph.skip_location_info=false. But this means that the third pass is always activated on click, both for the board and for the pieces. In case of the pieces, this is a waste of resources.

That's why it seems to me that it would make sense to set skip_location_info on the object that has selectable=true instead of on the graph. Then the third pass would only be activated when the board is clicked, not when the pieces are clicked.

Aeva commented 8 years ago

Oh! I think I get what you're saying. Let me make sure I understand correctly, what you're proposing is that "skip location info" should be a per-object setting rather than a global setting? That seems sensible.

wijnen commented 8 years ago

Yes, exactly.

Aeva commented 8 years ago

Ah! yes that is a good idea. I will include it for this feature :D I updated the above checklist.