I'm trying to project the normal of a point and colour it based on if it is (from the perspective of the camera/viewing plane) leaning left of vertical, or right of vertical.
To do this I'm taking my point normal and multiplying it by the gl_ModelViewProjectionMatrix, and checking if it has a positive or negative x value. However all my points go red (indicating left of vertical, which definitely isnt the case). If I change ModelViewProjectionMatrix to gl_ProjectionMatrix I get red and green points, however they obviously aren't coloured from the camera's perspective without the ModelViewMatrix.
Am I misunderstanding something here?
Shader example:
void main(){
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 temp = vec4(vNormal.x, vNormal.y, vNormal.z, 1);
vMajorTransformed = gl_ModelViewProjectionMatrix * temp;
if (vMajorTransformed.x < 0) {
gl_FrontColor = vec4(1, 0, 0, 1);
} else {
gl_FrontColor = vec4(0, 1, 0, 1);
}
gl_PointSize = 3;
}
gl_NormalMatrix
, and it is different fromgl_ModelViewMatrix
in that it is 3x3 - you would not need to create a 4D vector or worry about W to transform your normal if you multiply by this matrix. (e.g.vMajorTransformed = gl_NormalMatrix * vNormal
, assumingvMajorTransformed
isvec3
). – Andon M. Coleman