protected override void ValueChanged(MyGuiControlBase sender)
        {
            base.ValueChanged(sender);

            var settings = new MyRenderFogSettings()
            {
                FogMultiplier = MySector.FogProperties.FogMultiplier,
                FogColor = MySector.FogProperties.FogColor,
                FogDensity = MySector.FogProperties.FogDensity
            };
            MyRenderProxy.UpdateFogSettings(ref settings);
        }
Exemplo n.º 2
0
        public override bool Draw()
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGuiScreenGamePlay::Draw");

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3D(-60.7171351205786, 34.002275028352, 78.131769977211),
            //    0.02f,
            //    Vector3.One,
            //    1, true, true);

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3(-13.36391f, -1.974166f, -35.97278f),
            //    0.2f,
            //    Vector3.One,
            //    1, true, true);



            //Vector3 target = new Vector3(-83.87779f, -62.17611f, -127.3294f);
            //Vector3 pos = new Vector3(-87.42791f, -57.17604f, -139.3147f);

            //VRageRender.MyRenderProxy.DebugDrawLine3D(
            //    target, pos, Color.Green, Color.Yellow, false);

            //if (MyCubeBuilder.Static.CurrentGrid != null)
            //{
            //    Matrix m = MyCubeBuilder.Static.CurrentGrid.WorldMatrix;
            //    m.Translation = MySession.Static.ControlledObject.WorldMatrix.Translation;
            //    VRageRender.MyRenderProxy.DebugDrawAxis(m, 1, false);
            //}

            if (MySector.MainCamera != null)
            {
                // set new camera values
                MySession.Static.CameraController.ControlCamera(MySector.MainCamera);
                // update camera properties accordingly to the new settings - zoom, spring, shaking...
                MySector.MainCamera.Update(MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
                // upload to renderer
                MySector.MainCamera.UploadViewMatrixToRender();
            }

            MyRenderProxy.UpdateGameplayFrame(MySession.Static.GameplayFrameCounter);

            VRageRender.MyRenderProxy.UpdateGodRaysSettings(
                MySector.GodRaysProperties.Enabled,
                MySector.GodRaysProperties.Density,
                MySector.GodRaysProperties.Weight,
                MySector.GodRaysProperties.Decay,
                MySector.GodRaysProperties.Exposition,
                false
            );

            VRageRender.MyRenderProxy.UpdateAntiAliasSettings(
                MyPostProcessAntiAlias.Enabled
            );

            VRageRender.MyRenderProxy.UpdateVignettingSettings(
                MyPostProcessVignetting.Enabled,
                MyPostProcessVignetting.VignettingPower
            );

            VRageRender.MyRenderProxy.UpdateColorMappingSettings(
                MyPostProcessColorMapping.Enabled
            );

            VRageRender.MyRenderProxy.UpdateChromaticAberrationSettings(
                MyPostProcessChromaticAberration.Enabled,
                MyPostProcessChromaticAberration.DistortionLens,
                MyPostProcessChromaticAberration.DistortionCubic,
                new Vector3(MyPostProcessChromaticAberration.DistortionWeightRed,
                            MyPostProcessChromaticAberration.DistortionWeightGreen,
                            MyPostProcessChromaticAberration.DistortionWeightBlue)
            );

            VRageRender.MyRenderProxy.UpdateContrastSettings(
                MyPostProcessContrast.Enabled,
                MyPostProcessContrast.Contrast,
                MyPostProcessContrast.Hue,
                MyPostProcessContrast.Saturation
            );

            VRageRender.MyRenderFogSettings fogSettings = new VRageRender.MyRenderFogSettings()
            {
                Enabled = MySector.FogProperties.EnableFog,
                FogNear = MySector.FogProperties.FogNear,
                FogFar = MySector.FogProperties.FogFar,
                FogMultiplier = MySector.FogProperties.FogMultiplier,
                FogBacklightMultiplier = MySector.FogProperties.FogBacklightMultiplier,
                FogColor = MySector.FogProperties.FogColor,
                FogDensity = MySector.FogProperties.FogDensity / 100.0f
            };
            VRageRender.MyRenderProxy.UpdateFogSettings(ref fogSettings);

            VRageRender.MyRenderProxy.UpdateHDRSettings(
                MyPostProcessHDR.DebugHDRChecked,
                MyPostProcessHDR.Exposure,
                MyPostProcessHDR.Threshold,
                MyPostProcessHDR.BloomIntensity,
                MyPostProcessHDR.BloomIntensityBackground,
                MyPostProcessHDR.VerticalBlurAmount,
                MyPostProcessHDR.HorizontalBlurAmount,
                (int)MyPostProcessHDR.NumberOfBlurPasses
            );


            VRageRender.MyRenderProxy.UpdateSSAOSettings(
                MyPostProcessVolumetricSSAO2.Enabled,
                MyPostProcessVolumetricSSAO2.ShowOnlySSAO,
                MyPostProcessVolumetricSSAO2.UseBlur,
                MyPostProcessVolumetricSSAO2.MinRadius,
                MyPostProcessVolumetricSSAO2.MaxRadius,
                MyPostProcessVolumetricSSAO2.RadiusGrowZScale,
                MyPostProcessVolumetricSSAO2.CameraZFarScale * MySector.MainCamera.FarPlaneDistance,
                MyPostProcessVolumetricSSAO2.Bias,
                MyPostProcessVolumetricSSAO2.Falloff,
                MyPostProcessVolumetricSSAO2.NormValue,
                MyPostProcessVolumetricSSAO2.Contrast
            );

            Vector3 sunDirection = -MySector.SunProperties.SunDirectionNormalized;
            if (MySession.Static.Settings.EnableSunRotation && !MyFakes.DEVELOPMENT_PRESET)
            {
                sunDirection = -MySector.SunProperties.BaseSunDirectionNormalized;
                float angle = 2.0f * MathHelper.Pi * (float)(MySession.Static.ElapsedGameTime.TotalMinutes / MySession.Static.Settings.SunRotationIntervalMinutes);
                float originalSunCosAngle = Math.Abs(Vector3.Dot(sunDirection, Vector3.Up));
                Vector3 sunRotationAxis;
                if (originalSunCosAngle > 0.95f)
                {
                    // original sun is too close to the poles
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Left), sunDirection);
                }
                else
                {
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Up), sunDirection);
                }
                sunDirection = Vector3.Transform(sunDirection, Matrix.CreateFromAxisAngle(sunRotationAxis, angle));
                sunDirection.Normalize();

                MySector.SunProperties.SunDirectionNormalized = -sunDirection;
            }

            var gravityProviders = Sandbox.Game.GameSystems.MyGravityProviderSystem.NaturalGravityProviders;
            float planetFactor = 0;
            Vector3D cameraPos = MySector.MainCamera.WorldMatrix.Translation;
            foreach (var gravityProvider in gravityProviders)
            {
                var planet = gravityProvider as MyPlanet;
                if (planet != null)
                {
                    if (planet.HasAtmosphere)
                    {
                        double distanceToPlanet = (planet.WorldMatrix.Translation - cameraPos).Length();
                        float t = ((float)distanceToPlanet - planet.AverageRadius) / (planet.AtmosphereRadius - planet.AverageRadius);
                        if (t < 1.0f)
                        {
                            planetFactor = 1.0f - MathHelper.Clamp(t, 0f, 1f);

                            // Dark side intensity hack
                            //float sunDot = sunDirection.Dot(Vector3D.Normalize(planet.WorldMatrix.Translation - cameraPos));
                            //
                            //if(sunDot < 0f
                            //	&& planetFactor > 0.8f)
                            //{
                            //    float planetInfluence = 1.0f - MathHelper.Clamp((planetFactor - 0.8f) / 0.15f, 0.0f, 1.0f);
                            //    float positionInfluence = MathHelper.Clamp(1.0f + sunDot / 0.1f, 0f, 1f);
                            //    MySector.SunProperties.SunIntensity = MathHelper.Clamp(planetInfluence + positionInfluence, 0.0f, 1.0f) * MyDefinitionManager.Static.EnvironmentDefinition.SunProperties.SunIntensity;
                            //}
                            //else
                            //{
                            //    MySector.SunProperties.SunIntensity = MyDefinitionManager.Static.EnvironmentDefinition.SunProperties.SunIntensity;
                            //}

                            break;
                        }
                    }
                }
            }

            VRageRender.MyRenderProxy.UpdateRenderEnvironment(
                sunDirection,
                MySector.SunProperties.SunDiffuse,
                MySector.SunProperties.AdditionalSunDiffuse,
                MySector.SunProperties.SunSpecular,
                MySector.SunProperties.SunIntensity,
                MySector.SunProperties.AdditionalSunIntensity,
                MySector.SunProperties.AdditionalSunDirection,
                true,
                MySector.SunProperties.AmbientColor,
                MySector.SunProperties.AmbientMultiplier,
                MySector.SunProperties.EnvironmentAmbientIntensity,
                MySector.SunProperties.BackgroundColor,
                MySector.BackgroundTexture,
                MySector.BackgroundTexture,
                MySector.BackgroundTexture,
                MySector.BackgroundOrientation,
                MySector.SunProperties.SunSizeMultiplier,
                MySector.DistanceToSun,
                MySector.SunProperties.SunMaterial,
                MySector.DayTime,
                MySector.ResetEyeAdaptation,
                MyFakes.ENABLE_SUN_BILLBOARD,
                planetFactor
            );

            if (MyDebugDrawSettings.DEBUG_DRAW_ADDITIONAL_ENVIRONMENTAL_LIGHTS)
            {
                Color[] colors = { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.SlateGray };
                for (int lightIndex = 0; lightIndex < MySector.SunProperties.AdditionalSunDirection.Length; ++lightIndex)
                {
                    var lightDirection = MySector.SunProperties.AdditionalSunDirection[lightIndex];
                    MyRenderProxy.DebugDrawSphere(
                        MySector.MainCamera.Position + 2f * MathHelper.CalculateVectorOnSphere(MySector.SunProperties.SunDirectionNormalized, lightDirection[0], lightDirection[1]),
                        0.25f, colors[lightIndex], 1f, false);

                }
            }

            MySector.ResetEyeAdaptation = false;
            VRageRender.MyRenderProxy.UpdateEnvironmentMap();


            VRageRender.MyRenderProxy.SwitchProsprocessSettings(VRageRender.MyPostprocessSettings.LerpExposure(ref MyPostprocessSettingsWrapper.Settings, ref MyPostprocessSettingsWrapper.PlanetSettings, planetFactor));

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Main render");

            VRageRender.MyRenderProxy.Draw3DScene();

            using (Stats.Generic.Measure("GamePrepareDraw"))
            {
                if (MySession.Static != null)
                    MySession.Static.Draw();
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Draw HUD");

            if (MySession.Static.ControlledEntity != null && MySession.Static.CameraController != null)
                MySession.Static.ControlledEntity.DrawHud(MySession.Static.CameraController, MySession.Static.LocalPlayerId);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("FillDebugScreen");
            //FillDebugScreen();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            if (MySandboxGame.IsPaused && !MyHud.MinimalHud)
                DrawPauseIndicator();

            return true;
        }
        public override bool Draw()
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGuiScreenGamePlay::Draw");

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3D(-60.7171351205786, 34.002275028352, 78.131769977211),
            //    0.02f,
            //    Vector3.One,
            //    1, true, true);

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3(-13.36391f, -1.974166f, -35.97278f),
            //    0.2f,
            //    Vector3.One,
            //    1, true, true);

            

            //Vector3 target = new Vector3(-83.87779f, -62.17611f, -127.3294f);
            //Vector3 pos = new Vector3(-87.42791f, -57.17604f, -139.3147f);

            //VRageRender.MyRenderProxy.DebugDrawLine3D(
            //    target, pos, Color.Green, Color.Yellow, false);

            //if (MyCubeBuilder.Static.CurrentGrid != null)
            //{
            //    Matrix m = MyCubeBuilder.Static.CurrentGrid.WorldMatrix;
            //    m.Translation = MySession.ControlledObject.WorldMatrix.Translation;
            //    VRageRender.MyRenderProxy.DebugDrawAxis(m, 1, false);
            //}

            MatrixD viewMatrix = MySession.Static.CameraController.GetViewMatrix();
            if (viewMatrix.IsValid() && viewMatrix != MatrixD.Zero)            
            {
                MySector.MainCamera.SetViewMatrix(viewMatrix);
            }
            else
            {
                Debug.Fail("Camera matrix is invalid or zero!");
            }

            

            VRageRender.MyRenderProxy.UpdateGodRaysSettings(
                MySector.GodRaysProperties.Enabled,
                MySector.GodRaysProperties.Density,
                MySector.GodRaysProperties.Weight,
                MySector.GodRaysProperties.Decay,
                MySector.GodRaysProperties.Exposition,
                false
            );

            VRageRender.MyRenderProxy.UpdateAntiAliasSettings(
                MyPostProcessAntiAlias.Enabled
            );

            VRageRender.MyRenderProxy.UpdateVignettingSettings(
                MyPostProcessVignetting.Enabled,
                MyPostProcessVignetting.VignettingPower
            );

            VRageRender.MyRenderProxy.UpdateColorMappingSettings(
                MyPostProcessColorMapping.Enabled
            );

            VRageRender.MyRenderProxy.UpdateChromaticAberrationSettings(
                MyPostProcessChromaticAberration.Enabled,
                MyPostProcessChromaticAberration.DistortionLens,
                MyPostProcessChromaticAberration.DistortionCubic,
                new Vector3(MyPostProcessChromaticAberration.DistortionWeightRed,
                            MyPostProcessChromaticAberration.DistortionWeightGreen,
                            MyPostProcessChromaticAberration.DistortionWeightBlue)
            );

            VRageRender.MyRenderProxy.UpdateContrastSettings(
                MyPostProcessContrast.Enabled,
                MyPostProcessContrast.Contrast,
                MyPostProcessContrast.Hue,
                MyPostProcessContrast.Saturation
            );

            VRageRender.MyRenderFogSettings fogSettings = new VRageRender.MyRenderFogSettings()
            {
                Enabled = MySector.FogProperties.EnableFog,
                FogNear = MySector.FogProperties.FogNear,
                FogFar = MySector.FogProperties.FogFar,
                FogMultiplier = MySector.FogProperties.FogMultiplier,
                FogBacklightMultiplier = MySector.FogProperties.FogBacklightMultiplier,
                FogColor = MySector.FogProperties.FogColor,
                FogDensity = MySector.FogProperties.FogDensity / 100.0f
            };
            VRageRender.MyRenderProxy.UpdateFogSettings(ref fogSettings);

            VRageRender.MyRenderProxy.UpdateHDRSettings(
                MyPostProcessHDR.DebugHDRChecked,
                MyPostProcessHDR.Exposure,
                MyPostProcessHDR.Threshold,
                MyPostProcessHDR.BloomIntensity,
                MyPostProcessHDR.BloomIntensityBackground,
                MyPostProcessHDR.VerticalBlurAmount,
                MyPostProcessHDR.HorizontalBlurAmount,
                (int)MyPostProcessHDR.NumberOfBlurPasses
            );


            VRageRender.MyRenderProxy.UpdateSSAOSettings(
                MyPostProcessVolumetricSSAO2.Enabled,
                MyPostProcessVolumetricSSAO2.ShowOnlySSAO,
                MyPostProcessVolumetricSSAO2.UseBlur,
                MyPostProcessVolumetricSSAO2.MinRadius,
                MyPostProcessVolumetricSSAO2.MaxRadius,
                MyPostProcessVolumetricSSAO2.RadiusGrowZScale,
                MyPostProcessVolumetricSSAO2.CameraZFarScale * MySector.MainCamera.FarPlaneDistance,
                MyPostProcessVolumetricSSAO2.Bias,
                MyPostProcessVolumetricSSAO2.Falloff,
                MyPostProcessVolumetricSSAO2.NormValue,
                MyPostProcessVolumetricSSAO2.Contrast
            );

            Vector3 sunDirection = -MySector.SunProperties.SunDirectionNormalized;
            if (MySession.Static.Settings.EnableSunRotation && !MyFakes.DEVELOPMENT_PRESET)
            {
                sunDirection = -MySector.SunProperties.BaseSunDirectionNormalized;
                float angle = 2.0f * MathHelper.Pi * (float)(MySession.Static.ElapsedGameTime.TotalMinutes / MySession.Static.Settings.SunRotationIntervalMinutes);
                float originalSunCosAngle = Math.Abs(Vector3.Dot(sunDirection, Vector3.Up));
                Vector3 sunRotationAxis;
                if (originalSunCosAngle > 0.95f)
                {
                    // original sun is too close to the poles
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Left), sunDirection);
                }
                else
                {
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Up), sunDirection);
                }
                sunDirection = Vector3.Transform(sunDirection, Matrix.CreateFromAxisAngle(sunRotationAxis, angle));
                sunDirection.Normalize();

                MySector.SunProperties.SunDirectionNormalized = -sunDirection;
            }

			MyRenderProxy.Settings.FarShadowDistanceOverride = -1.0f;
            Vector3D cameraPos = MySector.MainCamera.WorldMatrix.Translation;

            VRageRender.MyRenderProxy.UpdateRenderEnvironment(
                sunDirection,
                MySector.SunProperties.SunDiffuse,
                MySector.SunProperties.BackSunDiffuse,
                MySector.SunProperties.SunSpecular,
                MySector.SunProperties.SunIntensity,
                MySector.SunProperties.BackSunIntensity,
                true,
                MySector.SunProperties.AmbientColor,
                MySector.SunProperties.AmbientMultiplier,
                MySector.SunProperties.EnvironmentAmbientIntensity,
                MySector.SunProperties.BackgroundColor,
                MySector.BackgroundTexture,
                MySector.BackgroundOrientation,
                MySector.SunProperties.SunSizeMultiplier,
                MySector.DistanceToSun,
                MySector.SunProperties.SunMaterial,
                MySector.DayTime,
                MySector.ResetEyeAdaptation,
                MyFakes.ENABLE_SUN_BILLBOARD
            );
            MySector.ResetEyeAdaptation = false;
            VRageRender.MyRenderProxy.UpdateEnvironmentMap();


            VRageRender.MyRenderProxy.SwitchProsprocessSettings(VRageRender.MyPostprocessSettings.LerpExposure(ref MyPostprocessSettingsWrapper.Settings, ref MyPostprocessSettingsWrapper.Settings, 0));

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Main render");

            VRageRender.MyRenderProxy.Draw3DScene();

            using (Stats.Generic.Measure("GamePrepareDraw"))
            {
                if (MySession.Static != null)
                    MySession.Static.Draw();
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Draw HUD");

            if (MySession.ControlledEntity != null && MySession.Static.CameraController != null)
                MySession.ControlledEntity.DrawHud(MySession.Static.CameraController, MySession.LocalPlayerId);

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("FillDebugScreen");
            //FillDebugScreen();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            if (MySandboxGame.IsPaused && !MyHud.MinimalHud)
                DrawPauseIndicator();

            return true;
        }
