transform world space normals to screen space normals
Asked Answered
S

3

10

What is the proper way to transform surface normals defined in world space to normals in screen space? I don't think they can simply be multiplied by the projection matrix, because perspective division transforms things into clip space and as far as I understand, in this space planes that are coplanar to the image plane remain coplanar.

But the transformation I'm looking for should result in transformed normals such that the blue world normals depicted in graphic A should result in differing screenspace normals (because, even though their planes are coplanar to the image plane, they do not face the camera) - on the other hand the depicted normals in graphic B should after the transformation be (more or less) equal, since their surfaces face the camera.

enter image description here

What transformation am I looking for? how to calculate it?

I need this for some screen-space effects.

Sprague answered 14/1, 2013 at 11:10 Comment(1)
Your examples are wrong. That is not how screen space looks nor works. It's a projection onto a plane, not onto a sphere.Unfavorable
S
1

You're looking for Transformation Matrix with Respect to a Basis. There is quite fine video about steps how to calculate this matrix. Check KhanAcademy video.

EDIT

You didn't provide any information about technology which are you using (OGL, DX, shaders, own projection, ...), but you should definitely read some articles about tangent space, e.g. Messing with Tangent Space..

Surculose answered 14/1, 2013 at 13:41 Comment(2)
I know how to transform normals from tangent space to object space or world space or vise versa. This doesn't cover screenspace thoughSprague
But how are connected normals of some objects with screen space..? Normals are always normals, doesn't matter from which point are you looking on them..Surculose
A
1

Try to do it as usually done when transforming normals from model(to view) space - using inverse-transpose matrix.

Ankh answered 14/1, 2013 at 13:52 Comment(6)
this doesn't cover my issue. This is about properly transforming normals to eye space. This is not about projectionSprague
yes, I see it's not that simple. in your case result of normal transformation depends on the position of the surface which has this normal...Ankh
@user1282931 - could you perform your screen-space effects in eye space?Ankh
exactly - the origin of each normal vector affects the result! no, I cannot perform them in eye space. I need to calculate lookups into a texture based on screenspace normalvectorSprague
then maybe simply transform(project) origin of a normal and another point(origin shifted by that normal). and then having these two transformed points recalculate normal in projection space.Ankh
Beware that the transformed normal is a curve, it's no longer a line. So if you pick an arbitrary point along the normal, transform it, and then connect to the transformed origin, you'll get an approximation at best, but not the accurate projected normal. That one is a limit of the transformed difference with the original offset approaching zero.Preceding
P
1

Supposing you want to transform the normal N at point P by an arbitrary 4x4 matrix. Let's represent the matrix with the model part T (having rotation, scale, and translation) and the part with the last row as W. This allows us to say that:

Transform(P) = (T * P) / dot(W,P)

Now, the projected normal can be seen as a limit(d -> 0) of:

(Transform(P+dN) - Transform(P)) / d

Expanding this equation and then crossing out "d" from both nominator and denominator leads to this formula:

dot(W,N) * (Transform(N) - Transform(P)) / dot(W,P)

This is untested and unverified, but I thought given the lack of positive answers to this question I'd give it a shot ;)

Preceding answered 15/8, 2017 at 22:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.