Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Material NormalMap

ousttrue edited this page Sep 3, 2018 · 7 revisions

Editor Import

Mark TextureImporter as normalMap

 public void MarkTextureAssetAsNormalMap()
        {
            if (string.IsNullOrEmpty(assetPath))
                return;

            TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
            if (null == textureImporter) {
                return;
            }
            textureImporter.textureType = TextureImporterType.NormalMap;
            textureImporter.SaveAndReimport();
        }

RunTime Import

Convert texture

        static Color32 ConvertNormalMap(Color32 src)
        {
            return new Color32
            {
                r = 0,
                g = src.g,
                b = 0,
                a = src.r,
            };
        }

Both export

Unpack DXT5nm

fixed4 frag (v2f i) : SV_Target
{
    fixed4 col = tex2D(_MainTex, i.uv);
    col.xyz = (UnpackNormal(col) + 1) * 0.5;
    col.z = 1;
    return col;
}
Clone this wiki locally