I implemented color picking recently and I would like to use it as kind of highlight when mouse is over an object but I am concerned about performance. Color picking requires whole frame to be drawn, loosing effectively up to half of performance (MouseMove can happen nearly every frame).
Also, when mouse moves it is very likely to be nearly above previous point - is there any way how to use this fact to improve performance of 3D picking? Or is my best chance to use some other technique of 3D picking or approximation of results?
tl;dr If I wanted to do "realtime" 3D picking - on MouseMove, what is the best technique for doing so performance-wise?
EDIT: the exact numbers are even worse, when rendering 1m triangles render time increase from 1.5ms to 2-6ms and in spikes up to 15ms.
Answer
Considerations:
A. Do the color-frame less frequently, for example at 10 fps (every 6th frame if you run at 60fps). Small lag won't be that noticeable;
B. Render color-frame at lower resolution, e.g. 1/4, if you don't need pixel-perfect precision;
C. Render only one pixel that you need below the cursor. I'm not confident with the math, but surely there's a way to setup a view/projection matrix to take a tiny portion from the full view/projection matrix. If done right, frustum culling will reduce a lot too - meaning less overhead of unpickable objects ever getting sent to render at all;
D. Make sure you strip off any unnecessary parts and computations, alike non-pickable objects;
E. Forget about color-picking and switch over to Ray-Object intersection technique.
No comments:
Post a Comment