Mapping a point in world space to a UV of a sphere

Hi. So the question is in the title.
I have an arbitrary point in space inside a sphere, let it be point A. I need to sample a texture color at the surface point closest to my point A. Imagine a vector going from a center of a sphere to the surface through point A . I need to know the color where the vector hits the surface.

My initial idea was to transform point A to spherical coordinates and have angles represent uv coordintes(mapped to 0-1 range). However, I can’t seem to get it to work.

Any help would be greatly appreciated!

That’s exactly what I was doing. For some reason texture appears tilted(rotated). And using 1-uv(x or y) or -uv(x or y) doesn’t seem to help.

It is rotated 90 degrees around z axis(the one looking at you).
I can “rotate” it around vertical axis by changing uv.x+ _Rotate. However, I can’t seem to find a way to rotate it around z axis.

For now I overcome this by rotating vertices in shader and later rotating the transform back. However, this seems like a dirty fix.

That sounds like you have a mesh that’s imported from a program using z up instead of Unity’s y up. In which case take the code in the above link and swap the .z and .y