Example #1
0
        private RenderQueueType GetRenderQueueType()
        {
            RenderQueueType renderQueueType;

            if (owner.isBlendModeOpaque)
            {
                renderQueueType = HDRenderQueue.ConvertFromOpaqueRenderQueue(opaqueRenderQueue);
            }
            else
            {
                renderQueueType = HDRenderQueue.ConvertFromTransparentRenderQueue(transparentRenderQueue);
            }
            return(renderQueueType);
        }
        public override string GetRenderQueueStr()
        {
            RenderQueueType renderQueueType;
            string          prefix = string.Empty;

            if (owner.isBlendModeOpaque)
            {
                prefix          = "Geometry";
                renderQueueType = HDRenderQueue.ConvertFromOpaqueRenderQueue(opaqueRenderQueue);
            }
            else
            {
                prefix          = "Transparent";
                renderQueueType = HDRenderQueue.ConvertFromTransparentRenderQueue(transparentRenderQueue);
            }

            int renderQueue = HDRenderQueue.ChangeType(renderQueueType, 0, owner.useAlphaClipping) - (int)(owner.isBlendModeOpaque ? Priority.Opaque : Priority.Transparent);

            return(prefix + renderQueue.ToString("+#;-#;+0"));
        }
        void SurfaceTypePopup()
        {
            if (surfaceType == null)
            {
                return;
            }

            Material material        = m_MaterialEditor.target as Material;
            var      mode            = (SurfaceType)surfaceType.floatValue;
            var      renderQueueType = HDRenderQueue.GetTypeByRenderQueueValue(material.renderQueue);
            bool     alphaTest       = material.HasProperty(kAlphaCutoffEnabled) && material.GetFloat(kAlphaCutoffEnabled) > 0.0f;

            EditorGUI.showMixedValue = surfaceType.hasMixedValue;
            var newMode = (SurfaceType)EditorGUILayout.Popup(StylesBaseUnlit.surfaceTypeText, (int)mode, StylesBaseUnlit.surfaceTypeNames);

            if (newMode != mode) //EditorGUI.EndChangeCheck is called even if value remain the same after the popup. Prefer not to use it here
            {
                m_MaterialEditor.RegisterPropertyChangeUndo("Surface Type");
                surfaceType.floatValue = (float)newMode;
                HDRenderQueue.RenderQueueType targetQueueType;
                switch (newMode)
                {
                case SurfaceType.Opaque:
                    targetQueueType = HDRenderQueue.GetOpaqueEquivalent(HDRenderQueue.GetTypeByRenderQueueValue(material.renderQueue));
                    break;

                case SurfaceType.Transparent:
                    targetQueueType = HDRenderQueue.GetTransparentEquivalent(HDRenderQueue.GetTypeByRenderQueueValue(material.renderQueue));
                    break;

                default:
                    throw new ArgumentException("Unknown SurfaceType");
                }
                material.renderQueue = HDRenderQueue.ChangeType(targetQueueType, (int)transparentSortPriority.floatValue, alphaTest);
            }
            EditorGUI.showMixedValue = false;

            bool isMixedRenderQueue = surfaceType.hasMixedValue || m_MaterialEditor.targets.Select(m => HDRenderQueue.GetTypeByRenderQueueValue(((Material)m).renderQueue)).Distinct().Count() > 1;

            EditorGUI.showMixedValue = isMixedRenderQueue;
            ++EditorGUI.indentLevel;
            switch (mode)
            {
            case SurfaceType.Opaque:
                //GetOpaqueEquivalent: prevent issue when switching surface type
                HDRenderQueue.OpaqueRenderQueue renderQueueOpaqueType = HDRenderQueue.ConvertToOpaqueRenderQueue(HDRenderQueue.GetOpaqueEquivalent(renderQueueType));
                var newRenderQueueOpaqueType = (HDRenderQueue.OpaqueRenderQueue)EditorGUILayout.Popup(StylesBaseUnlit.renderingPassText, (int)renderQueueOpaqueType, StylesBaseUnlit.opaqueRenderingPassNames);
                if (newRenderQueueOpaqueType != renderQueueOpaqueType)     //EditorGUI.EndChangeCheck is called even if value remain the same after the popup. Prefer not to use it here
                {
                    m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Pass");
                    renderQueueType      = HDRenderQueue.ConvertFromOpaqueRenderQueue(newRenderQueueOpaqueType);
                    material.renderQueue = HDRenderQueue.ChangeType(renderQueueType, alphaTest: alphaTest);
                }
                break;

            case SurfaceType.Transparent:
                //GetTransparentEquivalent: prevent issue when switching surface type
                HDRenderQueue.TransparentRenderQueue renderQueueTransparentType = HDRenderQueue.ConvertToTransparentRenderQueue(HDRenderQueue.GetTransparentEquivalent(renderQueueType));
                var names = StylesBaseUnlit.transparentRenderingPassNames;
                if (!showPreRefractionPass)
                {
                    names = names.Skip(1).ToArray();
                    --renderQueueTransparentType;         //keep index sync with displayed value
                }
                var newRenderQueueTransparentType = (HDRenderQueue.TransparentRenderQueue)EditorGUILayout.Popup(StylesBaseUnlit.renderingPassText, (int)renderQueueTransparentType, names);
                if (newRenderQueueTransparentType != renderQueueTransparentType)     //EditorGUI.EndChangeCheck is called even if value remain the same after the popup. Prefer not to use it here
                {
                    if (!showPreRefractionPass)
                    {
                        ++newRenderQueueTransparentType;        //keep index sync with displayed value
                    }
                    m_MaterialEditor.RegisterPropertyChangeUndo("Rendering Pass");
                    renderQueueType      = HDRenderQueue.ConvertFromTransparentRenderQueue(newRenderQueueTransparentType);
                    material.renderQueue = HDRenderQueue.ChangeType(renderQueueType, offset: (int)transparentSortPriority.floatValue);
                }
                break;

            default:
                throw new ArgumentException("Unknown SurfaceType");
            }
            --EditorGUI.indentLevel;
            EditorGUI.showMixedValue = false;
        }