public static GPUShadowAlgorithm Pack(ShadowAlgorithm algo, ShadowVariant vari, ShadowPrecision prec)
        {
            int precshift = ShadowConstants.Bits.k_ShadowVariant + ShadowConstants.Bits.k_ShadowAlgorithm;
            int algoshift = ShadowConstants.Bits.k_ShadowVariant;

            return((GPUShadowAlgorithm)((int)prec << precshift | ((int)algo << algoshift) | (int)vari));
        }
Exemplo n.º 2
0
 public void SetGlobalShadowOverride(GPUShadowType shadowType, ShadowAlgorithm shadowAlgorithm, ShadowVariant shadowVariant, ShadowPrecision shadowPrecision, bool enable)
 {
     m_GlobalOverrides[(int)shadowType].enabled   = enable;
     m_GlobalOverrides[(int)shadowType].algorithm = shadowAlgorithm;
     m_GlobalOverrides[(int)shadowType].variant   = shadowVariant;
     m_GlobalOverrides[(int)shadowType].precision = shadowPrecision;
 }
Exemplo n.º 3
0
        void DrawWidgets(Light l, GPUShadowType shadowType, ShadowAlgorithm shadowAlgorithm, ShadowVariant shadowVariant, ShadowPrecision shadowPrecision, bool globalOverride)
        {
#if UNITY_EDITOR
            var          dict        = m_Entries[(int)shadowType];
            int[]        algoOptions = new int[dict.Count];
            GUIContent[] algoDescs   = new GUIContent[dict.Count];
            int          idx         = 0;

            foreach (var entry in dict)
            {
                algoOptions[idx] = (int)entry.Key;
                algoDescs[idx]   = new GUIContent(entry.Value.algorithmDesc);
                idx++;
            }

            using (new UnityEditor.EditorGUI.DisabledGroupScope(globalOverride))
            {
                UnityEditor.EditorGUI.BeginChangeCheck();
                shadowAlgorithm = (ShadowAlgorithm)UnityEditor.EditorGUILayout.IntPopup(new GUIContent("Shadow Algorithm"), (int)shadowAlgorithm, algoDescs, algoOptions);
                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    shadowVariant = 0;
                }
            }

            UnityEditor.EditorGUI.indentLevel++;
            Entry e = dict[shadowAlgorithm];

            int          varsAvailable = e.variantsAvailable;
            int[]        varOptions    = new int[varsAvailable];
            GUIContent[] varDescs      = new GUIContent[varsAvailable];

            idx = 0;
            for (int writeIdx = 0; writeIdx < varsAvailable; idx++)
            {
                if (e.variantDels[idx].low != null || e.variantDels[idx].high != null)
                {
                    varOptions[writeIdx] = idx;
                    varDescs[writeIdx]   = new GUIContent(e.variantDescs[idx]);
                    writeIdx++;
                }
            }

            UnityEditor.EditorGUILayout.BeginHorizontal();

            using (new UnityEditor.EditorGUI.DisabledGroupScope(globalOverride))
            {
                shadowVariant = (ShadowVariant)UnityEditor.EditorGUILayout.IntPopup(new GUIContent("Variant + Precision"), (int)shadowVariant, varDescs, varOptions);

                if (e.variantDels[(int)shadowVariant].low != null && e.variantDels[(int)shadowVariant].high != null)
                {
                    GUIContent[] precDescs   = new GUIContent[] { new GUIContent("High"), new GUIContent("Low") };
                    int[]        precOptions = new int[] { 0, 1 };
                    shadowPrecision = (ShadowPrecision)UnityEditor.EditorGUILayout.IntPopup((int)shadowPrecision, precDescs, precOptions, GUILayout.MaxWidth(65));
                }
                else
                {
                    using (new UnityEditor.EditorGUI.DisabledScope())
                    {
                        GUIContent[] precDescs   = new GUIContent[] { new GUIContent(e.variantDels[(int)shadowVariant].low == null ? "High" : "Low") };
                        int[]        precOptions = new int[] { e.variantDels[(int)shadowVariant].low == null ? 0 : 1 };
                        UnityEditor.EditorGUILayout.IntPopup(precOptions[0], precDescs, precOptions, GUILayout.MaxWidth(65));
                        shadowPrecision = (ShadowPrecision)precOptions[0];
                    }
                }
            }

            AdditionalShadowData asd        = l.GetComponent <AdditionalShadowData>();
            GPUShadowAlgorithm   packedAlgo = ShadowUtils.Pack(shadowAlgorithm, shadowVariant, shadowPrecision);
            int[] shadowData = null;
            if (!GUILayout.Button("Reset", GUILayout.MaxWidth(80.0f)))
            {
                shadowData = asd.GetShadowData((int)packedAlgo);
            }

            UnityEditor.EditorGUILayout.EndHorizontal();

            if (shadowPrecision == ShadowPrecision.Low)
            {
                e.variantDels[(int)shadowVariant].low(l, shadowAlgorithm, shadowVariant, shadowPrecision, ref shadowData);
            }
            else
            {
                e.variantDels[(int)shadowVariant].high(l, shadowAlgorithm, shadowVariant, shadowPrecision, ref shadowData);
            }
            asd.SetShadowAlgorithm((int)shadowAlgorithm, (int)shadowVariant, (int)shadowPrecision, (int)packedAlgo, shadowData);

            UnityEditor.EditorGUI.indentLevel--;
#endif
        }
 public static void Unpack(GPUShadowAlgorithm gpuAlgo, out ShadowAlgorithm algo, out ShadowVariant vari, out ShadowPrecision prec)
 {
     algo = ExtractAlgorithm(gpuAlgo);
     vari = ExtractVariant(gpuAlgo);
     prec = ExtractPrecision(gpuAlgo);
 }