Hello Sergey,
I apologize, seems I formulated the task not entirely correctly.
The regular search algorithm will not work, since I need the nearest surface of the sphere, not the nearest center of the sphere.
For example, if I need only 5 nearest spheres, then there is no chance for the red sphere to get into the search results, even if I specify a search number 5 times greater. This is despite the fact that the red sphere is the nearest!
But you suggested to me a good idea. I will try to create several kd-trees, separately for large, medium and small spheres. Hope this works.
But I heard that there are search algorithms for rendering that are just looking for triangles nearest to the camera. Perhaps this is what I need.
Maybe you know similar algorithms, and where to find them?
Anyway, thanks for the reply.