# What are projection independent ways of determining whether a normal is facing the viewer?

A position v and normal n are given in world coordinates. Also there is a view matrix V for world-eye coordinate transition and a projection matrix P for eye-ndc transition. I would like to determine, whether the normal is facing the viewer.

If we assume that P is a perspective matrix, we can compare the normal direction with the direction to the viewer, both in eye-space. Note that the approach won't work for an orthographic projection, because there is no well defined eye position. But if P is orthographic, we only need to check the Z coordinate of n in eye space. Nevertheless, I'm seeking a solution that does not make assumption about what projection type we're using.

One way of achieving this is to compute the inverse P' of P and retrieve the viewing direction as a vector spanned between P' [u.x, u.y, -1] and P' [u.x, u.y, 1], where u is v transformed to ndc. The drawback here is that it requires inverting a matrix and in my case also passing it to the shader.

Another solution would be to construct a small triangle around v within the normal plane of n, and check what's its winding direction in the ndc. The problem with this approach is that it's computationally heavy and it's still seems to me more like a hack than a proper solution.

I am not very satisfied with these two solutions. Do you have any other ideas? Am I missing something very simple?

EDIT: Since it seems unclear why the dot(v - eye, n) < 0 is not satisfactory in my case, I post an exaple showing the difference between perspective and ortho projection for this particular problem.

As you can see, the vector is facing slightly away in the perspective projection, but clearly towards in the orthographic projection. More specifically, a face having that particular normal would be culled in perspective, but not in ortho.

• or just get the position of the eye and dot(eye-v, n)>0 Commented Mar 7, 2016 at 11:17
• Also keep in mind that, if you only use this value in a pixel shader, the active cull-mode will have already discarded any back-faces (the "small triangle" test you mentioned is already being performed). So, depending on where you use it, you might already know, without asking.
– Jon
Commented Mar 7, 2016 at 12:46
• I think you should clarify the question to include your purpose. You don't actually intend to figure out if the face is pointing towards the point in space the viewer is at. It seems like you want a perspective independent way of determining whether a face would be culled, which I think has a simpler answer of there isn't one. Commented Apr 6, 2016 at 21:08

You can get the position of the eye and test dot(eye-v, n)>0.
• @MarcinKaczmarek in orthographic projection you already have the direction of the viewing angle, just plug that (negated) in for eye-v Commented Mar 7, 2016 at 11:29