AmplifyCreations / AmplifyImpostors-Feedback

0 stars 0 forks source link

AI should copy the common properties for the original materials #14

Closed BOXOPHOBIC closed 1 year ago

BOXOPHOBIC commented 1 year ago

The baker and the runtime shader are custom-made. The issue I have right now:

image

Simply put, it would be nice if the common original material properties could be copied over to the baked material.

BOXOPHOBIC commented 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));
                        }
                    }
                }
            }
        }
BOXOPHOBIC commented 1 year ago

Older request, I attached the script I use to copy the material properties from one material to another, regardless of the shader used.

Dawie3565 commented 1 year ago

this item is now tracking in https://github.com/AmplifyCreations/AmplifyShaderEditor-Feedback/issues/169