Exemplo n.º 1
0
 void ImportTexture(string type, string path)
 {
     if (File.Exists(path))
     {
         string texMapName  = (string)mapNames[Regex.Replace(type, @"\b([a-z])", m => m.Value.ToUpper())];
         string tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName) : texPath + texMapName;
         string importPath  = tempTexName + ".png";
         MegascansImageUtils.CreateTexture(path, importPath);
         MegascansImageUtils.TextureImportSetup(importPath, false, false);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Previous version of the importer would loop through a list of texture paths, and use a bunch of if-statements and do things accordingly.
        /// This version just takes in every texture path and if it's not null, does the thing. Less looping, better overall performance.
        /// </summary>
        /// <param name="albedo"></param>
        /// <param name="opacity"></param>
        /// <param name="normals"></param>
        /// <param name="metallic"></param>
        /// <param name="specular"></param>
        /// <param name="AO"></param>
        /// <param name="gloss"></param>
        /// <param name="displacement"></param>
        /// <param name="roughness"></param>
        /// <param name="translucency"></param>
        Material ReadWriteAllTextures(string albedo, string opacity, string normals, string metallic, string specular, string AO, string gloss, string displacement, string roughness, string translucency)
        {
            try {
                Material mat = CreateMaterial();

                if (mat == null)
                {
                    return(null);
                }

                //create a new work thread for each texture to be processed.
                //Pack the opacity into the alpha channel of albedo if it exists.
                string texMapName = (string)mapNames["Albedo"];
                tempTexName = texPath.Contains("$mapName")? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                string p = tempTexName + ".png";
                mapName = opacity != null ? "Albedo + Alpha" : "Albedo";
                MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                Texture2D tex = MegascansImageUtils.PackTextures(albedo, opacity, p);

                mat.SetTexture("_MainTex", tex);
                mat.SetTexture("_BaseColorMap", tex);

                if (shaderType == 1)
                {
                    mat.SetTexture("_BaseMap", tex);
                    mat.SetColor("_BaseColor", Color.white);
                }

                if (opacity != null)
                {
                    if (shaderType > 0)
                    {
                        mat.SetFloat("_AlphaClip", 1);
                        mat.SetFloat("_Mode", 1);
                        mat.SetFloat("_Cull", 1);
                        mat.EnableKeyword("_ALPHATEST_ON");
                    }
                    else
                    {
                        mat.SetInt("_AlphaCutoffEnable", 1);
                        mat.SetFloat("_AlphaCutoff", 0.333f);
                        mat.SetInt("_DoubleSidedEnable", 1);

                        mat.SetOverrideTag("RenderType", "TransparentCutout");
                        mat.SetInt("_ZTestGBuffer", (int)UnityEngine.Rendering.CompareFunction.Equal);
                        mat.SetInt("_CullMode", (int)UnityEngine.Rendering.CullMode.Off);
                        mat.SetInt("_CullModeForward", (int)UnityEngine.Rendering.CullMode.Back);
                        mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                        mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                        mat.SetInt("_ZWrite", 1);
                        mat.renderQueue = 2450;
                        mat.SetInt("_ZTestGBuffer", (int)UnityEngine.Rendering.CompareFunction.Equal);

                        mat.EnableKeyword("_ALPHATEST_ON");
                        mat.EnableKeyword("_DOUBLESIDED_ON");
                        mat.DisableKeyword("_BLENDMODE_ALPHA");
                        mat.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
                    }
                }

                //test to see if gloss is absent but roughness is present...
                bool useRoughness = (gloss == null && roughness != null);
                if (texPack < 1 || shaderType < 1)
                {
                    mapName = "Masks";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", "Masks"): texPath + "Masks";
                    p           = tempTexName + ".png";
                    mat.SetFloat("_Metallic", 1.0f);
                    tex = MegascansImageUtils.PackTextures(metallic, AO, displacement, useRoughness ? roughness : gloss, p, useRoughness);
                    mat.SetTexture("_MaskMap", tex);
                    mat.EnableKeyword("_MASKMAP");
                    mat.SetFloat("_MaterialID", 1);
                    mat.SetTexture("_MetallicGlossMap", tex);
                    mat.EnableKeyword("_METALLICSPECGLOSSMAP");
                    mat.EnableKeyword("_METALLICGLOSSMAP");
                }

                //do we need to process a specular map?
                if (texPack > 0 && specular != null)
                {
                    texMapName = (string)mapNames["Specular"];
                    mapName    = "Specular + Gloss";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                    p           = tempTexName + ".png";
                    tex         = MegascansImageUtils.PackTextures(specular, useRoughness ? roughness : gloss, p, useRoughness);
                    mat.SetTexture("_SpecGlossMap", tex);
                    mat.SetColor("_SpecColor", new UnityEngine.Color(1.0f, 1.0f, 1.0f));
                    mat.SetColor("_SpecularColor", new UnityEngine.Color(1.0f, 1.0f, 1.0f));
                    mat.SetFloat("_WorkflowMode", 0);
                    mat.SetFloat("_MaterialID", 4);
                    mat.SetTexture("_SpecularColorMap", tex);
                    mat.EnableKeyword("_METALLICSPECGLOSSMAP");
                    mat.EnableKeyword("_SPECGLOSSMAP");
                    mat.EnableKeyword("_SPECULAR_SETUP");
                    mat.EnableKeyword("_SPECULARCOLORMAP");
                    mat.EnableKeyword("_MATERIAL_FEATURE_SPECULAR_COLOR");
                }

                //handle any textures which can just be converted in place.
                if (normals != null)
                {
                    texMapName = (string)mapNames["Normal"];
                    mapName    = "Normals";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                    p           = tempTexName + ".png";
                    MegascansImageUtils.CreateTexture(normals, p);
                    tex = MegascansImageUtils.TextureImportSetup(p, true, false);
                    mat.SetTexture("_BumpMap", tex);
                    mat.SetTexture("_NormalMap", tex);
                    mat.EnableKeyword("_NORMALMAP_TANGENT_SPACE");
                    mat.EnableKeyword("_NORMALMAP");

                    mapName     = "Normals_Terrain";
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName + "_Terrain"): texPath + texMapName + "_Terrain";
                    p           = tempTexName + ".png";

                    if (generateTerrainNormal && type.ToLower().Contains("surface"))
                    {
                        MegascansImageUtils.ImportTerrainNormal(normals, p);
                    }
                }

                if (displacement != null && dispType > 0)
                {
                    texMapName = (string)mapNames["Displacement"];
                    mapName    = "Displacement";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                    p           = tempTexName + ".png";
                    MegascansImageUtils.CreateTexture(displacement, p);
                    tex = MegascansImageUtils.TextureImportSetup(p, false, false);
                    mat.SetTexture("_HeightMap", tex);
                    mat.SetTexture("_ParallaxMap", tex);
                    mat.EnableKeyword("_DISPLACEMENT_LOCK_TILING_SCALE");
                    if (dispType == 1)
                    {
                        mat.EnableKeyword("_VERTEX_DISPLACEMENT");
                        mat.EnableKeyword("_VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE");
                    }
                    if (dispType == 2)
                    {
                        mat.EnableKeyword("_PIXEL_DISPLACEMENT");
                        mat.EnableKeyword("_PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE");
                    }
                }

                //occlusion may or may not need to be packed, depending on the shader used.
                if (shaderType > 1 && AO != null)
                {
                    texMapName = (string)mapNames["AO"];
                    mapName    = "AO";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                    p           = tempTexName + ".png";
                    MegascansImageUtils.CreateTexture(AO, p);
                    tex = MegascansImageUtils.TextureImportSetup(p, false, false);
                    mat.SetTexture("_OcclusionMap", tex);
                    mat.EnableKeyword("_OCCLUSIONMAP");
                }

                if (translucency != null)
                {
                    texMapName = (string)mapNames["Translucency"];
                    mapName    = "Translucency";
                    MegascansUtilities.UpdateProgressBar(1.0f, "Processing Asset " + assetName, "Importing texture: " + mapName);
                    tempTexName = texPath.Contains("$mapName") ? texPath.Replace("$mapName", texMapName): texPath + texMapName;
                    p           = tempTexName + ".png";
                    tex         = MegascansImageUtils.PackTextures(translucency, translucency, translucency, null, p);
                    mat.SetInt("_MaterialID", 0);
                    mat.SetInt("_DiffusionProfile", 1);
                    mat.SetFloat("_EnableSubsurfaceScattering", 1);
                    mat.SetTexture("_SubsurfaceMaskMap", tex);
                    mat.SetTexture("_ThicknessMap", tex);
                    if (plant)
                    {
                        mat.SetInt("_DiffusionProfile", 2);
                        mat.SetFloat("_CoatMask", 0.0f);
                        mat.SetInt("_EnableWind", 1);
                        mat.EnableKeyword("_VERTEX_WIND");
                    }
                    mat.EnableKeyword("_SUBSURFACE_MASK_MAP");
                    mat.EnableKeyword("_THICKNESSMAP");
                    mat.EnableKeyword("_MATERIAL_FEATURE_TRANSMISSION");
                }
                return(mat);
            } catch (Exception ex) {
                Debug.Log("Exception: " + ex.ToString());
                MegascansUtilities.HideProgressBar();
                return(null);
            }
        }
