// Removes LOS Stencil Renderer and updates Culling Groups
        public void RemoveLOSStencilRenderer(LOSStencilRenderer stencilRenderer)
        {
            Debug.Assert(m_LOSStencilRenderers.Contains(stencilRenderer), "LOSStencilRenderer not found in list, can't remove");

            // Invoke Stencil Renderer removed event, before actually removing the Renderer.
            if (StencilRendererRemoved != null)
            {
                StencilRendererRemoved(stencilRenderer);
            }

            int index     = GetIndexOf(stencilRenderer);
            int lastIndex = m_LOSStencilRenderers.Count - 1;

            // Move the reference at the end of the list to the removed objects index.
            m_LOSStencilRenderers[index] = m_LOSStencilRenderers[lastIndex];
            m_BoundingSpheres[index]     = m_BoundingSpheres[lastIndex];

            // Remove the reference at the end of the list.
            m_LOSStencilRenderers.RemoveAt(lastIndex);

            Debug.Assert(!m_LOSStencilRenderers.Contains(stencilRenderer), "Remove failed");

            // Update Culling Groups.
            foreach (CullingGroup cullingGroup in m_CullingGroups.Values)
            {
                cullingGroup.EraseSwapBack(index);
                cullingGroup.SetBoundingSphereCount(m_LOSStencilRenderers.Count);
            }
        }
        private int GetIndexOf(LOSStencilRenderer stencilRenderer)
        {
            int index = m_LOSStencilRenderers.IndexOf(stencilRenderer);

            Debug.Assert(index >= 0, "Failed to get a valid index for LOS Stencil Renderer.");

            return(index);
        }
        /// <summary>
        /// Updates the Bounding Spheres of all Stencil Renderers whose Transform has changed
        /// </summary>
        public void UpdateBoundingSpheres()
        {
            for (int i = 0; i < m_LOSStencilRenderers.Count; ++i)
            {
                LOSStencilRenderer stencilRenderer = m_LOSStencilRenderers[i];

                if (!stencilRenderer.IsStatic && stencilRenderer.transform.hasChanged)
                {
                    m_BoundingSpheres[i] = stencilRenderer.RendererBoundingSphere;
                    stencilRenderer.transform.hasChanged = false;
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Subscribed to LOSManager event
        /// </summary>
        private void OnStencilRendererRemovedFromLOSManager(LOSStencilRenderer stencilRenderer)
        {
            if (m_Camera == null)
            {
                return;
            }

            // Remove the Command Buffer if the Stencil Renderer was visible before being removed
            if (LOSManager.Instance.IsLOSStencilRendererVisible(stencilRenderer, m_Camera))
            {
                m_Camera.RemoveCommandBuffer(ExcludeCameraEvent, stencilRenderer.RendererCommandBuffer);
            }
        }
        /// <summary>
        /// Returns if Stencil Renderer is visible to Camera
        /// </summary>
        public bool IsLOSStencilRendererVisible(LOSStencilRenderer stencilRenderer, Camera targetCamera)
        {
            bool isVisible = false;

            CullingGroup cullingGroup  = GetCullingGroup(targetCamera);
            int          rendererIndex = GetIndexOf(stencilRenderer);

            if (cullingGroup != null && rendererIndex >= 0)
            {
                isVisible = cullingGroup.IsVisible(rendererIndex);
            }

            return(isVisible);
        }
        /// <summary>
        /// Returns LOS Stencil Renderer at given index
        /// </summary>
        public LOSStencilRenderer this[int index]
        {
            get
            {
                LOSStencilRenderer stencilRenderer = null;

                if (index >= 0 && index < m_LOSStencilRenderers.Count)
                {
                    stencilRenderer = m_LOSStencilRenderers[index];
                }

                Debug.Assert(stencilRenderer != null, "Failed to return LOSStencilRenderer");

                return(stencilRenderer);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Culling Group Callback.
        /// Adds or removes Command Buffer to / from Camera based on LOSStencilRenderer visibility.
        /// </summary>
        private void OnCullingGroupStateChanged(CullingGroupEvent evt)
        {
            LOSStencilRenderer stencilRenderer = LOSManager.Instance[evt.index];

            if (stencilRenderer != null)
            {
                if (evt.hasBecomeVisible)
                {
                    m_Camera.AddCommandBuffer(ExcludeCameraEvent, stencilRenderer.RendererCommandBuffer);
                }
                else if (evt.hasBecomeInvisible)
                {
                    m_Camera.RemoveCommandBuffer(ExcludeCameraEvent, stencilRenderer.RendererCommandBuffer);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            LOSStencilRenderer targetScript = target as LOSStencilRenderer;

            m_IsDynamicBatchingDisabled.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Prevent Dynamic Batching", "Prevents Renderer from being batched"), m_IsDynamicBatchingDisabled.boolValue);

            if (m_IsDynamicBatchingDisabled.boolValue)
            {
                if (targetScript.IsStatic)
                {
                    EditorGUILayout.HelpBox("The GameObject this component is attached to is marked as static. This setting will be ignored.", MessageType.Warning);
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
        // Adds LOS Stencil Renderer and updates Culling Groups
        public void AddLOSStencilRenderer(LOSStencilRenderer stencilRenderer)
        {
            Debug.Assert(!m_LOSStencilRenderers.Contains(stencilRenderer), "LOSStencilRenderer already in list, can't add");

            int index = m_LOSStencilRenderers.Count;

            m_LOSStencilRenderers.Add(stencilRenderer);

            // Increase the capacity of the Bounding Spheres Array if needed
            if (m_BoundingSpheres.Length <= index)
            {
                IncreaseBoundingSphereArrayCapacity();
            }

            m_BoundingSpheres[index] = stencilRenderer.RendererBoundingSphere;

            Debug.Assert(m_LOSStencilRenderers.IndexOf(stencilRenderer) == index, "Index Mismatch!");

            // Update Culling Groups.
            foreach (CullingGroup cullingGroup in m_CullingGroups.Values)
            {
                cullingGroup.SetBoundingSphereCount(m_LOSStencilRenderers.Count);
            }
        }