Exemple #1
0
        internal void Construct()
        {
            m_components.Clear();

            m_visible = true;
            m_renderProxyDirty = true;

            m_ID = new MyIDTracker<MyActor>();
            m_localAabb = null;
            m_relativeTransform = null;

            Aabb = BoundingBoxD.CreateInvalid();
        }
        public static void IgnoreShadowForEntity(uint id, uint id2)
        {
            var light = Get(id);
            var actor = MyIDTracker <MyActor> .FindByID(id2);

            if (light != LightId.NULL && actor != null)
            {
                if (!m_ignoredShadowEntities.ContainsKey(light))
                {
                    m_ignoredShadowEntities[light] = new HashSet <uint>();
                }
                m_ignoredShadowEntities[light].Add(id2);
            }
        }
        internal override void Construct()
        {
            base.Construct();
            Type = MyActorComponentEnum.Instancing;


            m_capacity = 0;
            m_input = MyVertexInputLayout.Empty();
            m_ID = new MyIDTracker<MyInstancingComponent>();
            VB = VertexBufferId.NULL;
            
            if(m_owners == null)
            {
                m_owners = new List<MyActor>();
            }
            else
            {
                m_owners.Clear();
            }
        }
        internal static void Update()
        {
            foreach (var light in m_idIndex.Values)
            {
                if (m_pointlights[light.Index].Enabled || m_spotlights[light.Index].Enabled)
                {
                    var gid = light.ParentGID;
                    if (gid != -1 && MyIDTracker <MyActor> .FindByID((uint)gid) != null)
                    {
                        var matrix = MyIDTracker <MyActor> .FindByID((uint)gid).WorldMatrix;

                        Vector3D.Transform(ref m_lights.Data[light.Index].LocalPointPosition, ref matrix, out m_lights.Data[light.Index].PointPosition);

                        if (m_spotlights[light.Index].Enabled)
                        {
                            Vector3D.Transform(ref m_lights.Data[light.Index].LocalSpotPosition, ref matrix, out m_lights.Data[light.Index].SpotPosition);

                            Vector3.TransformNormal(ref m_lights.Data[light.Index].LocalDirection, ref matrix, out m_lights.Data[light.Index].Direction);
                            Vector3.TransformNormal(ref m_lights.Data[light.Index].LocalUp, ref matrix, out m_lights.Data[light.Index].Up);

                            m_spotlights[light.Index].ViewProjectionDirty = true;
                        }

                        CheckDirty(light);

                        if (light.FlareId != FlareId.NULL)
                        {
                            MyFlareRenderer.Update(light.FlareId);
                        }
                    }
                }
            }

            if (m_dirtyPointlights.Count > 0)
            {
                foreach (var id in m_dirtyPointlights)
                {
                    var proxy    = m_pointlights[id.Index].BvhProxyId;
                    var position = m_lights.Data[id.Index].PointPosition;
                    var range    = m_pointlights[id.Index].Light.Range;

                    var aabb = new BoundingBoxD(position - range, position + range);
                    m_pointlights[id.Index].BvhProxyId            = UpdateBvh(PointlightsBvh, id, m_pointlights[id.Index].Enabled, proxy, ref aabb);
                    m_pointlights[id.Index].LastBvhUpdatePosition = position;
                }

                m_dirtyPointlights.Clear();
            }

            if (m_dirtySpotlights.Count > 0)
            {
                foreach (var id in m_dirtySpotlights)
                {
                    var proxy    = m_spotlights[id.Index].BvhProxyId;
                    var position = m_lights.Data[id.Index].SpotPosition;
                    var dir      = m_lights.Data[id.Index].Direction;
                    var up       = m_lights.Data[id.Index].Up;

                    var aabb = MakeAabbFromSpotlightCone(ref m_spotlights[id.Index], position, dir, up);
                    m_spotlights[id.Index].BvhProxyId            = UpdateBvh(SpotlightsBvh, id, m_spotlights[id.Index].Enabled, proxy, ref aabb);
                    m_spotlights[id.Index].LastBvhUpdatePosition = position;
                    m_spotlights[id.Index].LastBvhUpdateDir      = dir;
                    m_spotlights[id.Index].LastBvhUpdateUp       = up;
                }

                m_dirtySpotlights.Clear();
            }

            BoundingFrustumD viewFrustumClippedD = MyRender11.Environment.Matrices.ViewFrustumClippedD;

            if (MyStereoRender.Enable)
            {
                if (MyStereoRender.RenderRegion == MyStereoRegion.LEFT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesLeftEye.ViewFrustumClippedD;
                }
                else if (MyStereoRender.RenderRegion == MyStereoRegion.RIGHT)
                {
                    viewFrustumClippedD = MyStereoRender.EnvMatricesRightEye.ViewFrustumClippedD;
                }
            }
            PointlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, MyLightsRendering.VisiblePointlights);
            SpotlightsBvh.OverlapAllFrustum(ref viewFrustumClippedD, MyLightsRendering.VisibleSpotlights);

            MyLightsRendering.VisibleSpotlights.Sort(new MyLightsCameraDistanceComparer());
        }