Exemplo n.º 1
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.º 2
0
        public void Draw(Light l)
        {
            AdditionalShadowData asd = l.GetComponent <AdditionalShadowData>();

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

            GPUShadowType shadowType = GetShadowLightType(l);

            // 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
            {
                asd.GetShadowAlgorithm(out shadowAlgorithm, out shadowVariant, out shadowPrecision);
            }

            DrawWidgets(l, shadowType, (ShadowAlgorithm)shadowAlgorithm, (ShadowVariant)shadowVariant, (ShadowPrecision)shadowPrecision, globalOverride);
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
        public bool GetGlobalShadowOverride(GPUShadowType shadowType, ref GPUShadowAlgorithm algo)
        {
            if (m_GlobalOverrides[(int)shadowType].enabled)
            {
                algo = ShadowUtils.Pack(m_GlobalOverrides[(int)shadowType].algorithm, m_GlobalOverrides[(int)shadowType].variant, m_GlobalOverrides[(int)shadowType].precision);
            }

            return(m_GlobalOverrides[(int)shadowType].enabled);
        }
Exemplo n.º 5
0
            protected override void PruneShadowCasters(Camera camera, VisibleLight[] lights, ref VectorArray <int> shadowRequests, ref ShadowRequestVector requestsGranted, out uint totalRequestCount)
            {
                Debug.Assert(shadowRequests.Count() > 0);
                // at this point the array is sorted in order of some importance determined by the prioritize function
                requestsGranted.Reserve(shadowRequests.Count());
                totalRequestCount = 0;

                ShadowmapBase.ShadowRequest sreq = new ShadowmapBase.ShadowRequest();
                uint totalSlots = ResetMaxShadows();

                // there's a 1:1 mapping between the index in the shadowRequests array and the element in requestsGranted at the same index.
                // if the prune function skips requests it must make sure that the array is still compact
                m_TmpSortKeys.Reset(shadowRequests.Count());
                for (uint i = 0, count = shadowRequests.Count(); i < count && totalSlots > 0; ++i)
                {
                    int           requestIdx = shadowRequests[i];
                    VisibleLight  vl         = lights[requestIdx];
                    bool          add        = false;
                    int           facecount  = 0;
                    GPUShadowType shadowType = GPUShadowType.Point;

                    switch (vl.lightType)
                    {
                    case LightType.Directional: add = m_MaxShadows[(int)GPUShadowType.Directional, 0]-- >= 0; shadowType = GPUShadowType.Directional; facecount = m_ShadowSettings.directionalLightCascadeCount; break;

                    case LightType.Point: add = m_MaxShadows[(int)GPUShadowType.Point, 0]-- >= 0; shadowType = GPUShadowType.Point; facecount = 6; break;

                    case LightType.Spot: add = m_MaxShadows[(int)GPUShadowType.Spot, 0]-- >= 0; shadowType = GPUShadowType.Spot; facecount = 1; break;
                    }

                    if (add)
                    {
                        sreq.instanceId    = vl.light.GetInstanceID();
                        sreq.index         = (uint)requestIdx;
                        sreq.facemask      = (uint)(1 << facecount) - 1;
                        sreq.shadowType    = shadowType;
                        totalRequestCount += (uint)facecount;
                        requestsGranted.AddUnchecked(sreq);
                        totalSlots--;
                    }
                    else
                    {
                        m_TmpSortKeys.AddUnchecked(requestIdx);
                    }
                }
                // make sure that shadowRequests contains all light indices that are going to cast a shadow first, then the rest
                shadowRequests.Reset();
                requestsGranted.ExtractTo(ref shadowRequests, (ShadowmapBase.ShadowRequest request) => { return((int)request.index); });
                m_TmpSortKeys.ExtractTo(ref shadowRequests, (long idx) => { return((int)idx); });
            }
Exemplo n.º 6
0
        public static bool MapLightType(LightType lt, out GPULightType gputype, out GPUShadowType shadowtype)
        {
            switch (lt)
            {
            case LightType.Spot: gputype = GPULightType.Spot;          shadowtype = GPUShadowType.Spot;        return(true);

            case LightType.Directional: gputype = GPULightType.Directional;   shadowtype = GPUShadowType.Directional; return(true);

            case LightType.Point: gputype = GPULightType.Point;         shadowtype = GPUShadowType.Point;       return(true);

            default:
            case LightType.Area: gputype = GPULightType.Rectangle; shadowtype = GPUShadowType.Unknown; return(false);           // area lights by themselves can't be mapped to any GPU type
            }
        }
        public static bool MapLightType(LightArchetype la, LightType lt, out GPUShadowType shadowtype)
        {
            switch (la)
            {
            case LightArchetype.Punctual:
                return(MapLightType(lt, out shadowtype));

            case LightArchetype.Area:
                shadowtype = GPUShadowType.Unknown;
                return(true);

            case LightArchetype.Projector:
                shadowtype = GPUShadowType.Unknown;
                return(true);

            default:
                shadowtype = GPUShadowType.Unknown;
                return(false);    // <- probably not what you want
            }
        }
Exemplo n.º 8
0
        // default implementation based on legacy Unity
        static public GPUShadowType ShadowLightType(Light l)
        {
            GPUShadowType shadowType = GPUShadowType.Unknown;

            switch (l.type)
            {
            case LightType.Spot:
                shadowType = GPUShadowType.Spot;
                break;

            case LightType.Directional:
                shadowType = GPUShadowType.Directional;
                break;

            case LightType.Point:
                shadowType = GPUShadowType.Point;
                break;
                // area lights by themselves can't be mapped to any GPU type
            }

            return(shadowType);
        }
Exemplo n.º 9
0
 public void PackShadowType(GPUShadowType type, GPUShadowAlgorithm algorithm)
 {
     shadowType = (uint)type << ShadowConstants.Bits.k_GPUShadowAlgorithm | (uint)algorithm;
 }
Exemplo n.º 10
0
 void SetGlobalOverrideEnabled(GPUShadowType shadowType, bool enabled)
 {
     m_GlobalOverrides[(int)shadowType].enabled = enabled;
 }
Exemplo n.º 11
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
        }
