Example #1
0
        public static void UpdateLightProxy(MyLight light)
        {
            if ((!light.LightOn || light.LightType == MyLight.LightTypeEnum.None) && light.ProxyId != MyDynamicAABBTree.NullNode)
            {
                m_tree.RemoveProxy(light.ProxyId);
                light.ProxyId = MyDynamicAABBTree.NullNode;
            }

            BoundingBox bbox = BoundingBoxHelper.InitialBox;

            if (light.IsTypePoint || light.IsTypeHemisphere)
            {
                bbox = BoundingBox.CreateFromSphere(light.PointBoundingSphere);
            }
            if (light.IsTypeSpot)
            {
                var box = light.SpotBoundingBox;
                BoundingBoxHelper.AddBBox(box, ref bbox);
            }

            if (light.ProxyId == MyDynamicAABBTree.NullNode)
            {
                light.ProxyId = m_tree.AddProxy(ref bbox, light, 0);
            }
            else
            {
                m_tree.MoveProxy(light.ProxyId, ref bbox, Vector3.Zero);
            }
        }
Example #2
0
 public void Close()
 {
     if (Light != null)
     {
         MyLights.RemoveLight(Light);
         Light = null;
     }
 }
Example #3
0
 public static void RemoveLight(MyLight light)
 {
     if (light.ProxyId != MyDynamicAABBTree.NullNode) // Has been added
     {
         m_tree.RemoveProxy(light.ProxyId);
     }
     light.Clear();
     m_preallocatedLights.Deallocate(light);
 }
Example #4
0
 public void Start(float lightSize)
 {
     if (lightSize > 0)
     {
         Light = MyLights.AddLight();
         Light.Color = Vector4.One;
         Light.Start(MyLight.LightTypeEnum.PointLight, 1.0f);
         Light.LightOn = lightSize > 0;
         Light.Intensity = 10;
     }
 }
Example #5
0
 public MyPrefabLamp(Vector3 position, float radiusMin, float radiusMax, int timerForBlic)
 {
     Position = position;
     RadiusMin = radiusMin;
     RadiusMax = radiusMax;
     TimerForBlic = timerForBlic;
     Light = MyLights.AddLight();
     Light.Start(MyLight.LightTypeEnum.PointLight, position, Vector4.One, 1, radiusMin);
     Light.Intensity = 1;
     Light.LightOn = true;
 }
Example #6
0
        static void SetLightToEffect(MyEffectDynamicLightingBase effect, int index, MyLight light, bool subtractCameraPosition)
        {
            if (subtractCameraPosition == true)
            {
                effect.SetDynamicLightsPosition(index, light.Position - MyCamera.Position);
            }
            else
            {
                effect.SetDynamicLightsPosition(index, light.Position);
            }

            effect.SetDynamicLightsColor(index, light.Color * light.Intensity);
            effect.SetDynamicLightsFalloff(index, light.Falloff);
            effect.SetDynamicLightsRange(index, light.Range);
        }
 public MyLightProperties(Vector4 color, Vector3 specularColor, float fallOff, float range, float intensity, float pointLightOffSet, Vector4 reflectorColor,
     float reflectorFallOff, float reflectorRange, float reflectorIntensity, float reflectorConeDegrees, MyLight.LightTypeEnum lightType, MyPrefabLight prefabLight, float flashOffset)
 {
     Color = color;
     SpecularColor = specularColor;
     FallOff = fallOff;
     Range = range;
     Intensity = intensity;
     PointLightOffSet = pointLightOffSet;
     ReflectorColor = reflectorColor;
     ReflectorFallOff = reflectorFallOff;
     ReflectorRange = reflectorRange;
     ReflectorIntensity = reflectorIntensity;
     ReflectorConeDegrees = reflectorConeDegrees;
     LightType = lightType;
     PrefabLight = prefabLight;
     FlashOffset = flashOffset;
 }
