Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been struggling to get this working. I simply wish to take a surface normal and convert it to a screen angle.

As an example, assuming we're working with the highlighted surface on the sphere below, where the arrow is the normal, the 2D angle would obviously be PI/4 radians.


Here's one of the many things I've tried to no avail:

float4 A = v.vertex;
float4 B = v.vertex + float4(v.normal, 0.0);

A = mul(MVP, A);
B = mul(MVP, B);

A.xy /= A.w;
B.xy /= B.w;              

o.theta = atan2(B.y - A.y, B.x - A.x);

I'm finally at my wit's end. Thanks for any and all help.

share|improve this question
The code you posted looks like it should work. Can you be more specific about how it's not working? Maybe you can add some debug output of the intermediate values? For instance, plot A and B in screen space after transforming and projecting them, so you can see visually if they're getting the right values. – Nathan Reed Jul 2 '13 at 4:52
You're entirely correct. I was just using my own code improperly. Thanks. – Tannz0rz Jul 2 '13 at 5:12
The screen angle is not “obviously” pi/4. It is closer to pi/6, actually. The normal vector always lies on a line that goes through the centre of the sphere. Here is a more accurate drawing. – sam hocevar Jun 8 '14 at 19:18

This depends on your camera. So if the camera is directly facing the object, you can do this. The surface normal is lets say (x,y,z). z meaning the depth. Then just make z = 0, as if you are projecting it in to plane. Then angle is simply atan2(y,x). This is for the simplest case though. IF the camera is not aligned with the object then you have to figure out a more complex projection.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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