# Wrapping normals around a sphere

I'm using a vertex shader to effectively wrap vertices on a sphere. Starting with world_position already after multiplying the vertex by the model transform matrix to get the coordinates in world space, I calculate the new position via an inverse Mercator projection:

float theta = 2.0 * PI * world_position.x / world_radius;
float phi = 2.0 * atan(exp(world_position.y / world_radius)) - PI / 2.0;

What I now need to do is take these angles, $$\theta$$ and $$\varphi$$, and use them to transform the normals as well. I've tried creating a rotation matrix to represent rotation first around the Y axis (for $$\theta$$) and then around the X axis (for $$\varphi$$), and multiplying that by the vertex's normal (after multiplying the normal by the model matrix's inverse transpose), but that didn't give the results I expected.
Turns out I needed to be looking at the former normal as a unit vector $$(\hat{r}, \hat{\theta},\hat{\varphi})$$, and then use a rotation matrix as outlined here to find $$(\hat{x},\hat{y},\hat{z})$$.