Example #8
0
        //  Kills this missile. Must be called at her end (after explosion or timeout)
        public override void Close()
        {
            base.Close();

            if (m_collidedEntity != null)
            {
                m_collidedEntity.OnClose -= m_collidedEntityClosedHandler;
                m_collidedEntity = null;
            }

            //  Free the light
            if (m_light != null)
            {
                MyLights.RemoveLight(m_light);
                m_light = null;
            }

            //  Stop thruster cue
            if ((m_thrusterCue != null) && (m_thrusterCue.Value.IsPlaying == true))
            {
                m_thrusterCue.Value.Stop(SharpDX.XACT3.StopFlags.Immediate);
            }

            if (m_smokeEffect != null)
            {
                m_smokeEffect.Stop();
                m_smokeEffect = null;
            }

            MyCannonShots.Remove(this);
        }
Example #9
0
 internal void RemoveLight()
 {
     if (m_light != null)
     {
         MyLights.RemoveLight(m_light);
         m_light = null;
     }
 }
Example #10
0
 public void Close()
 {
     m_explosionCue = null;
     if (m_light != null)
     {
         MyLights.RemoveLight(m_light);
         m_light = null;
     }
 }
        private void SetRenderSetup()
        {
            return;
            m_setup = new MyRender.MyRenderSetup();

            //m_setup.Fov = MathHelper.ToRadians(75);

            m_setup.CallerID = MyRenderCallerEnum.GUIPreview;
                                    
            m_setup.RenderTargets = new Texture[1];


            m_setup.EnabledModules = new HashSet<MyRenderModuleEnum>();
            m_setup.EnabledModules.Add(MyRenderModuleEnum.VoxelHand);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.Decals);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.CockpitWeapons);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.SectorBorder);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.DrawSectorBBox);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.DrawCoordSystem);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.Explosions);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.BackgroundCube);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.GPS);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.TestField);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.AnimatedParticles);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.Lights);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.TransparentGeometryForward);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.Projectiles);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.DebrisField);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.ThirdPerson);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.Editor);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.SolarObjects);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.SolarMapGrid);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.PrunningStructure);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.SunWind);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.IceStormWind);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.PrefabContainerManager);
            m_setup.EnabledModules.Add(MyRenderModuleEnum.PhysicsPrunningStructure);

            m_setup.EnabledRenderStages = new HashSet<MyRenderStage>();
            m_setup.EnabledRenderStages.Add(MyRenderStage.PrepareForDraw);
            m_setup.EnabledRenderStages.Add(MyRenderStage.Background);
            m_setup.EnabledRenderStages.Add(MyRenderStage.LODDrawStart);
            m_setup.EnabledRenderStages.Add(MyRenderStage.LODDrawEnd);
            m_setup.EnabledRenderStages.Add(MyRenderStage.AlphaBlendPreHDR);
            m_setup.EnabledRenderStages.Add(MyRenderStage.AlphaBlend);

 

            m_setup.EnabledPostprocesses = new HashSet<MyPostProcessEnum>();
            m_setup.EnabledPostprocesses.Add(MyPostProcessEnum.VolumetricSSAO2);
            m_setup.EnabledPostprocesses.Add(MyPostProcessEnum.HDR);
            

            //m_setup.BackgroundColor = new Color(0.17f, 0.18f, .25f, 0.0f);
            m_setup.BackgroundColor = new Color(Vector4.Zero);

            m_setup.EnableHDR = false;
            m_setup.EnableSun = true;
            m_setup.ShadowRenderer = MyRender.GetShadowRenderer(); // Default shadow render
            m_setup.EnableSmallLights = true;
            m_setup.EnableDebugHelpers = false;
            m_setup.EnableEnvironmentMapping = false;
            m_setup.EnableOcclusionQueries = false;

            m_setup.LodTransitionNear = 20000;
            m_setup.LodTransitionFar = 21000;
            m_setup.LodTransitionBackgroundStart = 50000;
            m_setup.LodTransitionBackgroundStart = 51000;

            m_setup.RenderElementsToDraw = new List<MyRender.MyRenderElement>();
            m_setup.TransparentRenderElementsToDraw = new List<MyRender.MyRenderElement>();
            m_setup.LightsToUse = new List<MyLight>();
            var fillLight = new MyLight();
            fillLight.Start(MyLight.LightTypeEnum.PointLight, .5f * new Vector4(1, 0.95f, 0.8f, 1), 1, 119); // fill light
            m_setup.LightsToUse.Add(fillLight);
            var backLight = new MyLight();
            backLight.Start(MyLight.LightTypeEnum.PointLight, .5f * new Vector4(1, 0.9f, 0.9f, 1), 1, 119); // back light
            m_setup.LightsToUse.Add(backLight);  
        }
