1
$\begingroup$

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;
float radius = world_position.z

gl_Position = vec4(radius * vec3(sin(theta)*cos(phi), sin(phi), cos(theta)*cos(phi)), 1.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.

How do I use the angles to rotate the normals so they match the rotations of the vertices?

$\endgroup$
1
$\begingroup$

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})$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.