Exemplo n.º 3
0
        void OnGUI()
        {
            GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), MSBackground, ScaleMode.StretchToFill);

            GUILayout.BeginHorizontal();

            GUILayout.Box("Bridge Plugin v" + version, MSHeadingTextStyle, GUILayout.Height(textHeadingSize.y));

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            if (GUILayout.Button(MSLogo, MSLogoStyle, GUILayout.Height(logoSize.y), GUILayout.Width(logoSize.x)))
            {
                Application.OpenURL("https://quixel.com/megascans/library/latest");
            }

            if (GUILayout.Button(BridgeLogo, MSLogoStyle, GUILayout.Height(logoSize.y), GUILayout.Width(logoSize.x)))
            {
                Application.OpenURL("https://quixel.com/bridge");
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            tab = GUILayout.Toolbar(tab, new string[] { "Settings", "Utilities" }, MSTabsStyle, GUILayout.Height(textSize.y));

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            Handles.color = Color.white;
            Handles.DrawLine(new Vector3(0f, lineYLoc), new Vector3(maxSize.x, lineYLoc));
            GUILayout.EndHorizontal();

            if (tab == 0)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Label("Workflow", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                texPack = EditorGUILayout.Popup(texPack, texPacking, MSPopup, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Label("Displacement", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                dispType = EditorGUILayout.Popup(dispType, dispTypes, MSPopup, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Box("Shader Type", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                shaderType = EditorGUILayout.Popup(shaderType, shaderTypes, MSPopup, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Box("Import Resolution", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                importResolution = EditorGUILayout.Popup(importResolution, importResolutions, MSPopup, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Box("LOD Fade Mode", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                lodFadeMode = EditorGUILayout.Popup(lodFadeMode, lodFadeModeSettings, MSPopup, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Box("Import Path", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                path = EditorGUILayout.TextField(path, MSField, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                setupCollision = EditorGUI.Toggle(collisionLoc, setupCollision, MSCheckBox);
                GUILayout.Box("Setup Collision", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                flipNormalY = EditorGUI.Toggle(flipNormalYLoc, flipNormalY, MSCheckBox);
                GUILayout.Box("Flip Normal Y (Green) Channel (2D Surfaces)", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                applyToSelection = EditorGUI.Toggle(applyToSelectionLoc, applyToSelection, MSCheckBox);
                GUILayout.Box("Apply To Selection (2D Surfaces)", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                addAssetToScene = EditorGUI.Toggle(addAssetToSceneLoc, addAssetToScene, MSCheckBox);
                GUILayout.Box("Add Asset to the Scene", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                setupPrefabs = EditorGUI.Toggle(setupPrefabsLoc, setupPrefabs, MSCheckBox);
                GUILayout.Box("Create Prefabs", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                importLODs = EditorGUI.Toggle(importLODsLoc, importLODs, MSCheckBox);
                GUILayout.Box("Import Lower LODs", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                setupLOD = EditorGUI.Toggle(setupLODLoc, setupLOD, MSCheckBox);
                GUILayout.Box("Create LOD Groups", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                importAllTextures = EditorGUI.Toggle(importAllTexturesLoc, importAllTextures, MSCheckBox);
                GUILayout.Box("Import All Textures", MSNormalTextStyle, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                connection = EditorGUI.Toggle(connectionLoc, connection, MSCheckBox);
                GUILayout.Box("Enable Plugin", MSNormalTextStyle, GUILayout.Height(textSize.y));
                if (GUILayout.Button("Help...", MSHelpStyle, GUILayout.Width(textSize.x)))
                {
                    Application.OpenURL("https://docs.google.com/document/d/1cu1ysjZx62O_MoYaXvBI70WjqHTEGpoRYYcfUmRfykc");
                }

                GUILayout.EndHorizontal();
            }
            else
            {
#if (UNITY_2018 || UNITY_2019 || UNITY_2020)
                GUILayout.BeginHorizontal();

                GUILayout.Box("Terrain Tools (Beta)", MSHeadingTextStyle, GUILayout.Height(textHeadingSize.y));

                GUILayout.EndHorizontal();

                if (MegascansUtilities.isLegacy())
                {
                    GUILayout.BeginHorizontal();

                    GUILayout.Box("Material Name", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                    terrainMaterialName = EditorGUILayout.TextField(terrainMaterialName, MSField, GUILayout.Height(fieldSize.y), GUILayout.Width(fieldSize.x));

                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();

                    GUILayout.Box("Material Path", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                    terrainMaterialPath = EditorGUILayout.TextField(terrainMaterialPath, MSField, GUILayout.Height(fieldSize.y), GUILayout.Width(fieldSize.x));

                    GUILayout.EndHorizontal();
                }

                GUILayout.BeginHorizontal();

                GUILayout.Box("Texture Tiling", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                tiling = EditorGUILayout.TextField(tiling, MSField, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Setup Paint Layers", MSStrechedWidthStyle, GUILayout.Height(textSize.y)))
                {
                    MegascansTerrainTools.SetupTerrain();
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                string warningMsg = "Warning: This feature works properly with the metallic workflow only.";
                if (MegascansUtilities.isLegacy())
                {
                    warningMsg += "This feature requires HD Render Pipeline.";
                }

                GUI.skin.label.wordWrap = true;
                GUILayout.Label(warningMsg, MSWarningTextStyle, GUILayout.Height(textSize.y));

                GUILayout.EndHorizontal();
#endif

                GUILayout.BeginHorizontal();

                GUILayout.Box("Texture Tools (Beta)", MSHeadingTextStyle, GUILayout.Height(textHeadingSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Flip Green Channel", MSStrechedWidthStyle, GUILayout.Height(textSize.y)))
                {
                    MegascansImageUtils.FlipGreenChannel();
                }

                GUILayout.EndHorizontal();

#if (UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020)
                GUILayout.BeginHorizontal();

                GUILayout.Box("Material Tools (Beta)", MSHeadingTextStyle, GUILayout.Height(textHeadingSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Create Terrain Paint Layer", MSStrechedWidthStyle, GUILayout.Height(textSize.y)))
                {
                    MegascansTerrainTools.CreateTerrainLayerFromMat();
                }

                GUILayout.EndHorizontal();
#endif

#if HDRP && (UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020)
                GUILayout.BeginHorizontal();

                GUILayout.Box("Decal Setup (Beta)", MSHeadingTextStyle, GUILayout.Height(textHeadingSize.y));

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                GUILayout.Box("Global Opacity (%)", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                decalBlend = EditorGUILayout.TextField(decalBlend, MSField, GUILayout.Height(fieldSize.y));

                GUILayout.EndHorizontal();

                if (!MegascansUtilities.isLegacy())
                {
                    GUILayout.BeginHorizontal();

                    GUILayout.Box("Scale", MSText, GUILayout.Height(textSize.y), GUILayout.Width(textSize.x));
                    decalSize = EditorGUILayout.TextField(decalSize, MSField, GUILayout.Height(fieldSize.y));

                    GUILayout.EndHorizontal();
                }

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Create Decal Projector", MSStrechedWidthStyle, GUILayout.Height(textSize.y)))
                {
                    MegascansDecalTools.SetupDecalProjector();
                }

                GUILayout.EndHorizontal();
#endif
            }

            if (!MSLogo)
            {
                InitStyle();
                Repaint();
            }
        }