I have seen VS omitting the normalization of the normal with the excuse of postponing the normalization to the PS. But how could this ever be correct?
If points are transformed with A, normals should be transformed with A^-T (the inverse transpose). The latter could have a determinant greater than 1 due to scale components. It is even possible to have a determinant of 1 due to non-uniform scale components (the latter will work since the matrix is applied to all three vertices). Assume we have a triangle with vertex normals (1,0,0), (0,1,0) and (0,0,1) and assume A^-T is just a non-uniform re-scaling of (1,2,3). The transformed normals are thus equal to (1,0,0), (0,2,0), (0,0,3). If we normalize in the VS, the final normals are again (1,0,0), (0,1,0) and (0,0,1). Assume now, we have a fragment with barycentric coordinates (0.33,0.33,0.33). If we normalized in the VS, the interpolated normal will be ((0.577,0.577,0577) after normalization in the PS). If we didn't normalized in the VS, the interpolated normal will be (0.33,0.66,0.99) ((0.267,0.534,0.801) after normalization in the PS).
This could only work by 'normalizing' your transformation matrix to have a determinant of 1. Otherwise the VS needs to do a normalization as well? (Maybe I only have bad examples at my disposal )
↧