Esempio n. 1
0
        //  This method adds lights information into specified effect.
        //  Method gets lights that could have influence on bounding sphere (it is assumed this will be bounding sphere of a phys object or voxel render cell).
        //  Lights that are far from bounding sphere are ignored. But near lights are taken to second step, where we sort them by distance and priority
        //  and set them to the effect.
        //  We assume RemoveKilled() was called before this method, so here we don't check if light isn't killed.
        public static void UpdateEffect(MyEffectDynamicLightingBase effect, ref BoundingSphere boundingSphere, bool subtractCameraPosition)
        {
            MyUtils.AssertIsValid(boundingSphere.Center);
            MyUtils.AssertIsValid(boundingSphere.Radius);

            // Reason to remove this condition: when updating effect with same bounding sphere, it could return different result when some light died (effect ended) before second request
            //if (m_lastBoundingSphere != boundingSphere)
            {
                UpdateSortedLights(ref boundingSphere, true);
                m_lastBoundingSphere = boundingSphere;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //  Now in 'm_sortedLights' we have only lights that intersects bounding sphere in SAP list
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                m_lightsCount = m_sortedLights.Count;
                int maxLightsForEffect = MyLightsConstants.MAX_LIGHTS_FOR_EFFECT;

                //  If number of lights with influence is more than max number of lights allowed in the effect, we sort them by distance (or we can do it by some priority)
                if (m_sortedLights.Count > maxLightsForEffect)
                {
                    m_sortLightsComparer.BoundingSphere = boundingSphere;
                    m_sortedLights.Sort(m_sortLightsComparer);
                    m_lightsCount = maxLightsForEffect;
                }
            }

            //  Set lights to effect, but not more than effect can handle
            for (int i = 0; i < m_lightsCount; i++)
            {
                SetLightToEffect(effect, i, m_sortedLights[i], subtractCameraPosition);
            }

            effect.SetDynamicLightsCount(m_lightsCount);


            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));
            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());
            effect.SetSunIntensity(MySector.SunProperties.SunIntensity);

            Vector3 ambientColor = MyRender.AmbientColor * MyRender.AmbientMultiplier;

            effect.SetAmbientColor(ambientColor * (MyRenderConstants.RenderQualityProfile.ForwardRender ? 6.5f : 1.0f));
        }
Esempio n. 2
0
        public static void Draw()
        {
            if (!CanDrawCockpit())
            {
                return;
            }

            MyModel model = MyModels.GetModelForDraw(MySession.PlayerShip.CockpitGlassModelEnum);

            RasterizerState.CullNone.Apply();

            if (MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                DepthStencilState.DepthRead.Apply();
            }
            else
            {
                MyStateObjects.DepthStencil_StencilReadOnly.Apply();
            }

            BlendState.NonPremultiplied.Apply();

            MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass);

            float glassDirtAlpha = MathHelper.Lerp(MyCockpitGlassConstants.GLASS_DIRT_MIN, MyCockpitGlassConstants.GLASS_DIRT_MAX,
                                                   MySession.PlayerShip.GlassDirtLevel);

            effect.SetGlassDirtLevelAlpha(new Vector4(glassDirtAlpha, 0, 0, 0));

            effect.SetWorldMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix);
            effect.SetViewMatrix(MyCamera.ViewMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Matrix projection = MyCamera.ProjectionMatrixForNearObjects;

                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewMatrixAtZero * projection);
            }
            else
            {
                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewProjectionMatrixAtZero);
            }

            MyMeshMaterial cockpitMaterial = model.GetMeshList()[0].Materials[0];

            cockpitMaterial.PreloadTexture();
            effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effect.SetDepthTexture(depthRT);

                effect.SetHalfPixel(MyUtils.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height));
            }

            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));

            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());

            effect.SetAmbientColor(Vector3.Zero);
            effect.SetReflectorPosition(MyCamera.Position - 4 * MySession.PlayerShip.WorldMatrix.Forward);

            if (MySession.PlayerShip.Light != null)
            {
                effect.SetNearLightColor(MySession.PlayerShip.Light.Color);
                effect.SetNearLightRange(MySession.PlayerShip.Light.Range);
            }

            MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
            effect.SetShadowBias(0.001f);

            m_boundingSphereForLights.Center = MySession.PlayerShip.GetPosition();
            MyLights.UpdateEffect(effect, ref m_boundingSphereForLights, true);

            effect.Begin();
            model.Render();
            effect.End();

            MyCockpitGlassDecals.Draw(effect);
        }