Exemplo n.º 12
0
        public static bool MapLightType(LightArchetype la, LightType lt, out GPULightType gputype, out GPUShadowType shadowtype)
        {
            switch (la)
            {
            case LightArchetype.Punctual: return(MapLightType(lt, out gputype, out shadowtype));

            case LightArchetype.Rectangle: gputype = GPULightType.Rectangle; shadowtype = GPUShadowType.Unknown; return(true);

            case LightArchetype.Line: gputype = GPULightType.Line; shadowtype = GPUShadowType.Unknown; return(true);

            default: gputype = GPULightType.Spot; shadowtype = GPUShadowType.Unknown; return(false);                         // <- probably not what you want
            }
        }
Exemplo n.º 13
0
        public static bool MapLightType(LightType lt, AdditionalLightData ald, out GPULightType gputype, out GPUShadowType shadowtype)
        {
            shadowtype = GPUShadowType.Unknown; // Default for all non-punctual lights
            gputype    = GPULightType.Spot;

            switch (ald.archetype)
            {
            case LightArchetype.Punctual:  return(MapLightType(lt, out gputype, out shadowtype));

            case LightArchetype.Area:      gputype = (ald.lightWidth > 0) ? GPULightType.Rectangle : GPULightType.Line; return(true);

            case LightArchetype.Projector:
                switch (lt)
                {
                case LightType.Directional: gputype = GPULightType.ProjectorOrtho;   return(true);

                case LightType.Spot:        gputype = GPULightType.ProjectorPyramid; return(true);

                default: Debug.Assert(false, "Projectors can only be Spot or Directional lights."); return(false);
                }

            default: return(false);    // <- probably not what you want
            }
        }