Summary
We get unexpected colors from texture mapped materials missing UVs or having them all set to zero.
Question
Does the “standard” allow UV coordinates that are all zero or all identical? If so, is the edge cases demonstrated below to be considered a bug?
Background
I was debugging a model that was rendered differently in Three.js compared to Babylon.js and finally tracked it down to the UV coordinates all being zero in combination with the existence of an normal-map.
As mentioned in earlier posts, we get the data from an external API and thus have to make the best of what we get, so “fix the model” isn’t really an option here.
I understand that having identical UV coordinates (for example all being zero) is quite an edge case, but is it breaking any specs?
Say that all UV coordinates are zero, I would expect that the texture samplers would take the value of that exact position in the maps and in practice end up with a constant values over the render faces, be that albedo or normals.
Playground
I created a test case playground to test this theory:
All squares uses the same albedo texture. All but the front left one has the same normal-map set.
- Front left: Normal UVs from [0 - 1]
- Front center: Normal UVs from [0 - 1]
- Front right: UVs set in range [0 - 0.001]
- Back left: UVs all set to 0
- Back center: UVs all set to 0.5
- Back right: UVs all set to 0.001
1 & 2 is exactly as expected, just normal uv-mapping.
I expected 3 to basically be the green color from the bottom left pixel of the albedo texture, but instead it starts with gray. The smaller the range, the more gray it gets. Hmmm, perhaps it is from the center of the albedo map? Haven’t checked that.
I expected 4 to be the green color from (0,0) in the albedo texture and use the neutral normal from the normal map at (0, 0). It renders fully black, I expect this is due to the computed normal is broken.
I expected 5 to use the color from the middle (0.5, 0.5) of the albedo texture and use a neutral normal from the normal map at (0.5, 0.5). Instead we get a fascinating repeating texture, identically strangely mapped in albedo and normal map.
Case 6 is the weirdest. Here you get a static gray color in the same way as case 3 above. The bumps though, they go all crazy and the pattern depends on the camera position.