Esempio n. 3
0
        static MyGlobalEvents()
        {
            m_globalEvents[(int)MyGlobalEventEnum.SunWind] =
                new MyGlobalEvent(
                    Type : MyGlobalEventEnum.SunWind,
                    Name : MyTextsWrapperEnum.GlobalEventSunWindName,
                    Description : MyTextsWrapperEnum.GlobalEventSunWindDescription,
                    RatePerHour : 12.0f,
                    Icon : null,
                    Enabled : true,
                    Action : delegate(object o, EventArgs e)
            {
                //dont allow sunwind in god editor on or when the game is paused
                if (!MySunWind.IsActive && !(MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) && !MyMinerGame.IsPaused())
                {
                    //MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.GlobalEventSunWindDescription, 5000));
                    MySunWind.Start();
                    //MyAudio.AddCue2D(MySoundCuesEnum.HudSolarFlareWarning);
                }
            },
                    WriteToEventLog: false
                    );

            m_globalEvents[(int)MyGlobalEventEnum.FractionStatusChange] =
                new MyGlobalEvent(
                    Type : MyGlobalEventEnum.FractionStatusChange,
                    Name : MyTextsWrapperEnum.GlobalEventFactionChangeName,
                    Description : MyTextsWrapperEnum.GlobalEventFactionChangeDescription,
                    RatePerHour : 10.0f,
                    Icon : null,
                    Enabled : false,
                    Action : delegate(object o, EventArgs e)
            {
                float statusChange = MyMwcUtils.GetRandomFloat(MyFactions.RELATION_WORST, MyFactions.RELATION_BEST) / 10.0f;

                int[] enumValues = MyMwcFactionsByIndex.GetFactionsIndexes();
                System.Diagnostics.Debug.Assert(enumValues.Length > 3);

                MyMwcObjectBuilder_FactionEnum faction1;
                do
                {
                    faction1 = MyMwcFactionsByIndex.GetFaction(MyMwcUtils.GetRandomInt(enumValues.Length));
                }while (faction1 == MyMwcObjectBuilder_FactionEnum.None);

                MyMwcObjectBuilder_FactionEnum faction2;
                do
                {
                    faction2 = MyMwcFactionsByIndex.GetFaction(MyMwcUtils.GetRandomInt(enumValues.Length));
                }while ((faction1 == faction2) || (faction2 == MyMwcObjectBuilder_FactionEnum.None));

                MyFactions.ChangeFactionStatus(faction1, faction2, statusChange);
            },
                    WriteToEventLog: false
                    );

            m_globalEvents[(int)MyGlobalEventEnum.MeteorWind] =
                new MyGlobalEvent(
                    Type : MyGlobalEventEnum.SunWind,
                    Name : MyTextsWrapperEnum.GlobalEventMeteorWindName,
                    Description : MyTextsWrapperEnum.GlobalEventSunWindDescription,
                    RatePerHour : MyFakes.ENABLE_RANDOM_METEOR_SHOWER ? 1.0f : 0.0f,
                    Icon : null,
                    Enabled : false,
                    Action : delegate(object o, EventArgs e)
            {
                //dont allow sunwind in god editor on or when the game is paused
                if (!(MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) && !MyMinerGame.IsPaused())
                {
                    //MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.GlobalEventSunWindDescription, 5000));
                    MyMeteorWind.Start();
                    //MyAudio.AddCue2D(MySoundCuesEnum.SfxSolarFlareWarning);
                }
            },
                    WriteToEventLog: false
                    );


            // todo implement localization strings
            m_globalEvents[(int)MyGlobalEventEnum.IceStorm] =
                new MyGlobalEvent(
                    Type : MyGlobalEventEnum.IceStorm,
                    Name : MyTextsWrapperEnum.GlobalEventIceStormName,              //Name: MyTextsWrapperEnum.GlobalEvent_IceStorm_Name,
                    Description : MyTextsWrapperEnum.GlobalEventSunWindDescription, //IceStorm_Description,
                    RatePerHour : MyFakes.ENABLE_RANDOM_ICE_STORM ? 1.0f : 0.0f,
                    Icon : null,
                    Enabled : false,
                    Action : delegate(object o, EventArgs e)
            {
                //dont allow sunwind in god editor on or when the game is paused
                if (!(MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) && !MyMinerGame.IsPaused())
                {
                    MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.GlobalEventSunWindDescription, 5000, null));        // MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.GlobalEvent_IceStorm_Description, 5000));
                    MyIceStorm.Start();
                    MyAudio.AddCue2D(MySoundCuesEnum.HudSolarFlareWarning);
                }
            },
                    WriteToEventLog: false
                    );

            m_globalEvents[(int)MyGlobalEventEnum.IceComet] =
                new MyGlobalEvent(
                    Type : MyGlobalEventEnum.IceComet,
                    Name : MyTextsWrapperEnum.GlobalEventIceCometName,
                    Description : MyTextsWrapperEnum.GlobalEventIceCometDescription,
                    RatePerHour : 0.0f,
                    Icon : null,
                    Enabled : false,
                    Action : delegate(object o, EventArgs e)
            {
                if (!(MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive()) && !MyMinerGame.IsPaused())
                {
                    MyHudNotification.AddNotification(new MyHudNotification.MyNotification(MyTextsWrapperEnum.GlobalEventSunWindDescription, 5000));
                    MyIceComet.Start();
                    MyAudio.AddCue2D(MySoundCuesEnum.HudSolarFlareWarning);
                }
            },
                    WriteToEventLog: false
                    );

            foreach (MyGlobalEvent e in m_globalEvents)
            {
                System.Diagnostics.Debug.Assert(e != null);
            }

            MyFactions.OnFactionStatusChanged += new MyFactionStatusChangeHandler(MyFactions_OnFactionStatusChanged);
        }