Example #12
0
 public override void Close()
 {
     MyLights.RemoveLight(m_pointLight);
     m_pointLight = null;
     base.Close();            
 }
Example #13
0
        public MyLightGlare(MyLight light)
        {
            m_parent = light;
            m_occlusionBox = new BoundingBox();

            m_occlusionQuery = MyOcclusionQueries.Get();
            m_measurementQuery = MyOcclusionQueries.Get();
        }
Example #14
0
        public static void Draw()
        {
            if (MyFakes.TEST_MISSION_1_ENABLED)
            {

                if (m_remainingPrimaryTargetsCounter == 0)
                {
                    if (m_russianDropZoneLight != null)
                    {
                        Vector3 dir = MyMwcUtils.Normalize(MyCamera.Position - RUSSIAN_DROP_ZONE_POSITION);

                        float timeBlic = MyMinerGame.TotalGamePlayTimeInMilliseconds % 980;
                        if (timeBlic > 250) timeBlic = 980 - timeBlic;
                        timeBlic = MathHelper.Clamp(1 - timeBlic / 250, 0, 1);

                        float alpha = MathHelper.Lerp(0.1f, 0.6f, timeBlic);

                        m_dropZoneLightColor.W = alpha;
                        m_russianDropZoneLight.Start(MyLight.LightTypeEnum.PointLight, RUSSIAN_DROP_ZONE_POSITION, m_dropZoneLightColor, 1, 200);

                        float radius = MathHelper.Lerp(0.1f, 150f, timeBlic);

                        MyTransparentGeometry.AddPointBillboard(MyTransparentMaterialEnum.ReflectorGlareAlphaBlended, m_dropZoneLightColor,
                                    RUSSIAN_DROP_ZONE_POSITION + dir * 5, radius, 0);
                    }
                    else
                    {
                        m_russianDropZoneLight = MyLights.AddLight();
                        if (m_russianDropZoneLight != null)
                        {
                            m_russianDropZoneLight.Start(MyLight.LightTypeEnum.PointLight, 1);
                        }
                    }
                }
            }
        }
Example #15
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public void Start(Vector3 position, Vector3 initialVelocity, Vector3 directionNormalized, MyMwcObjectBuilder_SmallShip_Ammo usedAmmo, MySmallShip minerShip)
        {
            m_usedAmmo = usedAmmo;
            m_ammoProperties = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);
            m_gameplayProperties = MyGameplayConstants.GetGameplayProperties(m_usedAmmo, Faction);
            m_penetratedVoxelMap = null;
            m_wasPenetration = false;
            m_hasExplosion = false;
            m_isExploded = false;
            m_collidedEntity = null;
            m_collisionPoint = null;
                
            Matrix orientation = GetWorldRotation();
            Vector3 pos = position;

            //  Play missile thrust cue (looping)
            m_thrusterCue = MyAudio.AddCue3D(MySoundCuesEnum.WepMissileFly, pos, orientation.Forward, orientation.Up, this.Physics.LinearVelocity);

            m_light = MyLights.AddLight();
            if (m_light != null)
            {
                m_light.Start(MyLight.LightTypeEnum.PointLight, GetPosition(), MyMissileHelperUtil.GetCannonShotLightColor(), 1, MyMissileConstants.MISSILE_LIGHT_RANGE);
            }

            m_diffuseColor = m_ammoProperties.TrailColor;

            switch (usedAmmo.AmmoType)
            {
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Basic:
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_High_Speed:
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Armor_Piercing_Incendiary:
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_SAPHEI:
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive:
                    m_explosionType = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                    break;
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_BioChem:
                    m_explosionType = MyExplosionTypeEnum.BIOCHEM_EXPLOSION;
                    break;
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_EMP:
                    m_explosionType = MyExplosionTypeEnum.EMP_EXPLOSION;
                    break;
                case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster:
                    m_explosionType = MyExplosionTypeEnum.BLASTER_EXPLOSION;
                    break;
                default:
                    throw new MyMwcExceptionApplicationShouldNotGetHere();
                    break;
            }

            this.Physics.Mass = m_gameplayProperties.WeightPerUnit;

            Vector3? correctedDirection = null;
            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                if (minerShip == MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip)
                {
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(minerShip, position, m_ammoProperties.MaxTrajectory);
                }
            }

            if (correctedDirection != null)
                directionNormalized = correctedDirection.Value;

            base.Start(position, initialVelocity, directionNormalized, m_ammoProperties.DesiredSpeed, minerShip);

            if (correctedDirection != null) //override the base class behaviour, update the missile direction
            {
                Matrix ammoWorld = minerShip.WorldMatrix;
                ammoWorld.Translation = position;
                ammoWorld.Forward = correctedDirection.Value;

                SetWorldMatrix(ammoWorld);
            }

            m_smokeEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot);
            m_smokeEffect.AutoDelete = false;
            m_smokeEffect.WorldMatrix = WorldMatrix;
        }
