I am consistently getting materials that use a autodeks interactive shader and they do not convert to a lit HDRP material. This is so consistent with asset store materials that I’m not sure why Unity has not fixed this as a quality of life thing for developing. When switching manually to HDRP Lit it wipes all textures out of their slots.
I had the same problem so I wrote this script to convert materials to HDRP. It works with Autodesk Interactive materials, but can easily be extended to support other materials as well.
using System;
using UnityEditor;
using UnityEngine;
using static UnityEditor.ShaderGraph.Internal.KeywordDependentCollection;
public class MaterialToHDRP : MonoBehaviour
{
[MenuItem("Tools/Convert selected Materials to HDRP...", priority = 0)]
private static void upgradeSelected()
{
foreach(string guid in Selection.assetGUIDs)
{
string assetPath= AssetDatabase.GUIDToAssetPath(guid);
Material m=AssetDatabase.LoadAssetAtPath<Material>(assetPath);
Material mInstance=Instantiate(AssetDatabase.LoadAssetAtPath<Material>(assetPath));
mInstance.name = m.name;
if (convert(mInstance))
EditorUtility.CopySerialized(mInstance, m); //Makes sure we keep the original GUID
}
AssetDatabase.SaveAssets();
}
private static bool convert(Material m)
{
string shaderName= m.shader.name;
if (shaderName.Equals("Autodesk Interactive",StringComparison.OrdinalIgnoreCase))
{
//Read
Texture albedo = m.GetTexture("_MainTex");
Texture metallic = m.GetTexture("_MetallicGlossMap");
Texture roughness = m.GetTexture("_SpecGlossMap");
Texture normal = m.GetTexture("_BumpMap");
float bumpScale = m.GetFloat("_BumpScale");
Vector2 offset = m.mainTextureOffset;
Vector2 tiling = m.mainTextureScale;
//Convert
m.shader= Shader.Find("HDRP/Lit");
m.SetTexture("_BaseColorMap", albedo);
m.SetTexture("_NormalMap", normal);
m.SetFloat("_NormalScale", bumpScale);
m.mainTextureOffset = offset;
m.mainTextureScale = tiling;
return true;
}
return false;
}
}
Note that it does not copy all the material parameters, but can be extended for more detailed conversion. However, some of the maps cannot be used in the Lit shader directly anyway, as the autodesk interactive material have separate slots for roughness and metallic for example, while the Lit shader has combined multiple masks into one using the RGB components, which helps save memory.
For a perfect conversion you’d need to make a shadergraph shader that takes the same input as the Autodesk Interactive shader, and then use the above script to convert to that new shader.
Hope it is helpful for someone