Normals
- But first dot product.
- The dot product between two vectors u, v is a scalar value.
- u · v = |u||v|cos(θ), where θ is the angle between the two vectors.
- u · v = u0v0 + u1v1+ ... + unvn
- This is reasonably efficient to compute.
- Especially if we have unit vectors.
- The Cross Product
- u × v
- This returns a normal to u and v.
- u ×v = - v × u
- u × v = [u2v3-u3v2, u3v1-u1v3, u1v2-u2v1]
- Surface normals to vertex normals
- A normal to the surface can be computed by crossing any two vectors that make up that surface.
- But if it is not plainer, then this is not really the "surface" normal.
- This is why we like triangles, they are always co-plainer.
- If we don't have a triangle, break it into triangles
- But what about the vertex normal?
- Will it do to just cross two of the adjacent edges?
- The usual approch is to average the normals for the adjacent surfaces (for a smooth surface)
- Or to compute for each different normal for non-smooth surfaces.
- By the way ...
- We need to be careful the order we specify our points for a polygon
- As this will effect the way the normal is pointing.
- And make it so some of our faces are pointing "inward" and some are pointing "outward".
- We normally represent normals as a vec3
- Translation of a normal is meaningless
- We will usually "normalize" the normals before we use them, so rescaling is probably not an issue either.
- Transfrering Normals
- This should be straight forward now.
- Build a buffer to hold the normals, and associate this with a attribute variable.
- Build a buffer with vertex, normal, color and associate each offset.
- Bind the buffer with offsets to different attribute variables.
- Transforming Normals
- This discussion is from the red book and from here
- If we just rotate, and translate nothing happens to normals, they can be rotated and translated just fine.
- If we apply a uniform scaling, then there is no problem as well.
- But if we apply a non-uniform scaling, normals are messed up.
- Do hand 1-d Example.
- We have several choices:
- Only scale by uniform amounts.
- Maintain a transformation matrix for normals.
- Derive a transformation matrix for normals from our vertex transformation matrix.
- The red book gives n' = M-1T n
- Where M is the upper 3x3 of the transformation matrix before projection.