Example #16
0
 //  IMPORTANT: This class isn't realy inicialized by constructor, but by Start()
 //  Copies values from 'sourceLight' into this instance
 public void Start(MyLight sourceLight)
 {
     //SysUtils.Utils.MyCommonDebugUtils.AssertDebug((sourceLight.LightType & LightTypeEnum.PointLight) != 0 && ReflectorTexture == null, "ReflectorTexture is null!");
     Start(sourceLight.LightType, sourceLight.Position, sourceLight.Color, sourceLight.Falloff, sourceLight.Range);
 }
Example #17
0
        protected override void InitPrefab(string displayName, Vector3 relativePosition, Matrix localOrientation, MyMwcObjectBuilder_PrefabBase objectBuilder, MyPrefabConfiguration prefabConfig)
        {

            m_prefabLightConfig = prefabConfig as MyPrefabConfigurationLight;
            MyMwcObjectBuilder_PrefabLight objectBuilderLight = objectBuilder as MyMwcObjectBuilder_PrefabLight;            

            m_light = MyLights.AddLight();

            m_light.LightType = (MyLight.LightTypeEnum)objectBuilderLight.LightType;

            m_light.Start(m_light.LightType, 1);
            m_light.UseInForwardRender = true;


            //grab first dummy and set it as point source
            //since we dont support yet more lights in one prefab. add just the first one
            MyModel model = MyModels.GetModelOnlyDummies(m_prefabLightConfig.ModelLod0Enum);

            m_pointLocalMatrix = Matrix.Identity;
            bool dummyFound = false;
            foreach (KeyValuePair<string, MyModelDummy> pair in model.Dummies)
            {
                if (pair.Key.StartsWith("Dummy", StringComparison.InvariantCultureIgnoreCase))
                {
                    m_pointLocalMatrix = pair.Value.Matrix;
                    dummyFound = true;
                    break;
                }
            }
            Debug.Assert(dummyFound, "Dummy 'POINT_LIGHT_POS' not found in light prefab model: " + model.AssetName);

            m_light.Color = objectBuilderLight.PointColor;
            m_light.ReflectorColor = objectBuilderLight.SpotColor;
            m_light.Falloff = objectBuilderLight.PointFalloff;
            m_light.ReflectorFalloff = objectBuilderLight.SpotFalloff;
            m_IntensityMax = m_light.Intensity = objectBuilderLight.PointIntensity;
            m_light.ReflectorIntensity = ReflectorIntensityMax = objectBuilderLight.SpotIntensity;
            m_light.ReflectorRange = MathHelper.Clamp(objectBuilderLight.SpotRange, 1, MyLightsConstants.MAX_SPOTLIGHT_RANGE);
            m_light.Range = MathHelper.Clamp(objectBuilderLight.PointRange, 1, MyLightsConstants.MAX_POINTLIGHT_RADIUS);
            m_light.PointLightOffset = objectBuilderLight.PointOffset;
            this.FlashOffset = objectBuilderLight.FlashOffset;

            //to add reflector range to builders
            m_light.SpecularColor = objectBuilderLight.PointSpecular;
            m_light.ReflectorConeDegrees = objectBuilderLight.SpotAgle;
            m_effect = objectBuilderLight.Effect;
            //m_light.LightOn = true;
            m_lastBlickChange = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            // here set the properties of glare for the prefab light
            m_light.GlareOn = true;
            m_light.Glare.Type = MyLightGlare.GlareTypeEnum.Normal;
            m_light.Glare.QuerySize = .8f;
            m_light.ShadowDistance = objectBuilderLight.ShadowsDistance;
            m_light.Glare.Intensity = m_light.Intensity;
            UpdateEffect();

            CastShadows = false;
            UpdateLightWorldMatrix();            
        }
