Esempio n. 1
0
        // Function used only to check performance of data with and without tessellation
        //[MenuItem("Internal/HDRP/Test/Remove tessellation materials (not reversible)")]
        static void RemoveTessellationMaterials()
        {
            var materials = Resources.FindObjectsOfTypeAll <Material>();

            var litShader        = Shader.Find("HDRP/Lit");
            var layeredLitShader = Shader.Find("HDRP/LayeredLit");

            foreach (var mat in materials)
            {
                if (mat.shader.name == "HDRP/LitTessellation")
                {
                    mat.shader = litShader;
                    // We remove all keyword already present
                    CoreEditorUtils.RemoveMaterialKeywords(mat);
                    LitGUI.SetupMaterialKeywordsAndPass(mat);
                    EditorUtility.SetDirty(mat);
                }
                else if (mat.shader.name == "HDRP/LayeredLitTessellation")
                {
                    mat.shader = layeredLitShader;
                    // We remove all keyword already present
                    CoreEditorUtils.RemoveMaterialKeywords(mat);
                    LayeredLitGUI.SetupMaterialKeywordsAndPass(mat);
                    EditorUtility.SetDirty(mat);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the material properties for the block.
        /// </summary>
        public override void LoadMaterialProperties()
        {
            layerCount = FindProperty(kLayerCount);

            // TODO: does not work with multi-selection
            Material material = materials[0];

            m_MaterialImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(material.GetInstanceID()));

            // Material importer can be null when the selected material doesn't exists as asset (Material saved inside the scene)
            if (m_MaterialImporter != null)
            {
                LayeredLitGUI.InitializeMaterialLayers(m_MaterialImporter, ref m_MaterialLayers, ref m_WithUV);
            }
        }
Esempio n. 3
0
        // This script is a helper for the artists to re-synchronize all layered materials
        //[MenuItem("Internal/HDRP/Synchronize all Layered materials")]
        static void SynchronizeAllLayeredMaterial()
        {
            var materials = Resources.FindObjectsOfTypeAll <Material>();

            bool VCSEnabled = (UnityEditor.VersionControl.Provider.enabled && UnityEditor.VersionControl.Provider.isActive);

            foreach (var mat in materials)
            {
                if (mat.shader.name == "HDRP/LayeredLit" || mat.shader.name == "HDRP/LayeredLitTessellation")
                {
                    CoreEditorUtils.CheckOutFile(VCSEnabled, mat);
                    LayeredLitGUI.SynchronizeAllLayers(mat);
                    EditorUtility.SetDirty(mat);
                }
            }
        }
Esempio n. 4
0
        void DrawLayerListGUI()
        {
            bool layersChanged = false;
            var  oldLabelWidth = EditorGUIUtility.labelWidth;

            // TODO: does not work with multi-selection
            Material material = materials[0];

            float indentOffset     = EditorGUI.indentLevel * 15f;
            float colorWidth       = 5;
            float UVWidth          = 30;
            float resetButtonWidth = 41;
            float padding          = 4f;
            float endOffset        = 2f;
            float labelWidth       = 75f;

            EditorGUIUtility.labelWidth = labelWidth;


            Rect headerLineRect         = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
            Rect headerLabelRect        = new Rect(headerLineRect.x, headerLineRect.y, EditorGUIUtility.labelWidth - indentOffset + 15f, headerLineRect.height);
            Rect headerUVRect           = new Rect(headerLineRect.x + headerLineRect.width - 37f - resetButtonWidth - endOffset, headerLineRect.y, UVWidth + 5, headerLineRect.height);
            Rect headerMaterialDropRect = new Rect(headerLineRect.x + headerLabelRect.width - 20f, headerLineRect.y, headerLineRect.width - headerLabelRect.width - headerUVRect.width, headerLineRect.height);

            EditorGUI.LabelField(headerLabelRect, Styles.layerNameHeader, EditorStyles.centeredGreyMiniLabel);
            EditorGUI.LabelField(headerMaterialDropRect, Styles.layerMaterialHeader, EditorStyles.centeredGreyMiniLabel);
            EditorGUI.LabelField(headerUVRect, Styles.uvHeader, EditorStyles.centeredGreyMiniLabel);

            for (int layerIndex = 0; layerIndex < numLayer; ++layerIndex)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();

                    Rect lineRect     = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
                    Rect colorRect    = new Rect(lineRect.x + 17f, lineRect.y + 7f, colorWidth, colorWidth);
                    Rect materialRect = new Rect(lineRect.x + padding + colorRect.width, lineRect.y, lineRect.width - UVWidth - padding - 3 - resetButtonWidth + endOffset, lineRect.height);
                    Rect uvRect       = new Rect(lineRect.x + lineRect.width - resetButtonWidth - padding - UVWidth - endOffset, lineRect.y, UVWidth, lineRect.height);
                    Rect resetRect    = new Rect(lineRect.x + lineRect.width - resetButtonWidth - endOffset, lineRect.y, resetButtonWidth, lineRect.height);

                    m_MaterialLayers[layerIndex] = EditorGUI.ObjectField(materialRect, Styles.layerLabels[layerIndex], m_MaterialLayers[layerIndex], typeof(Material), allowSceneObjects: true) as Material;
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Change layer material");
                        LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, true);
                        layersChanged = true;

                        // Update external reference.
                        foreach (var target in materialEditor.targets)
                        {
                            MaterialExternalReferences matExternalRefs = MaterialExternalReferences.GetMaterialExternalReferences(target as Material);
                            matExternalRefs.SetMaterialReference(layerIndex, m_MaterialLayers[layerIndex]);
                        }
                    }

                    EditorGUI.DrawRect(colorRect, kLayerColors[layerIndex]);

                    m_WithUV[layerIndex] = EditorGUI.Toggle(uvRect, m_WithUV[layerIndex]);

                    if (GUI.Button(resetRect, GUIContent.none))
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Reset layer material");
                        LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, !m_WithUV[layerIndex]);
                        layersChanged = true;
                    }

                    //draw text above to not cut the last letter
                    resetRect.x    -= 12;
                    resetRect.width = 50;
                    EditorGUI.LabelField(resetRect, Styles.resetButtonIcon);
                }

                if (m_MaterialLayers[layerIndex] != null && m_MaterialLayers[layerIndex].shader != null)
                {
                    var shaderName = m_MaterialLayers[layerIndex].shader.name;
                    if (shaderName != "HDRP/Lit" && shaderName != "HDRP/LitTessellation")
                    {
                        EditorGUILayout.HelpBox("Selected material is not an HDRP Lit Material. Some properties may not be correctly imported.", MessageType.Info);
                    }
                }
            }

            EditorGUIUtility.labelWidth = oldLabelWidth;

            if (layersChanged)
            {
                foreach (var mat in materials)
                {
                    LayeredLitGUI.SetupLayeredLitKeywordsAndPass(mat);
                }

                // SaveAssetsProcessor the referenced material in the users data
                if (m_MaterialImporter != null)
                {
                    LayeredLitGUI.SaveMaterialLayers(material, m_MaterialLayers);
                }

                // We should always do this call at the end
                materialEditor.serializedObject.ApplyModifiedProperties();
            }
        }
        void DrawMaterialCopyGUI()
        {
            bool layersChanged = false;
            var  width         = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 90;

            // TODO: does not work with multi-selection
            Material material = materials[0];

            Color originalContentColor = GUI.contentColor;

            float indentOffset    = EditorGUI.indentLevel * 15f;
            float colorWidth      = 14;
            float UVWidth         = 30;
            float copyButtonWidth = EditorGUIUtility.singleLineHeight;
            float endOffset       = 5f;

            Rect headerLineRect         = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
            Rect headerLabelRect        = new Rect(headerLineRect.x, headerLineRect.y, EditorGUIUtility.labelWidth - indentOffset, headerLineRect.height);
            Rect headerUVRect           = new Rect(headerLineRect.x + headerLineRect.width - 48 - endOffset, headerLineRect.y, UVWidth + 5, headerLineRect.height);
            Rect headerMaterialDropRect = new Rect(headerLineRect.x + headerLabelRect.width, headerLineRect.y, headerLineRect.width - headerLabelRect.width - headerUVRect.width, headerLineRect.height);

            EditorGUI.LabelField(headerLabelRect, Styles.layerNameHeader, EditorStyles.centeredGreyMiniLabel);
            EditorGUI.LabelField(headerMaterialDropRect, Styles.materialToCopyHeader, EditorStyles.centeredGreyMiniLabel);
            EditorGUI.LabelField(headerUVRect, Styles.uvHeader, EditorStyles.centeredGreyMiniLabel);

            for (int layerIndex = 0; layerIndex < numLayer; ++layerIndex)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();

                    Rect lineRect     = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight);
                    Rect colorRect    = new Rect(lineRect.x, lineRect.y, colorWidth, lineRect.height);
                    Rect materialRect = new Rect(lineRect.x + colorRect.width, lineRect.y, lineRect.width - UVWidth - colorWidth - copyButtonWidth + endOffset, lineRect.height);
                    Rect uvRect       = new Rect(lineRect.x + lineRect.width - copyButtonWidth - UVWidth - endOffset, lineRect.y, UVWidth, lineRect.height);
                    Rect copyRect     = new Rect(lineRect.x + lineRect.width - copyButtonWidth - endOffset, lineRect.y, copyButtonWidth, lineRect.height);

                    m_MaterialLayers[layerIndex] = EditorGUI.ObjectField(materialRect, Styles.layerLabels[layerIndex], m_MaterialLayers[layerIndex], typeof(Material), true) as Material;
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(m_MaterialImporter, "Change layer material");
                        LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, true);
                        layersChanged = true;
                    }


                    colorRect.width  = 30f;
                    GUI.contentColor = kLayerColors[layerIndex];
                    EditorGUI.LabelField(colorRect, "■");
                    GUI.contentColor = originalContentColor;

                    m_WithUV[layerIndex] = EditorGUI.Toggle(uvRect, m_WithUV[layerIndex]);

                    if (GUI.Button(copyRect, GUIContent.none))
                    {
                        LayeredLitGUI.SynchronizeLayerProperties(material, m_MaterialLayers, layerIndex, !m_WithUV[layerIndex]);
                        layersChanged = true;
                    }

                    //fake the icon with two Console icon
                    //Rect copyRect = GUILayoutUtility.GetLastRect();
                    copyRect.x    -= 16;
                    copyRect.width = 40;
                    EditorGUI.LabelField(copyRect, Styles.copyButtonIcon);
                    copyRect.x -= 3;
                    copyRect.y += 3;
                    EditorGUI.LabelField(copyRect, Styles.copyButtonIcon);
                }
            }

            EditorGUIUtility.labelWidth = width;

            if (layersChanged)
            {
                foreach (var mat in materials)
                {
                    LayeredLitGUI.SetupMaterialKeywordsAndPass(mat);
                }

                // SaveAssetsProcessor the referenced material in the users data
                if (m_MaterialImporter != null)
                {
                    LayeredLitGUI.SaveMaterialLayers(material, m_MaterialLayers);
                }

                // We should always do this call at the end
                materialEditor.serializedObject.ApplyModifiedProperties();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Renders the properties in the block.
        /// </summary>
        protected override void OnGUIOpen()
        {
            bool layersChanged  = false;
            int  oldindentLevel = EditorGUI.indentLevel;

            // TODO: does not work with multi-selection
            Material material = materials[0];

            float     indentOffset      = EditorGUI.indentLevel * 15f;
            const int UVWidth           = 14;
            const int resetButtonWidth  = 43;
            const int endOffset         = 2;
            const int horizontalSpacing = 4;
            const int headerHeight      = 15;

            EditorGUI.indentLevel = 0;

            Rect headerLineRect   = GUILayoutUtility.GetRect(1, headerHeight);
            Rect labelRect        = new Rect(headerLineRect.x + indentOffset, headerLineRect.y, EditorGUIUtility.labelWidth - indentOffset, headerHeight);
            Rect uvRect           = new Rect(headerLineRect.x + headerLineRect.width - horizontalSpacing - UVWidth - resetButtonWidth - endOffset, headerLineRect.y, UVWidth, headerHeight);
            Rect materialDropRect = new Rect(labelRect.xMax + horizontalSpacing, headerLineRect.y, uvRect.xMin - labelRect.xMax - 2 * horizontalSpacing, headerHeight);

            //Minilabel is slighly shifted from 2 px.
            const int shift           = 2;
            const int textOverflow    = 2;
            Rect      headerLabelRect = new Rect(labelRect)
            {
                xMin = labelRect.xMin - shift, xMax = labelRect.xMax + shift
            };
            Rect headerUVRect = new Rect(uvRect)
            {
                xMin = uvRect.xMin - shift, xMax = uvRect.xMax + shift + textOverflow
            };                                                                                                              //dealing with text overflow (centering "UV" on sligthly larger area)
            Rect headerMaterialDropRect = new Rect(materialDropRect)
            {
                xMin = materialDropRect.xMin - shift, xMax = materialDropRect.xMax + shift
            };

            using (new EditorGUI.DisabledScope(true))
            {
                EditorGUI.LabelField(headerLabelRect, Styles.layerNameHeader, EditorStyles.miniLabel);
                EditorGUI.LabelField(headerMaterialDropRect, Styles.layerMaterialHeader, EditorStyles.miniLabel);
                EditorGUI.LabelField(headerUVRect, Styles.uvHeader, EditorStyles.miniLabel);
            }

            for (int layerIndex = 0; layerIndex < numLayer; ++layerIndex)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    Rect lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
                    lineRect.xMin += indentOffset;
                    lineRect.yMax -= EditorGUIUtility.standardVerticalSpacing;

                    Rect lineLabelRect    = new Rect(labelRect.x, lineRect.y, labelRect.width, lineRect.height);
                    Rect lineMaterialRect = new Rect(materialDropRect.x, lineRect.y, materialDropRect.width, lineRect.height);
                    Rect lineUvRect       = new Rect(uvRect.x, lineRect.y, uvRect.width, lineRect.height);
                    Rect lineResetRect    = new Rect(uvRect.xMax + horizontalSpacing, lineRect.y, resetButtonWidth, lineRect.height);

                    using (new EditorGUIUtility.IconSizeScope(LayersUIBlock.Styles.layerIconSize))
                        EditorGUI.LabelField(lineLabelRect, LayersUIBlock.Styles.layers[layerIndex]);

                    EditorGUI.BeginChangeCheck();
                    m_MaterialLayers[layerIndex] = EditorGUI.ObjectField(lineMaterialRect, GUIContent.none, m_MaterialLayers[layerIndex], typeof(Material), allowSceneObjects: true) as Material;
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Change layer material");
                        LayeredLitGUI.SynchronizeLayerProperties(material, layerIndex, m_MaterialLayers[layerIndex], m_WithUV[layerIndex]);
                        layersChanged = true;

                        // Update external reference.
                        foreach (var target in materialEditor.targets)
                        {
                            MaterialExternalReferences matExternalRefs = MaterialExternalReferences.GetMaterialExternalReferences(target as Material);
                            matExternalRefs.SetMaterialReference(layerIndex, m_MaterialLayers[layerIndex]);
                        }
                    }

                    EditorGUI.BeginChangeCheck();
                    m_WithUV[layerIndex] = EditorGUI.Toggle(lineUvRect, m_WithUV[layerIndex]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Change layer material");
                        layersChanged = true;
                    }

                    if (GUI.Button(lineResetRect, Styles.resetButtonIcon))
                    {
                        Undo.RecordObjects(new UnityEngine.Object[] { material, m_MaterialImporter }, "Reset layer material");
                        LayeredLitGUI.SynchronizeLayerProperties(material, layerIndex, m_MaterialLayers[layerIndex], m_WithUV[layerIndex]);
                        layersChanged = true;
                    }
                }

                if (m_MaterialLayers[layerIndex] != null && m_MaterialLayers[layerIndex].shader != null)
                {
                    var shaderName = m_MaterialLayers[layerIndex].shader.name;
                    if (shaderName != "HDRP/Lit" && shaderName != "HDRP/LitTessellation")
                    {
                        EditorGUILayout.HelpBox("Selected material is not an HDRP Lit Material. Some properties may not be correctly imported.", MessageType.Info);
                    }
                }
            }

            EditorGUI.indentLevel = oldindentLevel;

            if (layersChanged)
            {
                foreach (var mat in materials)
                {
                    LayeredLitAPI.ValidateMaterial(mat);
                }

                // SaveAssetsProcessor the referenced material in the users data
                if (m_MaterialImporter != null)
                {
                    LayeredLitGUI.SaveMaterialLayers(material, m_MaterialLayers, m_WithUV);
                }

                // We should always do this call at the end
                materialEditor.serializedObject.ApplyModifiedProperties();
            }
        }