Closed BOXOPHOBIC closed 1 year ago
public static void CopyMaterialProperties(Material oldMaterial, Material newMaterial)
{
var oldShader = oldMaterial.shader;
var newShader = newMaterial.shader;
for (int i = 0; i < ShaderUtil.GetPropertyCount(oldShader); i++)
{
for (int j = 0; j < ShaderUtil.GetPropertyCount(newShader); j++)
{
var propertyName = ShaderUtil.GetPropertyName(oldShader, i);
var propertyType = ShaderUtil.GetPropertyType(oldShader, i);
if (propertyName == ShaderUtil.GetPropertyName(newShader, j))
{
if (propertyType == ShaderUtil.ShaderPropertyType.Color || propertyType == ShaderUtil.ShaderPropertyType.Vector)
{
newMaterial.SetVector(propertyName, oldMaterial.GetVector(propertyName));
}
if (propertyType == ShaderUtil.ShaderPropertyType.Float || propertyType == ShaderUtil.ShaderPropertyType.Range)
{
newMaterial.SetFloat(propertyName, oldMaterial.GetFloat(propertyName));
}
if (propertyType == ShaderUtil.ShaderPropertyType.TexEnv)
{
newMaterial.SetTexture(propertyName, oldMaterial.GetTexture(propertyName));
}
}
}
}
}
Older request, I attached the script I use to copy the material properties from one material to another, regardless of the shader used.
this item is now tracking in https://github.com/AmplifyCreations/AmplifyShaderEditor-Feedback/issues/169
The baker and the runtime shader are custom-made. The issue I have right now:
Simply put, it would be nice if the common original material properties could be copied over to the baked material.