Example #18
0
        private void InitLight()
        {
            m_pointLight = MyLights.AddLight();

            m_pointLight.LightType = MyLight.LightTypeEnum.PointLight;

            m_pointLight.Start(m_pointLight.LightType, 1);
            m_pointLight.UseInForwardRender = true;


            //grab first dummy and set it as point source
            //since we dont support yet more lights in one prefab. add just the first one
            MyModel model = MyModels.GetModelOnlyDummies(ModelLod0.ModelEnum);
            m_pointLocalMatrix = Matrix.CreateTranslation(model.BoundingSphere.Center);            
            
            m_pointLight.Color = new Vector4(1f, 0f, 0f, 1f);
            m_pointLight.ReflectorColor = Vector4.Zero;
            m_pointLight.Falloff = 0.1f;
            m_pointLight.ReflectorFalloff = 0.1f;
            m_intensityMax = m_pointLight.Intensity = 10f;            
            m_pointLight.ReflectorIntensity = 1f;            
            m_pointLight.ReflectorRange = 1f;
            m_pointLight.Range = 40f;
            m_pointLight.PointLightOffset = 0f;

            //to add reflector range to builders
            m_pointLight.SpecularColor = new Vector3(1f, 0f, 0f);
            m_pointLight.ReflectorConeDegrees = 0.1f;
            m_lastBlickChange = MyMinerGame.TotalGamePlayTimeInMilliseconds;

            // here set the properties of glare for the prefab light            
            m_pointLight.GlareOn = true;
            m_pointLight.Glare.Type = MyLightGlare.GlareTypeEnum.Distant;            
            m_pointLight.Glare.QuerySize = .8f;
            UpdateLightWorldMatrix();
        }
Example #19
0
        private static void AddSpotLightRenderElement(MyLight light)
        {
            float cosAngle = 1 - light.ReflectorConeMaxAngleCos;

            // Near clip is 5 to prevent cockpit bugs
            float nearClip = 5;
            float c = nearClip / cosAngle;

            // 'a' is "screen size" at near clip (a, c and nearclip makes right triangle)
            float a = (float)Math.Sqrt(c * c - nearClip * nearClip);
            if (nearClip < light.ReflectorRange)
            {
                Matrix lightView = Matrix.CreateLookAt(light.Position, light.Position + light.ReflectorDirection, light.ReflectorUp);

                float distanceSquared = Vector3.DistanceSquared(MyCamera.Position, light.Position);

                bool drawShadows = DrawPlayerLightShadow || (PlayerLight != light);
                drawShadows &= distanceSquared < light.ShadowDistance * light.ShadowDistance * MyRenderConstants.RenderQualityProfile.SpotShadowsMaxDistanceMultiplier;

                //drawShadows &= distanceSquared < 200*200 * MyRenderConstants.RenderQualityProfile.SpotShadowsMaxDistanceMultiplier;

                Matrix lightProjection = Matrix.CreatePerspectiveOffCenter(-a, a, -a, a, nearClip, light.ReflectorRange);

                bool renderShadows = EnableSpotShadows && MyRender.CurrentRenderSetup.EnableSmallLightShadows.Value && drawShadows ;

                MyLightRenderElement lightElement = null;
                lightElement = m_spotLightsPool.Allocate(true);
                Debug.Assert(lightElement != null, "Out of lights, increase pool");
                if (lightElement != null)
                {
                    lightElement.Light = light;
                    lightElement.World = light.SpotWorld;
                    lightElement.View = lightView;
                    lightElement.Projection = lightProjection;
                    lightElement.RenderShadows = renderShadows;
                    lightElement.BoundingBox = light.SpotBoundingBox;
                    lightElement.UseReflectorTexture = (light.LightOwner == MyLight.LightOwnerEnum.SmallShip);

                    if (renderShadows)
                    {
                        Matrix lightViewProjectionShadow = m_spotShadowRenderer.CreateViewProjectionMatrix(lightView, a, nearClip, light.ReflectorRange);
                        lightElement.ShadowLightViewProjection = lightViewProjectionShadow;
                    }
                    m_spotLightRenderElements.Add(lightElement);
                }
            }
        }
