public void Draw(Light l)
        {
            AdditionalLightData ald = l.GetComponent <AdditionalLightData>();

            Debug.Assert(ald != null, "Light has no valid AdditionalLightData component attached.");

            GPUShadowType shadowType;

            ShadowUtils.MapLightType(ald.archetype, l.type, out shadowType);

            // check if this has supported shadows
            if ((int)shadowType >= ShadowConstants.Counts.k_GPUShadowType)
            {
                return;
            }

            int  shadowAlgorithm;
            int  shadowVariant;
            int  shadowPrecision;
            bool globalOverride = m_GlobalOverrides[(int)shadowType].enabled;

            if (globalOverride)
            {
                shadowAlgorithm = (int)m_GlobalOverrides[(int)shadowType].algorithm;
                shadowVariant   = (int)m_GlobalOverrides[(int)shadowType].variant;
                shadowPrecision = (int)m_GlobalOverrides[(int)shadowType].precision;
            }
            else
            {
                ald.GetShadowAlgorithm(out shadowAlgorithm, out shadowVariant, out shadowPrecision);
            }

            DrawWidgets(l, shadowType, (ShadowAlgorithm)shadowAlgorithm, (ShadowVariant)shadowVariant, (ShadowPrecision)shadowPrecision, globalOverride);
        }
Beispiel #2
0
        static List <InputShadowLightData> GetInputShadowLightData(CullResults cullResults)
        {
            var shadowCasters         = new List <InputShadowLightData>();
            var lights                = cullResults.visibleLights;
            int directionalLightCount = 0;

            for (int i = 0; i < lights.Length; i++)
            {
                //@TODO: ignore baked. move this logic to c++...
                if (lights[i].light.shadows == LightShadows.None)
                {
                    continue;
                }

                // Only a single directional shadow casting light is supported
                if (lights[i].lightType == LightType.Directional)
                {
                    directionalLightCount++;
                    if (directionalLightCount != 1)
                    {
                        continue;
                    }
                }

                AdditionalLightData additionalLight = lights[i].light.GetComponent <AdditionalLightData>();

                InputShadowLightData light;
                light.lightIndex       = i;
                light.shadowResolution = AdditionalLightData.GetShadowResolution(additionalLight);

                shadowCasters.Add(light);
            }
            return(shadowCasters);
        }
        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];
                    }
                }
            }

            AdditionalLightData ald        = l.GetComponent <AdditionalLightData>();
            GPUShadowAlgorithm  packedAlgo = ShadowUtils.Pack(shadowAlgorithm, shadowVariant, shadowPrecision);
            int[] shadowData = null;
            if (!GUILayout.Button("Reset", GUILayout.MaxWidth(80.0f)))
            {
                shadowData = ald.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);
            }
            ald.SetShadowAlgorithm((int)shadowAlgorithm, (int)shadowVariant, (int)shadowPrecision, (int)packedAlgo, shadowData);

            UnityEditor.EditorGUI.indentLevel--;
#endif
        }