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;
 }
 public void Register(GPUShadowType type, ShadowPrecision precision, ShadowAlgorithm algorithm, string algorithmDescriptor, ShadowVariant[] variants, string[] variantDescriptors, VariantDelegate[] variantDelegates)
 {
     if (Validate(algorithmDescriptor, variants, variantDescriptors, variantDelegates))
     {
         Register(m_Entries[(int)type], precision, algorithm, algorithmDescriptor, variants, variantDescriptors, variantDelegates);
     }
 }
        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));
        }
        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
        }
 private void Register(Dictionary <ShadowAlgorithm, Entry> dict, ShadowPrecision precision, ShadowAlgorithm algorithm, string algorithmDescriptor, ShadowVariant[] variants, string[] variantDescriptors, VariantDelegate[] variantDelegates)
 {
     if (!dict.ContainsKey(algorithm))
     {
         Entry e;
         e.algorithmDesc     = algorithmDescriptor;
         e.variantsAvailable = variants.Length;
         e.variantDescs      = new string[ShadowConstants.Counts.k_ShadowVariant];
         e.variantDels       = new Dels[ShadowConstants.Counts.k_ShadowVariant];
         for (uint i = 0, cnt = (uint)variants.Length; i < cnt; ++i)
         {
             e.variantDescs[(uint)variants[i]] = variantDescriptors[i];
             if (precision == ShadowPrecision.Low)
             {
                 e.variantDels[(uint)variants[i]].low = variantDelegates[i];
             }
             else
             {
                 e.variantDels[(uint)variants[i]].high = variantDelegates[i];
             }
         }
         dict.Add(algorithm, e);
     }
     else
     {
         var entry = dict[algorithm];
         for (uint i = 0, cnt = (uint)variants.Length; i < cnt; ++i)
         {
             if (string.IsNullOrEmpty(entry.variantDescs[(uint)variants[i]]))
             {
                 entry.variantsAvailable++;
                 entry.variantDescs[(uint)variants[i]]     = variantDescriptors[i];
                 entry.variantDels[(uint)variants[i]].low  = precision == ShadowPrecision.Low  ? variantDelegates[i] : null;
                 entry.variantDels[(uint)variants[i]].high = precision == ShadowPrecision.High ? variantDelegates[i] : null;
             }
             else if (precision == ShadowPrecision.Low && entry.variantDels[(uint)variants[i]].low == null)
             {
                 entry.variantDels[(uint)variants[i]].low = variantDelegates[i];
             }
             else if (precision == ShadowPrecision.High && entry.variantDels[(uint)variants[i]].high == null)
             {
                 entry.variantDels[(uint)variants[i]].high = variantDelegates[i];
             }
             else
             {
                 Debug.Log("Tried to register variant " + variants[i] + " for algorithm " + algorithm + " with precision " + precision + ", but this variant is already registered. Skipping registration.");
             }
         }
     }
 }
 public static void Unpack(GPUShadowAlgorithm gpuAlgo, out ShadowAlgorithm algo, out ShadowVariant vari, out ShadowPrecision prec)
 {
     algo = ExtractAlgorithm(gpuAlgo);
     vari = ExtractVariant(gpuAlgo);
     prec = ExtractPrecision(gpuAlgo);
 }