Obtain World Coordinate from Color

I’m trying to get all world coordinates of a specific color in the world.
How would I do this in C++?

Assuming that the color may be generated by any shader or (post-)effect, you probably would have to get the screen buffer and do raycasts for all screen coordinates with pixels of the desired color to get the world coordinate. Please be aware that this approach will be very performance consuming and probably is not a good choice for real-time, especially if it is possible that there are many pixels with this color.

So my advice would be to evaluate if there are other solutions possible for your use case (e.g. add tags to all objects in question so you can get their world coordinates from scene graph. see )