The cause of these banding artifacts is the 8bit discretization of normal maps. For large shininess values (I believe the shininess exponent is 128 if you move the slider in Unity all the way to the right, but that’s not really documented), any normals bisecting viewer and light directions (=causing the viewer to see the highlight in the Phong model) react very sensitively to normal lengths != 1.
I’ll explain the artifacts in a moment. First, it is important to notice, there is no “neutral normal”, when using 8bit normal maps. tex2D() will interpret pixel value 0 as 0.0, and pixel value 255 as 1.0. As a result, pixel value 128 is interpreted as 128/255=0.50196. tex2D() on a “neutral” normal of 128/128/255 will therefore result in 0.50196/0.50196/1.0. Expanding from range-compression ([0:1]->[-1:1]) gives the actual normal vector 0.00392/0.00392/1.0 (a deviation of 0.3178 degrees to true 0/0/1), and as a sidenote, the length of that normal is 1.000015379, not 1.0. You can confirm this behaviour in the attached testcase, both on the plane, and in the material preview. Compare the images rendered…
a) …with simple specular shader (note, the preview is ugly, it’s a vertex lit shader)
b) …with a normal map of constant color 128/128/255
c) …with a normal map of constant color 127/127/255
The highlight will shift slightly between all three cases, which it shouldn’t if the normal was truly neutral. A truly neutral normal would be 127.5/127.5/255, but this cannot be represented with 8bit textures.
(edit: after disabling default texture compression DXT1 for the normal maps I noticed there is no longer a difference between 127/127/255 and a shader with unassigned normal map, so it seems the shader emulates a missing normal map by using 127/127/255. When switching to a non-bumped specular shader(=simple specular), however, one can see that the highlight does change positions.
If we now store normalized normals in our map, due to the 8bit discretization there comes a point where the z-component will flip from bit value 255 to bit value 254. For example, consider these normals at such a rounding border:
8bit normal 138/128/255 represents the normal 0.08235/0.00392/1.00000 (actual length 1.00339)
8bit normal 139/128/255 represents the normal 0.09020/0.00392/1.00000 (actual length 1.00407)
8bit normal 139/128/254 represents the normal 0.09020/0.00392/0.99216 (actual length 0.99626)
So the best representation (the one closest to length=1.0) for x=139 is 254, not 255.
Now, weighting these normals with the shininess exponent without the additional normalization shown in the previous post will result in:
1.00339^128=1.54274
1.00407^128=1.68124
0.99626^128=0.61870
The visual effect of this 255->254 transition will therefore be a drop in brightness to about 1/3, which is a lot. (Note in the testcase the highlight for 139/128/254 is very dark, and 139/128/255 is washed out)
Re-normalization of normals after range-decompression, as proposed in the previous post, will result in lengths of 1.0, and the Unity developers should fix the default Unity shaders accordingly.
However, there will still be a discrepancy in the direction of these normals:
138/128/255 will be re-normalized to 0.08207/0.00391/0.99662. The angle to a true 0/0/1 normal is 4.713 deg.
139/128/255 will be re-normalized to 0.08983/0.00391/0.99595. The angle to a true 0/0/1 normal is 5.159 deg.
139/128/254 will be re-normalized to 0.09054/0.00394/0.99589. The angle to a true 0/0/1 normal is 5.199 deg.
Again, weighting these normals with the shininess exponent will still result in discrepancies:
cos(4.713)^128=0.64820
cos(5.159)^128=0.59480
cos(5.199)^128=0.58993
These discrepancies are much less noticeable than for the case above, but they can still create visible artifacts (=banding) for large shininess exponents (they are not noticeable in the testcase). Unfortunately, the only way to get around this is to use 16bit normal maps.
An extension to the normalization solution would be to maximize the available bit depth of the normals, by not storing them normalized at length 1, but instead scaling them to their max x/y/z component to 1. So a 45 deg normal would not be represented as 0.707/0/0.707=218/128/218, but instead as 1/0/1=255/128/255. This approach further reduces the visible artifacts (but still can’t eliminate them completely), and since we now re-normalize all stored normals after texture sampling anyway, it doesn’t matter anymore that the normals stored in the map are of length >1.
(edit: had DXT1 compression enabled in the testcase, which is a BIG mistake for normal maps. fixed that by switching to RGB24bit)
294123–10472–$normalmap_testcase_151.unitypackage (13.4 KB)