The best way to highlight some part of UV?

Hi there! I have texture with different colors, and I want to highlight, lets say, only blue color, when the mouse is on top of it. Is that possible to do via shader?

I can pass mouse coordinates.
And somehow check inside surface shader, what pixel color do I have under mouse.
And then probably in the next pass highlight those pixels with this only color on the UV map.

Well that is the idea, maybe that is not the best approach and something better might be recommended?

Also, as I imagine, there is no way to return data from shader to Unity? Like, I can not let my C# script know, that right now we are highlighting blue color on the UV mask?

Maybe Raycast has to be used to get that pixel data?

This is definitely possible using a combination of CG and C#. I have made a similar system a while ago (for a project pretty similar to what you’re working on, actually).

You can find the uv coordinates by firing a ray at a mesh collider that uses the mesh you want to apply the highlighting to. Then you can get the color of texture it uses at those coordinates with GetPixel.
You can pass that data to a shader. In the pixel or surface shader, you can then do a texture lookup, and apply any effect you’d like to the pixel if it is the color you selected.

Keep in mind that textures are usually compressed before they are sent to the GPU, so testing for an exact match might result in rough edges of the highlight near changes in color.