/// <summary>
        /// Initializes this <see cref="Material"/> instance with Unlit attributes.
        /// </summary>
        /// <param name="material">The <see cref="Material"/> instance to set.</param>
        /// <returns>This <see cref="Material"/> instance.</returns>
        public static Material WithUnlit(this Material material)
        {
            Guard.NotNull(material, nameof(material));

            material.InitializeUnlit();
            return(material);
        }
Example #2
0
        public static void CopyTo(this MaterialBuilder srcMaterial, Material dstMaterial)
        {
            Guard.NotNull(srcMaterial, nameof(srcMaterial));
            Guard.NotNull(dstMaterial, nameof(dstMaterial));

            srcMaterial.ValidateForSchema2();

            dstMaterial.Alpha       = srcMaterial.AlphaMode.ToSchema2();
            dstMaterial.AlphaCutoff = srcMaterial.AlphaCutoff;
            dstMaterial.DoubleSided = srcMaterial.DoubleSided;

            var hasClearCoat = srcMaterial.GetChannel("ClearCoat") != null ||
                               srcMaterial.GetChannel("ClearCoatRoughness") != null ||
                               srcMaterial.GetChannel("ClearCoatNormal") != null;

            srcMaterial.CopyChannelsTo(dstMaterial, "Normal", "Occlusion", "Emissive");

            MaterialBuilder defMaterial = null;

            if (srcMaterial.ShaderStyle == "Unlit")
            {
                dstMaterial.InitializeUnlit();
                srcMaterial.CopyChannelsTo(dstMaterial, "BaseColor");
                return;
            }

            if (srcMaterial.ShaderStyle == "PBRMetallicRoughness")
            {
                if (hasClearCoat)
                {
                    dstMaterial.InitializePBRMetallicRoughnessClearCoat();
                }
                else
                {
                    dstMaterial.InitializePBRMetallicRoughness();
                }
                defMaterial = srcMaterial;
            }

            if (srcMaterial.ShaderStyle == "PBRSpecularGlossiness")
            {
                dstMaterial.InitializePBRSpecularGlossiness(srcMaterial.CompatibilityFallback != null);
                srcMaterial.CopyChannelsTo(dstMaterial, "Diffuse", "SpecularGlossiness");
                defMaterial = srcMaterial.CompatibilityFallback;
            }

            if (defMaterial != null)
            {
                if (defMaterial.ShaderStyle != "PBRMetallicRoughness")
                {
                    throw new ArgumentException(nameof(srcMaterial.CompatibilityFallback.ShaderStyle));
                }
                defMaterial.CopyChannelsTo(dstMaterial, "BaseColor", "MetallicRoughness");
                defMaterial.CopyChannelsTo(dstMaterial, "ClearCoat", "ClearCoatRoughness", "ClearCoatNormal");
            }
        }
Example #3
0
 /// <summary>
 /// Initializes this <see cref="Material"/> instance with Unlit attributes.
 /// </summary>
 /// <param name="material">The <see cref="Material"/> instance to set.</param>
 /// <returns>This <see cref="Material"/> instance.</returns>
 public static Material WithUnlit(this Material material)
 {
     material.InitializeUnlit();
     return(material);
 }
Example #4
0
        public static void CopyTo(this MaterialBuilder srcMaterial, Material dstMaterial)
        {
            Guard.NotNull(srcMaterial, nameof(srcMaterial));
            Guard.NotNull(dstMaterial, nameof(dstMaterial));

            srcMaterial.ValidateForSchema2();

            srcMaterial.TryCopyNameAndExtrasTo(dstMaterial);

            dstMaterial.Alpha             = srcMaterial.AlphaMode.ToSchema2();
            dstMaterial.AlphaCutoff       = srcMaterial.AlphaCutoff;
            dstMaterial.DoubleSided       = srcMaterial.DoubleSided;
            dstMaterial.IndexOfRefraction = srcMaterial.IndexOfRefraction;

            var hasClearCoat
                = srcMaterial.GetChannel("ClearCoat") != null ||
                  srcMaterial.GetChannel("ClearCoatRoughness") != null ||
                  srcMaterial.GetChannel("ClearCoatNormal") != null;

            var hasTransmission = srcMaterial.GetChannel("Transmission") != null;

            var hasSheen
                = srcMaterial.GetChannel("SheenColor") != null ||
                  srcMaterial.GetChannel("SheenRoughness") != null;

            var hasSpecular
                = srcMaterial.GetChannel("SpecularColor") != null ||
                  srcMaterial.GetChannel("SpecularFactor") != null;

            var hasVolume
                = srcMaterial.GetChannel("VolumeThickness") != null ||
                  srcMaterial.GetChannel("VolumeAttenuation") != null;

            srcMaterial.CopyChannelsTo(dstMaterial, "Normal", "Occlusion", "Emissive");

            MaterialBuilder defMaterial = null;

            if (srcMaterial.ShaderStyle == "Unlit")
            {
                dstMaterial.InitializeUnlit();
                srcMaterial.CopyChannelsTo(dstMaterial, "BaseColor");
                return;
            }

            if (srcMaterial.ShaderStyle == "PBRMetallicRoughness")
            {
                dstMaterial.InitializePBRMetallicRoughness
                (
                    hasClearCoat ? "ClearCoat" : null,
                    hasTransmission ? "Transmission" : null,
                    hasSheen ? "Sheen" : null,
                    hasSpecular ? "Specular" : null,
                    hasVolume ? "Volume" : null);

                defMaterial = srcMaterial;
            }

            if (srcMaterial.ShaderStyle == "PBRSpecularGlossiness")
            {
                dstMaterial.InitializePBRSpecularGlossiness(srcMaterial.CompatibilityFallback != null);
                srcMaterial.CopyChannelsTo(dstMaterial, "Diffuse", "SpecularGlossiness");
                defMaterial = srcMaterial.CompatibilityFallback;
            }

            if (defMaterial != null)
            {
                if (defMaterial.ShaderStyle != "PBRMetallicRoughness")
                {
                    throw new ArgumentException(nameof(srcMaterial.CompatibilityFallback.ShaderStyle));
                }
                defMaterial.CopyChannelsTo(dstMaterial, "BaseColor", "MetallicRoughness");
                defMaterial.CopyChannelsTo(dstMaterial, "ClearCoat", "ClearCoatRoughness", "ClearCoatNormal");
                defMaterial.CopyChannelsTo(dstMaterial, "Transmission");
                defMaterial.CopyChannelsTo(dstMaterial, "SheenColor", "SheenRoughness");
                defMaterial.CopyChannelsTo(dstMaterial, "SpecularColor", "SpecularFactor");
                defMaterial.CopyChannelsTo(dstMaterial, "VolumeThickness", "VolumeAttenuation");
            }
        }