コード例 #1
0
        public void Draw(MyEffectDistantImpostors effect)
        {
            LoadInDraw();

            Device device = MyRender.GraphicsDevice;

            RasterizerState.CullNone.Apply();
            MyStateObjects.NonPremultiplied_NoAlphaWrite_BlendState.Apply();
            MyStateObjects.DistantImpostorsDepthStencilState.Apply();


            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MyRenderCamera.FieldOfView, MyRenderCamera.AspectRatio, 1000, 10000000);

            effect.SetViewProjectionMatrix((Matrix)(MyRenderCamera.ViewMatrix * projection));
            effect.SetSunDirection(MyRender.Sun.Direction);
            MyRenderCamera.SetupBaseEffect(effect, MyLodTypeEnum.LOD0);

            foreach (MyVoxelMapImpostorGroup group in m_voxelMapImpostorGroups)
            {
                group.Draw(effect, MyImpostorType.Billboards);
            }

            BlendState.NonPremultiplied.Apply();

            foreach (MyVoxelMapImpostorGroup group in m_voxelMapImpostorGroups)
            {
                group.Draw(effect, MyImpostorType.Nebula);
            }
        }
コード例 #2
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.PostLighting:
            {
                //todo fog
                //if (MySector.FogProperties.FogMultiplier <= 0.0f)
                //  return source;

                MyStateObjects.VolumetricFogBlend.Apply();

                MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog;

                int width  = MyRenderCamera.Viewport.Width;
                int height = MyRenderCamera.Viewport.Height;

                var scale = MyRender.GetScaleForViewport(source);

                volumetricFog.SetSourceRT(source);
                volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                volumetricFog.SetHalfPixel(width, height);
                volumetricFog.SetViewProjectionMatrix((Matrix)MyRenderCamera.ViewProjectionMatrix);
                volumetricFog.SetCameraPosition((Vector3)MyRenderCamera.Position);
                volumetricFog.SetCameraMatrix((Matrix)MatrixD.Invert(MyRenderCamera.ViewMatrix));
                volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());
                volumetricFog.SetScale(scale);
                MyRenderCamera.SetupBaseEffect(volumetricFog, MyLodTypeEnum.LOD0);

                //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position));
                //todo
                //if (MyFakes.MWBUILDER)
                //    volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground);
                //else
                volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default);

                MyRender.GetFullscreenQuad().Draw(volumetricFog);
            }
            break;
            }
            return(source);
        }
コード例 #3
0
ファイル: MyRender-3D.cs プロジェクト: warex0/SpaceEngineers
        internal static void UpdateScreenSize()
        {
            MyRender.Log.WriteLine("MyRender.UpdateScreenSize() - START");

            //VRageRender.MyRender.GetRenderProfiler().StartProfilingBlock("MySandboxGame::UpdateScreenSize");

            ScreenSize     = new Vector2I((int)GraphicsDevice.Viewport.Width, (int)GraphicsDevice.Viewport.Height);
            ScreenSizeHalf = new Vector2I(ScreenSize.X / 2, ScreenSize.Y / 2);

            if (m_screenshot != null)
            {
                ScreenSize.X   = (int)(ScreenSize.X * m_screenshot.SizeMultiplier.X);
                ScreenSize.Y   = (int)(ScreenSize.Y * m_screenshot.SizeMultiplier.Y);
                ScreenSizeHalf = new Vector2I(ScreenSize.X / 2, ScreenSize.Y / 2);
            }

            MyRender.Log.WriteLine("ScreenSize: " + ScreenSize.ToString());

            int safeGuiSizeY = ScreenSize.Y;
            int safeGuiSizeX = (int)(safeGuiSizeY * 1.3333f);     //  This will mantain same aspect ratio for GUI elements

            int safeFullscreenSizeX = ScreenSize.X;
            int safeFullscreenSizeY = ScreenSize.Y;

            m_fullscreenRectangle = new VRageMath.Rectangle(0, 0, ScreenSize.X, ScreenSize.Y);

            //  Triple head is drawn on three monitors, so we will draw GUI only on the middle one
            m_safeGuiRectangle = new VRageMath.Rectangle(ScreenSize.X / 2 - safeGuiSizeX / 2, 0, safeGuiSizeX, safeGuiSizeY);

            //if (MyVideoModeManager.IsTripleHead() == true)
            //m_safeGuiRectangle.X += MySandboxGame.ScreenSize.X / 3;

            m_safeFullscreenRectangle = new VRageMath.Rectangle(ScreenSize.X / 2 - safeFullscreenSizeX / 2, 0, safeFullscreenSizeX, safeFullscreenSizeY);

            //  This will help as maintain scale/ratio of images, texts during in different resolution
            m_safeScreenScale = (float)safeGuiSizeY / MyRenderGuiConstants.REFERENCE_SCREEN_HEIGHT;

            MyRenderCamera.UpdateScreenSize();

            MyRender.Log.WriteLine("MyRender.UpdateScreenSize() - END");
        }
