public static void UpdateFlare(LightId id, ref MyFlareDesc glare)
        {
            var oldFlareId = m_lights.Data[id.Index].FlareId;

            m_lights.Data[id.Index].FlareId = MyFlareRenderer.Set(m_lights.Data[id.Index].FlareId, glare);
            if (m_lights.Data[id.Index].FlareId != FlareId.NULL && !m_spotlights[id.Index].Enabled && !m_pointlights[id.Index].Enabled)
            {
                DistantFlaresWithoutLight.Add(id);
            }
            else if (oldFlareId != FlareId.NULL)
            {
                DistantFlaresWithoutLight.Remove(id);
            }
        }
        private static void Remove(uint GID, LightId id)
        {
            m_idIndex.Remove(GID);

            if (m_pointlights[id.Index].BvhProxyId != -1)
            {
                PointlightsBvh.RemoveProxy(m_pointlights[id.Index].BvhProxyId);
            }

            if (m_spotlights[id.Index].BvhProxyId != -1)
            {
                SpotlightsBvh.RemoveProxy(m_spotlights[id.Index].BvhProxyId);
            }
            MyFlareRenderer.Remove(id.FlareId);
            m_dirtyPointlights.Remove(id);
            m_dirtySpotlights.Remove(id);
            m_ignoredShadowEntities.Remove(id);
            m_lights.Free(id.Index);
        }
Beispiel #3
0
 internal static void DrawFlares()
 {
     foreach (var id in MyLights.DistantFlaresWithoutLight)
     {
         if (id.FlareId != FlareId.NULL)
         {
             MyFlareRenderer.Draw(id.FlareId, id.PointPosition);
         }
     }
     foreach (var id in VisiblePointlights)
     {
         if (id.FlareId != FlareId.NULL && !MyLights.GetSpotlights()[id.Index].Enabled)
         {
             MyFlareRenderer.Draw(id.FlareId, id.PointPosition);
         }
     }
     foreach (var id in VisibleSpotlights)
     {
         if (id.FlareId != FlareId.NULL)
         {
             MyFlareRenderer.Draw(id.FlareId, id.SpotPosition);
         }
     }
 }
        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());
        }