AmplifyCreations/AmplifyImpostors-Feedback

Copy Original material properties to baked Material

Opened this issue · 0 comments

Boxophobic item14

Issue
The baker and the runtime shader are custom-made. The issue I have right now:
•The original shader has some properties
•The runtime AI shader has the same properties, but since they are not copied, the original material and the baked material properties do not match.
•The runtime shader shares 20-30 parameters with the original material, so right now I added a small utility to copy those properties from the original gameobject > meshRenderer > sharedMaterial.

**Requested Change: **
it would be nice if the common original material properties could be copied over to the baked material.

**Recommended Solution: **
script I use to copy the material properties from one material to another, regardless of the shader used.

` 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));
                }
            }
        }
    }
}`