Exemple #1
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                mat.SetTexture("_MainTex", DiffuseMap);
            }
            else
            {
                mat.color = Diffuse.GetValueOrDefault(mat.color);
            }

            if (NormalMap)
            {
                mat.SetTexture("_BumpMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }
            else
            {
                // TODO: Unity has no notion of a constant normal map.
            }

            if (DisplacementMap)
            {
                mat.SetTexture("_ParallaxMap", DisplacementMap);
                mat.EnableKeyword("_PARALLAXMAP");
            }
            else
            {
                // TODO: Unity has no notion of a parallax map.
            }

            if (OcclusionMap)
            {
                mat.SetTexture("_OcclusionMap", OcclusionMap);
            }
            else
            {
                // TODO: Unity has no notion of a constant occlusion value.
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.EnableKeyword("_EMISSION");
            }
            else
            {
                var rgb = Emission.GetValueOrDefault(Color.black);
                mat.SetColor("_EmissionColor", rgb);
                if (rgb.r > 0 || rgb.g > 0 || rgb.b > 0)
                {
                    mat.EnableKeyword("_EMISSION");
                }
            }

            if (!IsMetallicWorkflow)
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecGlossMap", SpecularMap);
                    mat.EnableKeyword("_SPECGLOSSMAP");
                }
                else
                {
                    var rgb = Specular.GetValueOrDefault(Color.gray);
                    mat.SetColor("_SpecColor", rgb);
                }

                if (RoughnessMap)
                {
                    // Roughness for spec setup is tricky, since it may require merging two textures.
                    // For now, just detect that case and issue a warning (e.g. when roughness has a map,
                    // but isn't the albedo or spec map).
                    // Roughness also needs to be converted to glossiness.
                    if (RoughnessMap != SpecularMap && SpecularMap != null)
                    {
                        var specGlossTex = MaterialImporter.CombineRoughnessToGloss(SpecularMap, RoughnessMap);
                        mat.SetTexture("_SpecGlossMap", specGlossTex);
                        mat.EnableKeyword("_SPECGLOSSMAP");
                    }
                    else if (SpecularMap == null && RoughnessMap != DiffuseMap)
                    {
                        var mainGlossTex = MaterialImporter.CombineRoughnessToGloss(DiffuseMap, RoughnessMap);
                        mat.SetTexture("_SpecGlossMap", mainGlossTex);
                        mat.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
                    }
                    else
                    {
                        // TODO: create a new texture with constant spec value, combined with roughness texture.
                    }
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
            else
            {
                if (MetallicMap)
                {
                    mat.SetTexture("_MetallicGlossMap", MetallicMap);
                    mat.EnableKeyword("_METALLICGLOSSMAP");
                }
                else
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault(0));
                }

                if (RoughnessMap)
                {
                    // In this case roughness get its own map, but still must be converted to glossiness.
                    mat.SetTexture("_SpecGlossMap", RoughnessMap);
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
        }
Exemple #2
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                Debug.Log("here");
                mat.SetTexture("_BaseColorMap", DiffuseMap);
                mat.SetColor("_BaseColor", Color.white);
            }
            else
            {
                mat.SetColor("_BaseColor", Diffuse.GetValueOrDefault(mat.color));
            }

            // TODO: What about opacity map?

            if (!IsSpecularWorkflow)
            {
                // Robustness: It would be ideal if this parameter were provided by HDRP, however that
                // would require this asset package having a dependency on the HDRP package itself,
                // which is (yet) not desirable.
                mat.SetFloat("_MaterialID", /*Standard Metallic*/ 1);
            }
            else
            {
                mat.SetFloat("_MaterialID", /*Spec Color*/ 4);
                mat.EnableKeyword("_MATERIAL_FEATURE_SPECULAR_COLOR");
                mat.EnableKeyword("_SPECULARCOLORMAP");
            }

            // R=Metallic, G=Occlusion, B=Displacement, A=Roughness(Smoothness)
            var MaskMap = BuildMaskMap(!IsSpecularWorkflow ? MetallicMap : null, OcclusionMap, DisplacementMap, RoughnessMap);

            if (MaskMap)
            {
                mat.SetTexture("_MaskMap", MaskMap);
                mat.EnableKeyword("_MASKMAP");
            }

            if (!IsSpecularWorkflow)
            {
                if (!MetallicMap)
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault());
                }
            }
            else
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecularColorMap", SpecularMap);
                }
                else
                {
                    mat.SetColor("_SpecularColor", Specular.GetValueOrDefault());
                }
            }

            if (!RoughnessMap)
            {
                var smoothness = 1 - Roughness.GetValueOrDefault();
                mat.SetFloat("_Smoothness", smoothness);
                // HDRP Lit does not seem to respect smoothness, so just clamp to the correct value.
                mat.SetFloat("_SmoothnessRemapMin", smoothness);
                mat.SetFloat("_SmoothnessRemapMax", smoothness);
            }

            if (!OcclusionMap)
            {
                mat.SetFloat("_AORemapMin", Occlusion.GetValueOrDefault());
                mat.SetFloat("_AORemapMax", Occlusion.GetValueOrDefault());
            }

            // Single displacement scalar value not supported.

            if (ClearcoatMap)
            {
                mat.SetTexture("_CoatMaskMap", ClearcoatMap);
                mat.EnableKeyword("_MATERIAL_FEATURE_CLEAR_COAT");
            }
            mat.SetFloat("_CoatMask", ClearcoatRoughness.GetValueOrDefault());

            if (NormalMap)
            {
                mat.SetTexture("_NormalMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.EnableKeyword("_EMISSIVE_COLOR_MAP");
            }
            else
            {
                mat.SetColor("_EmissionColor", Emission.GetValueOrDefault());
            }
        }
