Surface normal to screen angle

Posted by Tannz0rz on Game Development See other posts from Game Development or by Tannz0rz
Published on 2013-07-02T04:46:44Z Indexed on 2013/07/02 5:14 UTC
Read the original article Hit count: 271

Filed under:
|
|
|
|

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.

Sphere

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(VP, A);
B = mul(VP, B);

A.xy = (0.5 * (A.xy / A.w)) + 0.5;
B.xy = (0.5 * (B.xy / B.w)) + 0.5;              

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.

© Game Development or respective owner

Related posts about math

Related posts about shaders