Exemple #1
0
        private void TransformAOTexture(ShaderArguments arguments, string baseColorName)
        {
            if (arguments.Occlusion == null)
            {
                return;
            }
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(arguments.Occlusion);
            var assetGuid = arguments.Occlusion.GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial = new Material(Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/PremultiplyOcclusionStrength"));

            try
            {
                var mainTexture = arguments.Occlusion;
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetFloat("_OcclusionStrength", arguments.OcclusionStrength);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, tmpMaterial,
                                                             _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc,
                             ExportUtils.GetTextureOptions(mainTexture).WithSRGB(true));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
            }
        }
Exemple #2
0
        private void CopyTextureAndSaveAs(Texture texture)
        {
            var outputAssetName        = EvaluateTextureName(texture);
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(texture);
            var assetGuid = texture.GetKey();

            if (_engine.IsUpToDate(assetGuid, outputAssetName, sourceFileTimestampUtc))
            {
                return;
            }

            var tImporter      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
            var texType        = tImporter?.textureType ?? TextureImporterType.Default;
            var textureOptions = ExportUtils.GetTextureOptions(texture);

            switch (texType)
            {
            case TextureImporterType.NormalMap:
                new TextureProcessor().ProcessAndSaveTexture(texture, "Hidden/UnityToCustomEngineExporter/Urho3D/DecodeNormalMap", _engine.GetTargetFilePath(outputAssetName), true);
                break;

            default:
                new TextureProcessor().ProcessAndSaveTexture(texture, "Hidden/UnityToCustomEngineExporter/Urho3D/Copy", _engine.GetTargetFilePath(outputAssetName), textureOptions.textureImporterFormat != TextureImporterFormat.DXT1);
                WriteOptions(assetGuid, outputAssetName, sourceFileTimestampUtc, textureOptions.WithSRGB(true));
                break;
            }
        }
Exemple #3
0
        private void CopyTexture(Texture texture)
        {
            var relPath = ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, texture);
            var newName = EvaluateTextureName(texture);

            if (relPath != newName)
            {
                CopyTextureAndSaveAs(texture);
            }
            else
            {
                _engine.TryCopyFile(AssetDatabase.GetAssetPath(texture), newName);
                WriteOptions(texture.GetKey(), newName, ExportUtils.GetLastWriteTimeUtc(texture),
                             ExportUtils.GetTextureOptions(texture));
            }
        }
Exemple #4
0
        private void TransformSpecularGlossiness(SpecularGlossinessShaderArguments arguments, string baseColorName)
        {
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(arguments.Diffuse,
                                                                         arguments.PBRSpecular.Texture, arguments.Smoothness.Texture);
            var assetGuid =
                (arguments.Diffuse ?? arguments.PBRSpecular.Texture ?? arguments.Smoothness.Texture).GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial =
                new Material(
                    Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/ConvertSpecularToMetallicRoughness"));
            Texture mainTexture       = null;
            Texture specularTexture   = null;
            Texture smoothnessTexture = null;

            try
            {
                mainTexture        = EnsureTexture(new TextureOrColor(arguments.Diffuse, arguments.DiffuseColor));
                specularTexture    = EnsureTexture(arguments.PBRSpecular);
                smoothnessTexture  = EnsureTexture(arguments.Smoothness);
                var(width, height) = MaxTexutreSize(mainTexture, specularTexture, smoothnessTexture);
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetTexture("_SpecGlossMap", specularTexture);
                tmpMaterial.SetFloat("_SmoothnessScale",
                                     arguments.GlossinessTextureScale *
                                     (arguments.Smoothness.Texture != null ? 1.0f : arguments.Glossiness));
                tmpMaterial.SetTexture("_Smoothness", smoothnessTexture);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, width, height, tmpMaterial,
                                                             _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc,
                             (ExportUtils.GetTextureOptions(mainTexture) ?? ExportUtils.GetTextureOptions(specularTexture) ??
                              ExportUtils.GetTextureOptions(smoothnessTexture)).WithSRGB(false));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
                DestroyTmpTexture(arguments.Diffuse, mainTexture);
                DestroyTmpTexture(arguments.PBRSpecular, specularTexture);
                DestroyTmpTexture(arguments.Smoothness, smoothnessTexture);
            }
        }
Exemple #5
0
        private void TransformNormal(Texture bump, float bumpScale, string baseColorName)
        {
            if (bump == null)
            {
                return;
            }

            if (bumpScale >= 0.999f)
            {
                CopyTexture(bump);
                return;
            }

            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(bump);
            var assetGuid = bump.GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial = new Material(Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/DecodeNormalMap"));

            try
            {
                var mainTexture = bump;
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetFloat("_BumpScale", bumpScale);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, tmpMaterial, _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc, ExportUtils.GetTextureOptions(mainTexture).WithSRGB(false));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
            }
        }