So something came up today when I was going over my Blinn shader. As I've been taught, the half-angle vector is calculated in the fragment shader, and is equal to
normalize(lightDir + viewDir). This seems to work fine.
When adding a normal map, this still seems to works, except I use tangent space vectors and
dot the half-angle with the normal from the normal map.
But here's what I don't understand: when using normal maps, shouldn't the light & view directions be re-computed for each fragment? Seeing as the interpolation between the vectors is no longer linear,
viewDir can't possibly be correct anymore?
Somehow I feel like the per-pixel normal should play a part in calculating the view/light directions. Am I missing something?
This came up when working on a fresnel effect which also uses the half-angle vector. Without any changes to the half-angle vector, the fresnel effect can't possibly know anything about the normal map, which seems wrong (and actually looks wrong).
Here's the fresnel calculation:
// Fresnel (Schlick approximation) float base = 1 - dot(viewDir, halfAngle); float exp = pow(base, 5); float fresnel = exp + fZero * (1.0 - exp);
Given that neither viewDir nor halfAngle incorporate the normals from the normal map, the fresnel effect is computed based on interpolated normals and looks "blocky". Maybe this isn't a problem for the Blinn computation, but I thought it might be too.