How to calculate vertex-camera alignment?

edited May 2016 in GLSL / Shaders

Hi,

I would like to colorize faces depending on how well aligned they are to the camera. Something like this:

intensity = max(0.0, dot(camNormal, vertNormal));

I should pass camNormal and vertNormal from the vertex shader to the fragment shader. My problem is, I don't know how to calculate the "camNormal" (the direction in which the camera is pointing).

In @codeanticode's blog I see that both modelview and normalMatrix should include in some way the camera information, but I don't know how to get it out of those matrices. Does someone know?

Thanks!

Tagged:

Answers

  • I can never remember all these opengl spaces, but in eye space the camera is at the origin, looking ahead.

  • Thanks. Do you mean I could replace camNormal with something like vec3(0, 0, 1) or vec3(0,0,-1)?

  • Answer ✓

    I think so, as long as your 'vertNormal' has been transformed to eye space (multiplied by normalMatrix)

Sign In or Register to comment.