Mapping a flat grid to the World background (cartesian to spherical coordinates with shader nodes)

Hi, I’m trying to create a procedural grid for a World background. I could easily create a procedural grid texture using Brick Texture node, but now I have to convert it’s coordinate system to map it to a sphere. The desired result would be like this UV Sphere (grid is pinching at the top and bottom), but for the World. I think what I need to do is to convert from cartesian coordinates to spherical coordinates. I’m finding multiple formulas for that but none have worked for me. Here is a few screenshots of what I want (basically replicating the UVmap projection of a UV sphere) but with shader nodes. Does anyone has any clue on how to do this? Any help with the math would be greatly appreciated!

PS: I’m not looking for an easier solution, I want to do this in procedurally in World shader nodes.




image

first nodes set up
how do you do the UV sphere unwrap ?

second nodes set up
this is added to the world nodes
and what should it look like ?

thanks for feedback
happy bl