Game Development Community

32bit normal map lighting error t3d1.1b3 - NOT A BUG

by Rob McNaughton · in Torque 3D Professional · 12/15/2010 (7:08 am) · 4 replies

I am hoping this is an already solved issue or someone can tell me what I am doing wrong.

I am trying to use the parallax material feature and am finding there is an error when using 32bit normalmaps. The default terrain material I am using requires the heightmap to be in the alpha of the normal map but the lighting seems to break when loading any kind of 32bit normalmap texture.

Here is the example where I assign a white diffuse, grey detail, and a dxt1 vs a dxt5 normal map, no parallax.
chaingunstudios.com/3dToolMan/Torque32bitNormalLighting.jpgI also tested 32bit TGA files and they get the same error. What I really noticed first was any dark pixels in the alpha of the normal map causes darkening of the rendered material as if the shader uses RGBA source normalmap much differently than RGB. Looks to me the shader is expecting a modified channel layout like dxt5-NM, yet the height must still be the alpha, which is not an option for the altered channel dxt5-nm.

Any ideas?

About the author

Lead Technical Artist for Blizzard's "Team 1" working on StarCraft II. Rob has tinkered with torque for a long time and has yet to make something to show. Soon...


#1
12/16/2010 (4:45 am)
I just looked at bit more and indead the shaders are expecting 32bit normal maps as dxt5-NM textures. That means the Alpha is the original Red channel and the hight map that use to be in the alpha could be placed into the new red channel.

I am looking into how to change the shader to look to the r channel in the normal map for parallax now...
#2
12/16/2010 (7:37 am)
Fixed it by putting the heightmap part of the DXT5-NM normalmap texture in the Red Channel and changing torque.hlsl this way.

float depth = tex2D( texMap, texCoord ).r;
depth = ( depth + tex2D( texMap, texCoord + offset ).r ) * 0.5;
Works pretty sweet!
chaingunstudios.com/3dToolMan/Torque32bitNormalLightingCorrected.jpg
#3
12/16/2010 (7:18 pm)
I had always assumed DXT5-NM would not support specific Alpha Layer information.
But I do value expanding my knowledge, almost as much as i love being wrong...


DXT5nm
DXT5nm is the same file format as DXT5 except before compression the red channel is moved into the alpha channel, the green channel is left as-is, and the red and blue channels are blanked with the same solid color. This re-arranging of the color channels is often called swizzling.

The Green and Alpha channels are used because in the DXT format they are compressed using somewhat higher bit depths than the Red and Blue channels. Red and Blue have to be filled with the same solid color because most DXT compressors use an algorithm that compares differences between the three color channels. If you try to store some kind of texture in Red and/or Blue (specular power, height map, etc.) then the compressor will create more compression artifacts because it has to compare all three channels.
Reproduced from tech-artists.org/wiki/Normal_map_compression


And after a few quick T3D experiments, your improvements seem much better then default DXT5-NM. This is a great improvement, thanks for sharing it with the community!


#4
12/17/2010 (2:54 am)
While hijacking the red channel of a dxt5-NM does reduce the quality of the green channel, it is still far superior to a dxt5 without the swizzle. No artist I have seen can tell the difference if you add info to the red channel and I do that for a lot of assets.

By the way photoshop nvidia filter doesn't fill the r and b channels with a single color when saving a dxt5-NM, they instead use a normalized version of the green channel in both red and blue thats why it comes out grey. The newer nvidia tool nvcompress does as the flood single color in the r and b and they come out green/orange.

Lastly, I think this is not the correct way to do it (though it will work for me). Torque loads 32bit normal maps incorrectly. You cant have a dxt-nm and use the A channel for parallax height. The best solution would be to get the parallax from the alpha of another map. I would think the alpha of the detail would be the best for terrain.