コード例 #4
0
        internal static void DrawMessageQueue()
        {
            if (m_spriteBatch == null)
            {
                return;
            }

            DrawSpriteStencilEnum currentStencil = DrawSpriteStencilEnum.None;


            BeginSpriteBatch();

            /*
             * if (m_drawMessages.Count == 0)
             * {
             *  GraphicsDevice.Clear(ClearFlags.All, new SharpDX.ColorBGRA(1.0f, 1, 0, 1), 1, 0);
             *  DrawText(new Vector2(0, 300), new StringBuilder("No draw input"), Color.White, 1);
             * } */


            while (m_drawMessages.Count > 0)
            {
                IMyRenderMessage drawMessage = m_drawMessages.Dequeue();

                MyRenderMessageEnum messageType = drawMessage.MessageType;
                switch (messageType)
                {
                case MyRenderMessageEnum.SpriteScissorPush:
                {
                    var msg = drawMessage as MyRenderMessageSpriteScissorPush;
                    m_spriteBatch.ScissorStack.Push(msg.ScreenRectangle);
                    break;
                }

                case MyRenderMessageEnum.SpriteScissorPop:
                {
                    m_spriteBatch.ScissorStack.Pop();
                    break;
                }

                case MyRenderMessageEnum.DrawSprite:
                {
                    MyRenderMessageDrawSprite sprite = (MyRenderMessageDrawSprite)drawMessage;

                    ProcessSpriteMessage(sprite);
                    break;
                }

                case MyRenderMessageEnum.DrawSpriteNormalized:
                {
                    MyRenderMessageDrawSpriteNormalized sprite = (MyRenderMessageDrawSpriteNormalized)drawMessage;

                    ProcessNormalizedSpriteMessage(sprite);

                    break;
                }

                case MyRenderMessageEnum.DrawSpriteAtlas:
                {
                    MyRenderMessageDrawSpriteAtlas sprite = (MyRenderMessageDrawSpriteAtlas)drawMessage;

                    ProcessAtlasSprite(sprite);

                    break;
                }

                case MyRenderMessageEnum.DrawString:
                {
                    var message = drawMessage as MyRenderMessageDrawString;

                    var font = MyRender.GetFont(message.FontIndex);
                    font.DrawString(
                        message.ScreenCoord * m_sizeMultiplierForStrings,
                        message.ColorMask,
                        message.Text,
                        message.ScreenScale * m_sizeMultiplierForStrings.X,
                        message.ScreenMaxWidth * m_sizeMultiplierForStrings.X);

                    break;
                }

                case MyRenderMessageEnum.DrawScene:
                {
                    EndSpriteBatch();

                    MyRenderCamera.UpdateCamera();
                    MyRender.SetDeviceViewport(MyRenderCamera.Viewport);

                    Draw3D();

                    DrawDebugMessages();

                    BeginSpriteBatch();

                    break;
                }

                case MyRenderMessageEnum.DrawVideo:
                {
                    var rMessage = (MyRenderMessageDrawVideo)drawMessage;
                    MyRender.DrawVideo(rMessage.ID, rMessage.Rectangle, rMessage.Color, rMessage.FitMode);

                    break;
                }

                case MyRenderMessageEnum.UpdateEnvironmentMap:
                {
                    MyRender.GetRenderProfiler().StartProfilingBlock("MyEnvironmentMap.Update");
                    MyEnvironmentMap.Update();
                    MyRender.GetRenderProfiler().EndProfilingBlock();

                    break;
                }

                case MyRenderMessageEnum.DrawSecondaryCamera:
                {
                    var rMessage = (MyRenderMessageDrawSecondaryCamera)drawMessage;

                    MySecondaryCameraRenderer.Instance.ViewMatrix = (MatrixD)rMessage.ViewMatrix;
                    MySecondaryCameraRenderer.Instance.Render();

                    break;
                }

                case MyRenderMessageEnum.DrawSecondaryCameraSprite:
                {
                    MyRenderMessageDrawSecondaryCameraSprite sprite = (MyRenderMessageDrawSecondaryCameraSprite)drawMessage;

                    Vector2 rightVector = sprite.Rotation != 0f ? new Vector2((float)Math.Cos(sprite.Rotation), (float)Math.Sin(sprite.Rotation)) : sprite.RightVector;
                    //rightVector = new Vector2(1, 1);

                    DrawSpriteMain(
                        MySecondaryCameraRenderer.Instance.GetRenderedTexture(),
                        null,
                        ref sprite.DestinationRectangle,
                        sprite.ScaleDestination,
                        sprite.SourceRectangle,
                        sprite.Color,
                        rightVector,
                        ref sprite.Origin,
                        sprite.Effects,
                        sprite.Depth
                        );

                    break;
                }

                case MyRenderMessageEnum.UpdateBillboardsColorize:
                {
                    var rMessage = (MyRenderMessageUpdateBillboardsColorize)drawMessage;

                    MyTransparentGeometry.EnableColorize        = rMessage.Enable;
                    MyTransparentGeometry.ColorizeColor         = rMessage.Color;
                    MyTransparentGeometry.ColorizePlaneDistance = rMessage.Distance;
                    MyTransparentGeometry.ColorizePlaneNormal   = rMessage.Normal;

                    break;
                }

                default:
                {
                    System.Diagnostics.Debug.Assert(false, "Unknown draw message");
                    break;
                }
                }
            }

            GetRenderProfiler().StartProfilingBlock("SpriteBatchRestart");
            EndSpriteBatch();
            BeginSpriteBatch();
            GetRenderProfiler().EndProfilingBlock();

            GetRenderProfiler().StartProfilingBlock("DrawDebugMessages");
            DrawDebugMessages();
            GetRenderProfiler().EndProfilingBlock();

            if (MyRenderProxy.DRAW_RENDER_STATS)
            {
                MyRenderStatsDraw.Draw(MyRenderStats.m_stats, 0.6f, Color.Yellow);
            }

            if (MyRender.Settings.TearingTest)
            {
                DrawTearingTest();
            }

            if (MyRender.Settings.MultimonTest)
            {
                // Middle screen
                var from = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, 0);
                var to   = new Vector2(GraphicsDevice.Viewport.Width / 2.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Orange, Color.Orange);

                from = new Vector2(GraphicsDevice.Viewport.Width / 3.0f, 0);
                to   = new Vector2(GraphicsDevice.Viewport.Width / 3.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Yellow, Color.Yellow);
                from = new Vector2(GraphicsDevice.Viewport.Width / 3.0f * 2.0f, 0);
                to   = new Vector2(GraphicsDevice.Viewport.Width / 3.0f * 2.0f, GraphicsDevice.Viewport.Height);
                VRageRender.MyRenderProxy.DebugDrawLine2D(from, to, Color.Yellow, Color.Yellow);
            }

            GetRenderProfiler().StartProfilingBlock("SpriteBatchEnd");
            EndSpriteBatch();
            GetRenderProfiler().EndProfilingBlock();


            System.Diagnostics.Debug.Assert(m_spriteBatchUsageCount == 0);
        }
