Search Unity

problems using dds texture format directly in UNITY

Discussion in 'Editor & General Support' started by jasonnorgaar, Aug 18, 2011.

  1. jasonnorgaar

    jasonnorgaar

    Joined:
    Jan 24, 2011
    Posts:
    16
    Hello

    I am running into an issue with using dds format texture maps directly in UNITY. I had wanted to use dds directly in order to save time on the import process, however my normal maps seem to come in messed up, and UNITY doesn't give me the option to fix them. Normally, when I use the UNITY internal conversion on my normal map, it tells me the normal map needs to be fixed when I use textures that aren't dds.

    Is it possible to use dds directly in UNITY without having messed up normal maps?
     
  2. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    I haven't tried direct import of DDS compressed normal maps myself, but I think the problem is that Unity doesn't do conversion of DDS textures when they are imported. Since Unity uses DXT5nm compressed normal maps, if your normal maps aren't in DXT5nm format, then they'll be messed up.

    I guess you could use a shader that doesn't swap them like that (either written from scratch or modify one of the built in ones).
     
  3. jasonnorgaar

    jasonnorgaar

    Joined:
    Jan 24, 2011
    Posts:
    16
    I did use dxt5 for the maps. So I guess I will not use dds, and rely on Unity's internal converter instead unless someone knows a way other than developing a custom shader.
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    How are your normal maps messed up? When Unity says that the normal map needs to be fixed it just means that it needs to be automatically compressed to DXT5nm format. Hitting the "Fix" button next to the normal map texture in the Inspector will do this. Or you can change the texture type to normal map in the import settings.
     
  5. jasonnorgaar

    jasonnorgaar

    Joined:
    Jan 24, 2011
    Posts:
    16
    yup my bad, I was using dxt5 interpolated alpha instead of dxt5_NM. No issue. Thanks :)
     
  6. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    117
    Bump. How does Unity know the difference between DXT5 and DXT5nm when importing a DDS normal map?
     
  7. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    117
    To answer my own question, this is taken from: ScriptableRenderLoop/ShaderLibrary/Packing.hlsl

    Code (CSharp):
    1. // Unpack normal as DXT5nm (1, y, 0, x) or BC5 (x, y, 0, 1)
    2. float3 UnpackNormalmapRGorAG(float4 packedNormal, float scale = 1.0)
    3. {
    4.     // This do the trick
    5.     packedNormal.x *= packedNormal.w;
    6.     float3 normal;
    7.     normal.xy = packedNormal.xy * 2.0 - 1.0;
    8.     normal.xy *= scale;
    9.     normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
    10.     return normal;
    11. }