Exemplo n.º 4
0
        public override bool Draw()
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyGuiScreenGamePlay::Draw");

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3D(-60.7171351205786, 34.002275028352, 78.131769977211),
            //    0.02f,
            //    Vector3.One,
            //    1, true, true);

            //VRageRender.MyRenderProxy.DebugDrawSphere(
            //    new Vector3(-13.36391f, -1.974166f, -35.97278f),
            //    0.2f,
            //    Vector3.One,
            //    1, true, true);



            //Vector3 target = new Vector3(-83.87779f, -62.17611f, -127.3294f);
            //Vector3 pos = new Vector3(-87.42791f, -57.17604f, -139.3147f);

            //VRageRender.MyRenderProxy.DebugDrawLine3D(
            //    target, pos, Color.Green, Color.Yellow, false);

            //if (MyCubeBuilder.Static.CurrentGrid != null)
            //{
            //    Matrix m = MyCubeBuilder.Static.CurrentGrid.WorldMatrix;
            //    m.Translation = MySession.ControlledObject.WorldMatrix.Translation;
            //    VRageRender.MyRenderProxy.DebugDrawAxis(m, 1, false);
            //}

            MatrixD viewMatrix = MySession.Static.CameraController.GetViewMatrix();

            if (viewMatrix.IsValid() && viewMatrix != MatrixD.Zero)
            {
                MySector.MainCamera.SetViewMatrix(viewMatrix);
            }
            else
            {
                Debug.Fail("Camera matrix is invalid or zero!");
            }



            VRageRender.MyRenderProxy.UpdateGodRaysSettings(
                MySector.GodRaysProperties.Enabled,
                MySector.GodRaysProperties.Density,
                MySector.GodRaysProperties.Weight,
                MySector.GodRaysProperties.Decay,
                MySector.GodRaysProperties.Exposition,
                false
                );

            VRageRender.MyRenderProxy.UpdateAntiAliasSettings(
                MyPostProcessAntiAlias.Enabled
                );

            VRageRender.MyRenderProxy.UpdateVignettingSettings(
                MyPostProcessVignetting.Enabled,
                MyPostProcessVignetting.VignettingPower
                );

            VRageRender.MyRenderProxy.UpdateColorMappingSettings(
                MyPostProcessColorMapping.Enabled
                );

            VRageRender.MyRenderProxy.UpdateChromaticAberrationSettings(
                MyPostProcessChromaticAberration.Enabled,
                MyPostProcessChromaticAberration.DistortionLens,
                MyPostProcessChromaticAberration.DistortionCubic,
                new Vector3(MyPostProcessChromaticAberration.DistortionWeightRed,
                            MyPostProcessChromaticAberration.DistortionWeightGreen,
                            MyPostProcessChromaticAberration.DistortionWeightBlue)
                );

            VRageRender.MyRenderProxy.UpdateContrastSettings(
                MyPostProcessContrast.Enabled,
                MyPostProcessContrast.Contrast,
                MyPostProcessContrast.Hue,
                MyPostProcessContrast.Saturation
                );

            VRageRender.MyRenderFogSettings fogSettings = new VRageRender.MyRenderFogSettings()
            {
                Enabled                = MySector.FogProperties.EnableFog,
                FogNear                = MySector.FogProperties.FogNear,
                FogFar                 = MySector.FogProperties.FogFar,
                FogMultiplier          = MySector.FogProperties.FogMultiplier,
                FogBacklightMultiplier = MySector.FogProperties.FogBacklightMultiplier,
                FogColor               = MySector.FogProperties.FogColor,
                FogDensity             = MySector.FogProperties.FogDensity / 100.0f
            };
            VRageRender.MyRenderProxy.UpdateFogSettings(ref fogSettings);

            VRageRender.MyRenderProxy.UpdateHDRSettings(
                MyPostProcessHDR.DebugHDRChecked,
                MyPostProcessHDR.Exposure,
                MyPostProcessHDR.Threshold,
                MyPostProcessHDR.BloomIntensity,
                MyPostProcessHDR.BloomIntensityBackground,
                MyPostProcessHDR.VerticalBlurAmount,
                MyPostProcessHDR.HorizontalBlurAmount,
                (int)MyPostProcessHDR.NumberOfBlurPasses
                );


            VRageRender.MyRenderProxy.UpdateSSAOSettings(
                MyPostProcessVolumetricSSAO2.Enabled,
                MyPostProcessVolumetricSSAO2.ShowOnlySSAO,
                MyPostProcessVolumetricSSAO2.UseBlur,
                MyPostProcessVolumetricSSAO2.MinRadius,
                MyPostProcessVolumetricSSAO2.MaxRadius,
                MyPostProcessVolumetricSSAO2.RadiusGrowZScale,
                MyPostProcessVolumetricSSAO2.CameraZFarScale * MySector.MainCamera.FarPlaneDistance,
                MyPostProcessVolumetricSSAO2.Bias,
                MyPostProcessVolumetricSSAO2.Falloff,
                MyPostProcessVolumetricSSAO2.NormValue,
                MyPostProcessVolumetricSSAO2.Contrast
                );

            Vector3 sunDirection = -MySector.SunProperties.SunDirectionNormalized;

            if (MySession.Static.Settings.EnableSunRotation && !MyFakes.DEVELOPMENT_PRESET)
            {
                sunDirection = -MySector.SunProperties.BaseSunDirectionNormalized;
                float   angle = 2.0f * MathHelper.Pi * (float)(MySession.Static.ElapsedGameTime.TotalMinutes / MySession.Static.Settings.SunRotationIntervalMinutes);
                float   originalSunCosAngle = Math.Abs(Vector3.Dot(sunDirection, Vector3.Up));
                Vector3 sunRotationAxis;
                if (originalSunCosAngle > 0.95f)
                {
                    // original sun is too close to the poles
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Left), sunDirection);
                }
                else
                {
                    sunRotationAxis = Vector3.Cross(Vector3.Cross(sunDirection, Vector3.Up), sunDirection);
                }
                sunDirection = Vector3.Transform(sunDirection, Matrix.CreateFromAxisAngle(sunRotationAxis, angle));
                sunDirection.Normalize();

                MySector.SunProperties.SunDirectionNormalized = -sunDirection;
            }

            MyRenderProxy.Settings.FarShadowDistanceOverride = -1.0f;
            Vector3D cameraPos = MySector.MainCamera.WorldMatrix.Translation;

            VRageRender.MyRenderProxy.UpdateRenderEnvironment(
                sunDirection,
                MySector.SunProperties.SunDiffuse,
                MySector.SunProperties.BackSunDiffuse,
                MySector.SunProperties.SunSpecular,
                MySector.SunProperties.SunIntensity,
                MySector.SunProperties.BackSunIntensity,
                true,
                MySector.SunProperties.AmbientColor,
                MySector.SunProperties.AmbientMultiplier,
                MySector.SunProperties.EnvironmentAmbientIntensity,
                MySector.SunProperties.BackgroundColor,
                MySector.BackgroundTexture,
                MySector.BackgroundOrientation,
                MySector.SunProperties.SunSizeMultiplier,
                MySector.DistanceToSun,
                MySector.SunProperties.SunMaterial,
                MySector.DayTime,
                MySector.ResetEyeAdaptation,
                MyFakes.ENABLE_SUN_BILLBOARD
                );
            MySector.ResetEyeAdaptation = false;
            VRageRender.MyRenderProxy.UpdateEnvironmentMap();


            VRageRender.MyRenderProxy.SwitchProsprocessSettings(VRageRender.MyPostprocessSettings.LerpExposure(ref MyPostprocessSettingsWrapper.Settings, ref MyPostprocessSettingsWrapper.Settings, 0));

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Main render");

            VRageRender.MyRenderProxy.Draw3DScene();

            using (Stats.Generic.Measure("GamePrepareDraw"))
            {
                if (MySession.Static != null)
                {
                    MySession.Static.Draw();
                }
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("Draw HUD");

            if (MySession.ControlledEntity != null && MySession.Static.CameraController != null)
            {
                MySession.ControlledEntity.DrawHud(MySession.Static.CameraController, MySession.LocalPlayerId);
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().StartNextBlock("FillDebugScreen");
            //FillDebugScreen();
            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();

            if (MySandboxGame.IsPaused && !MyHud.MinimalHud)
            {
                DrawPauseIndicator();
            }

            return(true);
        }