コード例 #5
0
        internal static void RenderLights()
        {
            PrepareLights();

            RenderSpotShadows();

            GetRenderProfiler().StartProfilingBlock("Render lights");
            MyRender.SetRenderTarget(GetRenderTarget(MyRenderTargets.Auxiliary1), null, SetDepthTargetEnum.RestoreDefault);
            MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0.0f), 1, 0);

            SetCorrectViewportSize();

            if (MyRender.CurrentRenderSetup.EnableSmallLights.Value)
            {
                MyEffectPointLight        effectPointLight = (MyEffectPointLight)MyRender.GetEffect(MyEffects.PointLight);
                SharpDX.Direct3D9.Texture diffuseRT        = MyRender.GetRenderTarget(MyRenderTargets.Diffuse);
                effectPointLight.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                effectPointLight.SetDiffuseRT(diffuseRT);
                effectPointLight.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                effectPointLight.SetHalfPixel(diffuseRT.GetLevelDescription(0).Width, diffuseRT.GetLevelDescription(0).Height);
                effectPointLight.SetScale(GetScaleForViewport(diffuseRT));

                var invViewProjMatrix = Matrix.Invert(MyRenderCamera.ViewProjectionMatrixAtZero);
                var invViewMatrix     = Matrix.Invert(MyRenderCamera.ViewMatrixAtZero);

                effectPointLight.SetCameraPosition(Vector3.Zero);
                effectPointLight.SetViewMatrix(MyRenderCamera.ViewMatrixAtZero);
                effectPointLight.SetInvViewMatrix(invViewMatrix);

                DepthStencilState.None.Apply();
                MyStateObjects.Light_Combination_BlendState.Apply();

                //Render each light with a model specific to the light
                GetRenderProfiler().StartProfilingBlock("PointLight");

                var cullRationSq = MyRenderConstants.DISTANCE_LIGHT_CULL_RATIO * MyRenderConstants.DISTANCE_LIGHT_CULL_RATIO;

                if (MyRender.Settings.EnablePointLights)
                {
                    foreach (MyRenderLight light in m_pointLights)
                    {
                        var distanceSq = (MyRenderCamera.Position - light.PositionWithOffset).LengthSquared();

                        var hasVolumetricGlare = light.GlareOn && light.Glare.Type == MyGlareTypeEnum.Distant;
                        var isTooFarAway       = (light.Range * light.Range) < (distanceSq / cullRationSq);

                        if (!isTooFarAway)
                        {
                            // Always cull clockwise (render inner parts of object), depth test is done is PS using light radius
                            RasterizerState.CullClockwise.Apply();

                            effectPointLight.SetLightPosition((Vector3)(light.PositionWithOffset - MyRenderCamera.Position));
                            effectPointLight.SetLightIntensity(light.Intensity);
                            effectPointLight.SetSpecularLightColor(light.SpecularColor);
                            effectPointLight.SetFalloff(light.Falloff);

                            effectPointLight.SetLightRadius(light.Range);
                            effectPointLight.SetReflectorTexture(light.ReflectorTexture);
                            effectPointLight.SetLightColor(light.Color.ToVector3());

                            effectPointLight.SetTechnique(effectPointLight.PointTechnique);

                            MyDebugDraw.DrawSphereForLight(effectPointLight, light.PositionWithOffset, light.Range, ref Vector3.One, 1);
                            MyPerformanceCounter.PerCameraDrawWrite.LightsCount++;
                        }

                        // if(!isTooFarAway || hasVolumetricGlare)
                        //   light.Draw();
                    }
                }


                GetRenderProfiler().EndProfilingBlock();


                GetRenderProfiler().StartProfilingBlock("Hemisphere");

                if (MyRender.Settings.EnablePointLights)
                {
                    foreach (MyRenderLight light in m_hemiLights)
                    {
                        // compute bounding box
                        //Vector3 center = light.Position;// - light.Range * new Vector3(0,1,0);
                        //Vector3 extend = new Vector3(light.Range, light.Range, light.Range);
                        //m_lightBoundingBox.Min = center - extend;
                        //m_lightBoundingBox.Max = center + extend;
                        // Always cull clockwise (render inner parts of object), depth test is done is PS using light radius
                        if (Vector3D.Dot((Vector3D)light.ReflectorDirection, MyRenderCamera.Position - light.Position) > 0 && light.PointBoundingSphere.Contains(MyRenderCamera.Position) == VRageMath.ContainmentType.Contains)
                        {
                            RasterizerState.CullNone.Apply(); //zevnitr
                        }
                        else
                        {
                            RasterizerState.CullCounterClockwise.Apply(); //zvenku
                        }

                        effectPointLight.SetLightPosition((Vector3)(light.Position - MyRenderCamera.Position));
                        effectPointLight.SetLightIntensity(light.Intensity);
                        effectPointLight.SetSpecularLightColor(light.SpecularColor);
                        effectPointLight.SetFalloff(light.Falloff);

                        effectPointLight.SetLightRadius(light.Range);
                        effectPointLight.SetReflectorTexture(light.ReflectorTexture);
                        effectPointLight.SetLightColor(light.Color.ToVector3());
                        effectPointLight.SetTechnique(effectPointLight.HemisphereTechnique);

                        MatrixD world = MatrixD.CreateScale(light.Range) * MatrixD.CreateWorld(light.Position - MyRenderCamera.Position, light.ReflectorDirection, light.ReflectorUp);
                        MyDebugDraw.DrawHemisphereForLight(effectPointLight, ref world, ref Vector3.One, 1);
                        //light.Draw();

                        MyPerformanceCounter.PerCameraDrawWrite.LightsCount++;
                    }
                }
                GetRenderProfiler().EndProfilingBlock();


                GetRenderProfiler().StartProfilingBlock("Spotlight");
                RenderSpotLights(m_spotLightRenderElements, effectPointLight);

                GetRenderProfiler().EndProfilingBlock();

                foreach (var light in m_renderLightsForDraw)
                {
                    light.Draw();
                }
            }

            DepthStencilState.None.Apply();
            RasterizerState.CullCounterClockwise.Apply();

            MyStateObjects.Sun_Combination_BlendState.Apply();

            GetRenderProfiler().StartProfilingBlock("Sun light");

            if (Settings.EnableSun && CurrentRenderSetup.EnableSun.Value && MyRender.Sun.Direction != Vector3.Zero)
            {
                //Sun light
                MyEffectDirectionalLight effectDirectionalLight = MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight;
                Texture diffuseRTSun = MyRender.GetRenderTarget(MyRenderTargets.Diffuse);
                effectDirectionalLight.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                effectDirectionalLight.SetDiffuseRT(diffuseRTSun);
                effectDirectionalLight.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                effectDirectionalLight.SetHalfPixelAndScale(diffuseRTSun.GetLevelDescription(0).Width, diffuseRTSun.GetLevelDescription(0).Height, GetScaleForViewport(diffuseRTSun));

                effectDirectionalLight.SetCameraMatrix(Matrix.Invert(MyRenderCamera.ViewMatrixAtZero));

                effectDirectionalLight.SetAmbientMinimumAndIntensity(new Vector4(AmbientColor * AmbientMultiplier, EnvAmbientIntensity));

                effectDirectionalLight.SetTextureEnvironmentMain(MyEnvironmentMap.EnvironmentMainMap);
                effectDirectionalLight.SetTextureEnvironmentAux(MyEnvironmentMap.EnvironmentAuxMap);
                effectDirectionalLight.SetTextureAmbientMain(MyEnvironmentMap.AmbientMainMap);
                effectDirectionalLight.SetTextureAmbientAux(MyEnvironmentMap.AmbientAuxMap);
                effectDirectionalLight.SetTextureEnvironmentBlendFactor(MyEnvironmentMap.BlendFactor);

                effectDirectionalLight.SetCameraPosition(Vector3.Zero);

                //Set distance where no slope bias will be applied (because of cockpit artifacts)
                effectDirectionalLight.SetNearSlopeBiasDistance(3);

                effectDirectionalLight.ShowSplitColors(Settings.ShowCascadeSplits);


                effectDirectionalLight.SetShadowBias(MyRenderCamera.FieldOfView * 0.0001f * MyRenderConstants.RenderQualityProfile.ShadowBiasMultiplier);
                effectDirectionalLight.SetSlopeBias(0.00002f * MyRenderConstants.RenderQualityProfile.ShadowSlopeBiasMultiplier);
                effectDirectionalLight.SetSlopeCascadeMultiplier(20.0f); //100 makes artifacts in prefabs

                MyRender.GetShadowRenderer().SetupShadowBaseEffect(effectDirectionalLight);

                effectDirectionalLight.SetLightDirection(m_sun.Direction);
                effectDirectionalLight.SetLightColorAndIntensity(new Vector3(m_sun.Color.X, m_sun.Color.Y, m_sun.Color.Z), m_sun.Intensity);
                effectDirectionalLight.SetBacklightColorAndIntensity(new Vector3(m_sun.BackColor.X, m_sun.BackColor.Y, m_sun.BackColor.Z), m_sun.BackIntensity);
                //m_sun.SpecularColor = {X:0,9137255 Y:0,6078432 Z:0,2078431} //nice yellow
                effectDirectionalLight.SetSpecularLightColor(m_sun.SpecularColor);
                effectDirectionalLight.EnableCascadeBlending(MyRenderConstants.RenderQualityProfile.EnableCascadeBlending);

                effectDirectionalLight.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());

                effectDirectionalLight.SetEnableAmbientEnvironment(Settings.EnableEnvironmentMapAmbient && MyRenderConstants.RenderQualityProfile.EnableEnvironmentals && CurrentRenderSetup.EnableEnvironmentMapping.Value);
                effectDirectionalLight.SetEnableReflectionEnvironment(Settings.EnableEnvironmentMapReflection && MyRenderConstants.RenderQualityProfile.EnableEnvironmentals && CurrentRenderSetup.EnableEnvironmentMapping.Value);

                if (Settings.EnableShadows && MyRender.CurrentRenderSetup.ShadowRenderer != null)
                {
                    effectDirectionalLight.SetTechnique(effectDirectionalLight.DefaultTechnique);
                }
                else
                {
                    effectDirectionalLight.SetTechnique(effectDirectionalLight.DefaultWithoutShadowsTechnique);
                }

                GetFullscreenQuad().Draw(effectDirectionalLight);
            }
            GetRenderProfiler().EndProfilingBlock();

            //  var st = MyRender.GetRenderTarget(MyRenderTargets.ShadowMap);
            //  Texture.ToFile(st, "c:\\sm.dds", ImageFileFormat.Dds);

            // Blend in background
            if (true) // blend background
            {
                GetRenderProfiler().StartProfilingBlock("Blend background");

                //todo

                /*if (MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA)
                 * {
                 *  // for some reason the other option does not give 0 alpha for the background when rendering gui preview images
                 *  MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();
                 * }
                 * else */
                {
                    MyStateObjects.NonPremultiplied_NoAlphaWrite_BlendState.Apply();
                    //BlendState.NonPremultiplied.Apply();
                }
                DepthStencilState.None.Apply();
                RasterizerState.CullCounterClockwise.Apply();

                MyEffectBlendLights effectBlendLights = MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights;
                Texture             diffuseRT         = GetRenderTarget(MyRenderTargets.Diffuse);
                MyRenderCamera.SetupBaseEffect(effectBlendLights, m_currentLodDrawPass, m_currentSetup.FogMultiplierMult);
                effectBlendLights.SetDiffuseTexture(diffuseRT);
                effectBlendLights.SetNormalTexture(GetRenderTarget(MyRenderTargets.Normals));
                effectBlendLights.SetDepthTexture(GetRenderTarget(MyRenderTargets.Depth));
                effectBlendLights.SetHalfPixel(diffuseRT.GetLevelDescription(0).Width, diffuseRT.GetLevelDescription(0).Height);
                effectBlendLights.SetScale(GetScaleForViewport(diffuseRT));
                effectBlendLights.SetBackgroundTexture(GetRenderTarget(MyRenderTargets.Auxiliary0));

                effectBlendLights.SetTechnique(effectBlendLights.DefaultTechnique);

                GetFullscreenQuad().Draw(effectBlendLights);
                GetRenderProfiler().EndProfilingBlock();

                // Blend in emissive light, overwrite emissivity (alpha)
                GetRenderProfiler().StartProfilingBlock("Copy emisivity");

                //todo
                // if (MyPostProcessHDR.RenderHDRThisFrame())
                //     MyStateObjects.AddEmissiveLight_BlendState.Apply();
                // else
                MyStateObjects.AddEmissiveLight_NoAlphaWrite_BlendState.Apply();

                effectBlendLights.SetTechnique(effectBlendLights.CopyEmissivityTechnique);
                GetFullscreenQuad().Draw(effectBlendLights);


                bool showDebugLighting = false;

                if (Settings.ShowSpecularIntensity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlySpecularIntensity);
                    showDebugLighting = true;
                }
                else
                if (Settings.ShowSpecularPower)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlySpecularPower);
                    showDebugLighting = true;
                }
                else
                if (Settings.ShowEmissivity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlyEmissivity);
                    showDebugLighting = true;
                }
                else
                if (Settings.ShowReflectivity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlyReflectivity);
                    showDebugLighting = true;
                }

                if (showDebugLighting)
                {
                    BlendState.Opaque.Apply();
                    GetFullscreenQuad().Draw(effectBlendLights);
                }

                GetRenderProfiler().EndProfilingBlock();
            }

            //TakeScreenshot("Accumulated_lights", GetRenderTarget(MyRenderTargets.Lod0Depth), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);

            /*TakeScreenshot("EnvironmentMap_1", GetRenderTargetCube(MyRenderTargets.EnvironmentCube), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("EnvironmentMap_2", GetRenderTargetCube(MyRenderTargets.EnvironmentCubeAux), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("AmbientMap_1", GetRenderTargetCube(MyRenderTargets.AmbientCube), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("AmbientMap_2", GetRenderTargetCube(MyRenderTargets.AmbientCubeAux), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             */
            GetRenderProfiler().EndProfilingBlock();
        }