This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Material NormalMap
ousttrue edited this page Sep 3, 2018
·
7 revisions
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();
}
Convert texture
static Color32 ConvertNormalMap(Color32 src)
{
return new Color32
{
r = 0,
g = src.g,
b = 0,
a = src.r,
};
}
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;
}