Example #20
0
 //  IMPORTANT: This class isn't realy inicialized by constructor, but by Start()
 //  Copies values from 'sourceLight' into this instance
 public void Start(MyLight sourceLight)
 {
     //SysUtils.Utils.MyCommonDebugUtils.AssertDebug((sourceLight.LightType & LightTypeEnum.PointLight) != 0 && ReflectorTexture == null, "ReflectorTexture is null!");
     Start(sourceLight.LightType, sourceLight.Position, sourceLight.Color, sourceLight.Falloff, sourceLight.Range);
 }
Example #21
0
        void UpdateLight()
        {
            float distanceSq = Vector3.DistanceSquared(MyCamera.Position, WorldMatrix.Translation);
            //float maxTurnOnDistance = 15000;
            //float maxKeepedDistance = 100;

            float lightActivationDistanceSq = 4000 * 4000;

            if (distanceSq > lightActivationDistanceSq)
            {
                return;
            }

            MyPerformanceCounter.PerCameraDraw.Increment("Small ships with updated lights");

            if (/*distance < maxTurnOnDistance && */m_light == null)
            {
                m_light = MyLights.AddLight();
                if (m_light != null)
                {
                    m_light.Start(MyLight.LightTypeEnum.PointLight | MyLight.LightTypeEnum.Spotlight, 1.5f);
                    m_light.ShadowDistanceSquared = m_reflectorShadowDistance * m_reflectorShadowDistance;
                    m_light.ReflectorFalloff = MyMinerShipConstants.MINER_SHIP_NEAR_REFLECTOR_FALLOFF;
                    m_light.LightOwner = MyLight.LightOwnerEnum.SmallShip;
                    m_light.UseInForwardRender = true;

                    if (MyFakes.SMALL_SHIPS_GLARE)
                    {
                        m_light.GlareOn = true;
                        m_light.Glare.Type = MyLightGlare.GlareTypeEnum.Normal;
                        m_light.Glare.QuerySize = 2.5f;
                    }

                    switch (m_reflectorType)
                    {
                        case ReflectorTypeEnum.Single:
                            m_light.ReflectorTexture = MyTextureManager.GetTexture<MyTexture2D>("Textures\\Lights\\reflector");
                            break;

                        case ReflectorTypeEnum.Dual:
                            m_light.ReflectorTexture = MyTextureManager.GetTexture<MyTexture2D>("Textures\\Lights\\dual_reflector");
                            break;

                        default:
                            {
                                throw new MyMwcExceptionApplicationShouldNotGetHere();
                            }
                    }
                }
            }      /*
            if (distance >= maxTurnOnDistance && m_light != null)
            {
                MyLights.RemoveLight(m_light);
                m_light = null;
            }        */

            if (m_light == null) return;

            if (Fuel <= 0 || !Config.Engine.On)
            {
                m_light.ReflectorOn = false;
                m_light.LightOn = false;
                return;
            }

            var isCameraInsideMinerShip = IsCameraInsideMinerShip();

            var positionLightTransformed = GetLightPosition(isCameraInsideMinerShip);

            //  Update light position
            m_light.SetPosition(positionLightTransformed);


            if ((MyGuiScreenGamePlay.Static.ControlledEntity != this) && (MyFactions.GetFactionsRelation(this.Faction, MySession.PlayerShip.Faction) == MyFactionRelationEnum.Friend))
            {
                m_light.ShadowDistance = MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE;
            }
            else
            {
                if (MyRender.DrawPlayerLightShadow || MySession.Is25DSector)
                {
                    m_light.ShadowDistance = MyLightsConstants.MAX_SPOTLIGHT_SHADOW_RANGE;
                }
                else
                    m_light.ShadowDistance = 0;
            }


            //  Get interpolator between reflector influence and muzzle flash influence. It is because
            //  this one light display reflector or muzzle, so we need to interpolate.
            int muzzleFlashDeltaTime = MyMinerGame.TotalGamePlayTimeInMilliseconds - Weapons.MuzzleFlashLastTime;
            float interpolator = 1.0f - (float)Math.Pow(MathHelper.Clamp(((float)muzzleFlashDeltaTime /
                                                                          (float)MyMachineGunConstants.MUZZLE_FLASH_MACHINE_GUN_LIFESPAN), 0, 1), 3);

            var range = MathHelper.Lerp(MyMinerShipConstants.MINER_SHIP_NEAR_LIGHT_RANGE, MyMinerShipConstants.MINER_SHIP_MUZZLE_FLASH_LIGHT_RANGE, interpolator);
            range = MathHelper.Clamp(range * MyMinerShipConstants.MINER_SHIP_PLAYER_NEAR_LIGHT_RANGE_MULTIPLIER * LightRangeMultiplier, 0.1f, MyLightsConstants.MAX_POINTLIGHT_RADIUS);
            if (!isCameraInsideMinerShip)
            {
                range *= MyMinerShipConstants.MINER_SHIP_LIGHT_RADIUS_OUTSIDE_MODIFIER;
            }

            m_light.Range = range;
            
            //  Reflector color and range. See that color depends on reflector's level.
            //Vector4 colorReflector = MyMinerShipConstants.MINER_SHIP_REFLECTOR_LIGHT_COLOR * m_reflectorLevel;
            Vector4 colorReflector = GetReflectorProperties().CurrentReflectorLightColor * Config.ReflectorLight.Level;

            //  Color and range will be interpolated by current muzzle flash value and by state of reflector
            m_light.Color = Vector4.Lerp(colorReflector, MyMinerShipConstants.MINER_SHIP_MUZZLE_FLASH_LIGHT_COLOR, interpolator);
            m_light.SpecularColor = new Vector3(colorReflector.X, colorReflector.Y, colorReflector.Z);
            m_light.Falloff = MyMinerShipConstants.MINER_SHIP_LIGHT_FALLOFF;

            //more distant the ship, smaller light is.
            //float smallerSpeed = 0.1f; //10% on 100m
            /*float ratio = 1.0f;

            if (distance > maxKeepedDistance)
                ratio = 0.7f / (((distance - maxKeepedDistance) / 100.0f) + 1);
            m_light.Range *= ratio;
              */
            m_light.Intensity = MyMinerShipConstants.MINER_SHIP_NEAR_LIGHT_INTENSITY * System.Math.Max(Config.ReflectorLight.Level, interpolator) * LightIntensityMultiplier;
            /*if (this != MySession.PlayerShip)
            {
                m_light.Intensity *= 1.0f;
            }
              */

            m_light.ReflectorIntensity = MyMinerShipConstants.MINER_SHIP_NEAR_REFLECTOR_INTENSITY * ReflectorIntensityMultiplier;

            // Reflector properties
            m_light.ReflectorOn = Config.ReflectorLight.Level > 0.0f;
            if (m_light.ReflectorOn)
            {
                m_light.ReflectorUp = this.WorldMatrix.Up;
                m_light.ReflectorDirection = this.WorldMatrix.Forward;
                m_light.ReflectorColor = Config.ReflectorLight.Level * GetReflectorProperties().CurrentReflectorLightColor;
                m_light.UpdateReflectorRangeAndAngle(GetReflectorProperties().CurrentReflectorConeAngleForward, GetReflectorProperties().CurrentReflectorRangeForward);
            }

            m_light.LightOn = !IsDisabledByEMP();
        }