Return darkest point in a b&w texture, both value and x,y screen coordinates.

I have a 2d greyscale texture that is constantly changing in screen space (Canvas set to Overlay)
I need to determine the darkest points in this texture and return a Vector contining

  1. x coordinate of this darkest point

  2. y coordinate of this darkest point

  3. actual value of this darkest point

Confused about what my next steps should be to accomplish this. Do I need a custom shader or…?

For starters… what if there is more than one pixel that is of the same colour, but is considered the ‘darkest’?

What is “darkest”… RGB is sort of difficult to measure “darkness” of since black (which is what I assume you mean by dark) relies on all 3 colour channels being close to 0. But like what… average the 3 channels? I’d argue 0x0000FF is brighter than 0x606060, despite technically it averaging less than that. As a result, I’d suggest maybe converting your RGB values to HSV or HSL and use the V or L (value or luminance, depending the colour space chosen) to measure “darkness”. Unity has a RGBToHSV method:

Do you want the vector in world space or just the pixels? If you want just the pixel coord, that’s relatively easy… find your pixel and that’s that. If you want the world space coord… well you’ll need to get the pixel coord and then transform it into world space.

Anyways, what you need to do next is define what it is exactly you’re looking for (consider my questions).

re more than one pixel

I’m making an assumption to simplify things that the image texture is a (greyscale) depth map representing an arm or hand pointing away from the camera.
Vector x,y float values in screen Space. Guessing will need some type of averaging or filtering to ensure this x,y position doesn’t jump too much.
…and z value would be a float representing actual value of darkest pixel(s).