Exemple #3
0
        public override void ImportFromUsd()
        {
            Material mat = Material;

            if (DiffuseMap)
            {
                mat.SetTexture("_MainTex", DiffuseMap);
                // Albedo texture is modulated by the material color, so setting to white preserves the pure
                // texture color.
                mat.color = Color.white;
            }
            else
            {
                mat.color = Diffuse.GetValueOrDefault(mat.color);
            }

            if (NormalMap)
            {
                mat.SetTexture("_BumpMap", NormalMap);
                mat.EnableKeyword("_NORMALMAP");
            }
            else
            {
                // TODO: Unity has no notion of a constant normal map.
            }

            if (DisplacementMap)
            {
                mat.SetTexture("_ParallaxMap", DisplacementMap);
                mat.EnableKeyword("_PARALLAXMAP");
            }
            else
            {
                // TODO: Unity has no notion of a parallax map.
            }

            if (OcclusionMap)
            {
                mat.SetTexture("_OcclusionMap", OcclusionMap);
            }
            else
            {
                // TODO: Unity has no notion of a constant occlusion value.
            }

            if (EmissionMap)
            {
                mat.SetTexture("_EmissionMap", EmissionMap);
                mat.SetColor("_EmissionColor", Color.white);
                mat.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive;
                mat.EnableKeyword("_EMISSION");
            }
            else
            {
                var rgb = Emission.GetValueOrDefault(Color.black);
                mat.SetColor("_EmissionColor", rgb);
                if (rgb.r > 0 || rgb.g > 0 || rgb.b > 0)
                {
                    mat.EnableKeyword("_EMISSION");
                }
            }

            if (IsSpecularWorkflow)
            {
                if (SpecularMap)
                {
                    mat.SetTexture("_SpecGlossMap", SpecularMap);
                    mat.EnableKeyword("_SPECGLOSSMAP");
                }
                else
                {
                    var rgb = Specular.GetValueOrDefault(Color.gray);
                    mat.SetColor("_SpecColor", rgb);
                }

                if (RoughnessMap)
                {
                    // Roughness for spec setup is tricky, since it may require merging two textures.
                    // For now, just detect that case and issue a warning (e.g. when roughness has a map,
                    // but isn't the albedo or spec map).
                    // Roughness also needs to be converted to glossiness.
                    if (RoughnessMap != SpecularMap && SpecularMap != null)
                    {
                        var specGlossTex = MaterialImporter.CombineRoughness(SpecularMap, RoughnessMap, "specGloss");
                        mat.SetTexture("_SpecGlossMap", specGlossTex);
                        mat.EnableKeyword("_SPECGLOSSMAP");
                    }
                    else if (SpecularMap == null && RoughnessMap != DiffuseMap)
                    {
                        var mainGlossTex = MaterialImporter.CombineRoughness(DiffuseMap, RoughnessMap, "specGloss");
                        mat.SetTexture("_SpecGlossMap", mainGlossTex);
                        mat.EnableKeyword("_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A");
                    }
                    else
                    {
                        // TODO: create a new texture with constant spec value, combined with roughness texture.
                    }
                }
                else
                {
                    float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                    mat.SetFloat("_Glossiness", smoothness);
                    mat.SetFloat("_GlossMapScale", smoothness);
                }
            }
            else
            {
                if (MetallicMap)
                {
                    mat.SetTexture("_MetallicGlossMap", MetallicMap);
                    mat.EnableKeyword("_METALLICGLOSSMAP");
                }
                else
                {
                    mat.SetFloat("_Metallic", Metallic.GetValueOrDefault(0));
                }

                float smoothness = 1 - Roughness.GetValueOrDefault(.5f);
                mat.SetFloat("_Glossiness", smoothness);
                mat.SetFloat("_GlossMapScale", smoothness);

                if (RoughnessMap)
                {
                    var metalicRough = MaterialImporter.CombineRoughness(MetallicMap, RoughnessMap, "metalicRough");
                    // In this case roughness get its own map, but still must be converted to glossiness.
                    mat.SetTexture("_MetallicGlossMap", metalicRough);
                    mat.EnableKeyword("_METALLICGLOSSMAP");

                    // The scalar Glossiness modulates the roughness/glossiness map, however USD has no
                    // concept of this, so setting it to 1.0 effectively disables the scalar effect when
                    // the map is present.
                    mat.SetFloat("_Glossiness", 1.0f);
                    mat.SetFloat("_GlossMapScale", 1.0f);
                }
            }
        }