Transformation of normals into eye space.

I am attempting to create a outlining (cartoonish) effect around my meshes in OpenGL ES 1.1. Normally in OpenGL I would just render in wireframe mode with a line width of 3 or 5 in front face culling mode. Then I would render the polgons with back face culling and tadda, the depth buffer magic gives me the outline effect I want.

However OpenGL es doesnt support wireframe modes, and rendering with GL_LINES will not allow the black magic of cull face / depth buffer to work.

What I am doing now should work for what I want, but I am missing something, and cant figure out what… I have a series of triangles, each with a face normal. I simply rotate the normal by glGetFloatv(GL_MODELVIEW_MATRIX, modelView), and take the angle between the rotated vector and the origin view vector (0,0,-1). If the angle is 90 or greater than the triangle should be facing away from the camera. I then render that poly in line mode with a line width value of 3 or 5. For the most part it is working, except I am seeing the wrong line polys at certain angles.

Basically my question is, should the above method work correctly in order to transform a normal into eye space, and then check the angle between that normal and the view vector. Or, do I need to do some sort of transformation with the projection matrix as well?

Thanks in advance!

Normals need to be transformed with the transposed inverse of the modelview matrix into order to get them into eyespace. If the modelview matrix contains scaling, they need to be re-normalized as well.

Is that true if there is no non uniform scaling? I could be wrong, but isnt the modelview matrix equal to the transposed inverse when there is no scaling involved?

Yes, using this method, normals keep their direction relative to the surface, even if non-uniform scaling is involved.
Important: either treat the normals as 4-component vector with w=0 or just use the upper 3x3 part of the resulting matrix.

You can take a shortcut, if you know that the modelview matrix contains no (non-uniform)scaling, shearing or projection; only rotation and translation: Then you may use the modelview matrix as is :slight_smile:

Thanks. That’s what I thought. Must be an error in my code logic somewhere…