This seems like a fairly basic and common problem. Is there a builtin way to achieve it or do I have to write the algorithm on my own? If I do, how should it work?
Not that I'm aware of (you're asking if there's some sort of glsl function that would do the conversion, right?)
It's a pretty simple conversion though, just three lines; here it is in pseudocode:
r = sqrt(x*x+y*y+z*z); theta = atan2(y,x); phi = atan2(sqrt(x*x+y*y),z);