public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (m_ShadowRegistry == null)
            {
                return;
            }

            AdditionalLightData ald = (AdditionalLightData)target;

            if (ald == null)
            {
                return;
            }

            UnityEditor.EditorGUI.BeginChangeCheck();
            m_ShadowRegistry.Draw(ald.gameObject.GetComponent <Light>());
            serializedObject.Update();
            if (UnityEditor.EditorGUI.EndChangeCheck())
            {
                UnityEditor.EditorUtility.SetDirty(ald);
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                UnityEditor.SceneView.RepaintAll();
            }
            serializedObject.ApplyModifiedProperties();
        }
Beispiel #2
0
 public static int GetShadowResolution(AdditionalLightData lightData)
 {
     if (lightData != null)
     {
         return(lightData.shadowResolution);
     }
     else
     {
         return(DefaultShadowResolution);
     }
 }
 public static float GetInnerSpotPercent01(AdditionalLightData lightData)
 {
     if (lightData != null)
     {
         return(Mathf.Clamp(lightData.innerSpotPercent, 0.0f, 100.0f) / 100.0f);
     }
     else
     {
         return(0.0F);
     }
 }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (m_ShadowRegistry == null)
            {
                return;
            }

            AdditionalLightData ald = (AdditionalLightData)target;

            if (ald == null)
            {
                return;
            }

            UnityEditor.EditorGUI.BeginChangeCheck();

            m_ShadowRegistry.Draw(ald.gameObject.GetComponent <Light>());
            serializedObject.Update();

            // cascade code
            if (ald.gameObject.GetComponent <Light>().type == LightType.Directional)
            {
                UnityEditor.EditorGUI.BeginChangeCheck();
                UnityEditor.EditorGUILayout.PropertyField(m_ShadowCascadeCount);
                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    const int kMaxCascades = (int)ShadowAtlas.k_MaxCascadesInShader;  // depending on where you look this is either 32 or 4, so we're limiting it to 4 for now
                    int       newcnt       = m_ShadowCascadeCount.intValue <= 0 ? 1 : (m_ShadowCascadeCount.intValue > kMaxCascades ? kMaxCascades : m_ShadowCascadeCount.intValue);
                    m_ShadowCascadeCount.intValue   = newcnt;
                    m_ShadowCascadeRatios.arraySize = newcnt - 1;
                }
                UnityEditor.EditorGUI.indentLevel++;
                for (int i = 0; i < m_ShadowCascadeRatios.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeRatios.GetArrayElementAtIndex(i), 0.0f, 1.0f, new GUIContent("Cascade " + i));
                }
                UnityEditor.EditorGUI.indentLevel--;
            }

            if (UnityEditor.EditorGUI.EndChangeCheck())
            {
                UnityEditor.EditorUtility.SetDirty(ald);
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                UnityEditor.SceneView.RepaintAll();
            }
            serializedObject.ApplyModifiedProperties();
        }
Beispiel #5
0
            protected override void AllocateShadows(FrameId frameId, VisibleLight[] lights, uint totalGranted, ref ShadowRequestVector grantedRequests, ref ShadowIndicesVector shadowIndices, ref ShadowDataVector shadowDatas, ref ShadowPayloadVector shadowmapPayload)
            {
                ShadowData sd = new ShadowData();

                shadowDatas.Reserve(totalGranted);
                shadowIndices.Reserve(grantedRequests.Count());
                for (uint i = 0, cnt = grantedRequests.Count(); i < cnt; ++i)
                {
                    VisibleLight        vl  = lights[grantedRequests[i].index];
                    Light               l   = vl.light;
                    AdditionalLightData ald = l.GetComponent <AdditionalLightData>();

                    // set light specific values that are not related to the shadowmap
                    GPUShadowType shadowtype;
                    ShadowUtils.MapLightType(ald.archetype, vl.lightType, out sd.lightType, out shadowtype);
                    sd.bias    = l.shadowBias;
                    sd.quality = 0;

                    shadowIndices.AddUnchecked((int)shadowDatas.Count());

                    int smidx = 0;
                    while (smidx < k_MaxShadowmapPerType)
                    {
                        if (m_ShadowmapsPerType[(int)shadowtype, smidx].Reserve(frameId, ref sd, grantedRequests[i], (uint)ald.shadowResolution, (uint)ald.shadowResolution, ref shadowDatas, ref shadowmapPayload, lights))
                        {
                            break;
                        }
                        smidx++;
                    }
                    if (smidx == k_MaxShadowmapPerType)
                    {
                        throw new ArgumentException("The requested shadows do not fit into any shadowmap.");
                    }
                }

                // final step for shadowmaps that only gather data during the previous loop and do the actual allocation once they have all the data.
                foreach (var sm in m_Shadowmaps)
                {
                    if (!sm.ReserveFinalize(frameId, ref shadowDatas, ref shadowmapPayload))
                    {
                        throw new ArgumentException("Shadow allocation failed in the ReserveFinalize step.");
                    }
                }
            }
Beispiel #6
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
            }
        }