Ejemplo n.º 1
0
        internal static void DrawScene_OneLodLevel_Forward(MyLodTypeEnum currentLodDrawPass)
        {
            m_renderProfiler.StartProfilingBlock(currentLodDrawPass.ToString());

            m_currentLodDrawPass = currentLodDrawPass;

            MyMinerGame.Static.SetDeviceViewport(MyCamera.Viewport);

            BlendState.Opaque.Apply();
            DepthStencilState.Default.Apply();

            if (currentLodDrawPass == MyLodTypeEnum.LOD0)
            {
                //                 //  Clear depth buffer + stencil because that should be faster than just clearing depth buffer (HW thing...)
                //                 m_device.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, new Color(0, 0, 0, 0), 1, 0);
                m_renderElementIndex = 0;
            }

            if (!Wireframe)
                RasterizerState.CullCounterClockwise.Apply();
            else
                MyStateObjects.WireframeRasterizerState.Apply();

            // Render registered modules for this stage
            m_renderProfiler.StartProfilingBlock("MyRenderStage.LODDrawStart");
            DrawRenderModules(MyRenderStage.LODDrawStart);
            m_renderProfiler.EndProfilingBlock();

            if (currentLodDrawPass == MyLodTypeEnum.LOD0) // LOD0
            {
                m_renderProfiler.StartProfilingBlock("DrawNearObjects");
                if (!SkipLOD_NEAR && m_currentSetup.EnableNear.HasValue && m_currentSetup.EnableNear.Value)
                {
                    DrawScene_OneLodLevel_DrawNearObjects(ShowStencilOptimization, true);
                }
                m_renderProfiler.EndProfilingBlock();

                m_renderProfiler.StartProfilingBlock("Draw(false);");
                m_currentLodDrawPass = MyLodTypeEnum.LOD0;
                if (!SkipLOD_0)
                {
                    DrawScene_OneLodLevel_Draw(false, true);
                }
                m_renderProfiler.EndProfilingBlock();
            }
            else // LOD1
            {
                m_currentLodDrawPass = MyLodTypeEnum.LOD1;
                if (!SkipLOD_1)
                {
                    DrawScene_OneLodLevel_Draw(false, true);
                }
            }

            RasterizerState.CullCounterClockwise.Apply();

            // Render registered modules for this stage
            m_renderProfiler.StartProfilingBlock("MyRenderStage.LODDrawEnd");
            DrawRenderModules(MyRenderStage.LODDrawEnd);
            m_renderProfiler.EndProfilingBlock();

            m_renderProfiler.EndProfilingBlock();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draw one LOD level of the scene
        /// </summary>
        /// <param name="currentLodDrawPass"></param>
        /// <param name="drawCockpitInterior"></param>
        internal static void DrawScene_OneLodLevel(MyLodTypeEnum currentLodDrawPass)
        {
            m_renderProfiler.StartProfilingBlock(currentLodDrawPass.ToString());

            m_currentLodDrawPass = currentLodDrawPass;

            switch (currentLodDrawPass)
            {
                case MyLodTypeEnum.LOD0:
                    MyMinerGame.SetRenderTargets(m_GBufferDefaultBinding, null);
                    break;
            }

            MyMinerGame.Static.SetDeviceViewport(MyCamera.Viewport);

            //  We don't need depth buffer for clearing Gbuffer
            DepthStencilState.None.Apply();
            BlendState.Opaque.Apply();
            RasterizerState.CullCounterClockwise.Apply();


            if (currentLodDrawPass == MyLodTypeEnum.LOD0)
            {
                //  Clear depth buffer + stencil because that should be faster than just clearing depth buffer (HW thing...)
                m_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer | ClearFlags.Stencil, new ColorBGRA(1.0f,0,0,1), 1, 0);
                //  Clear Gbuffer
                MyGuiManager.GetFullscreenQuad().Draw(MyRender.GetEffect(MyEffects.ClearGBuffer));
            }

            //  This compare function "less" is better when drawing normal and LOD1 cells, then z-fighting isn't so visible.
            DepthStencilState.Default.Apply();

            if (!Wireframe)
                RasterizerState.CullCounterClockwise.Apply();
            else
                MyStateObjects.WireframeRasterizerState.Apply();

            m_renderProfiler.StartProfilingBlock("MyRenderStage.LODDrawStart");
            // Render registered modules for this stage
            m_renderProfiler.EndProfilingBlock();

            bool drawNear = !SkipLOD_NEAR && m_currentSetup.EnableNear.HasValue && m_currentSetup.EnableNear.Value;

            if (currentLodDrawPass == MyLodTypeEnum.LOD0) // LOD0
            {
                m_renderProfiler.StartProfilingBlock("DrawNearObjects");
                if (drawNear/* && MyRender.EnableLODBlending*/)
                {
                    DrawScene_OneLodLevel_DrawNearObjects(ShowStencilOptimization, true);
                }
                m_renderProfiler.EndProfilingBlock();

                m_renderProfiler.StartProfilingBlock("Draw(false);");
                m_currentLodDrawPass = MyLodTypeEnum.LOD0;
                if (!SkipLOD_0)
                {
                    DrawScene_OneLodLevel_Draw(false, true);
                }
                m_renderProfiler.EndProfilingBlock();
            }
            else // LOD1
            {
                /*
                if (EnableStencilOptimizationLOD1 && drawNear)
                {
                    DrawScene_OneLodLevel_DrawNearObjects(true, false);
                }
                 */
                         /*
                if (drawNear && !MyRender.EnableLODBlending)
                {
                    DrawScene_OneLodLevel_DrawNearObjects(ShowStencilOptimization, true);
                }          */

                //if (!MyRender.EnableLODBlending)
                {
                    //m_device.DepthStencilState = MyStateObjects.DepthStencil_TestFarObject;
                    MyStateObjects.DepthStencil_TestFarObject.Apply();
                }

                m_currentLodDrawPass = MyLodTypeEnum.LOD1;
                if (!SkipLOD_1)
                {
                    DrawScene_OneLodLevel_Draw(false, true);
                }

                m_renderProfiler.StartProfilingBlock("DrawNearObjects 2");
                /*if (drawNear && !MyRender.EnableLODBlending)
                {
                    DrawScene_OneLodLevel_DrawNearObjects(ShowStencilOptimization, true);
                } */
                m_renderProfiler.EndProfilingBlock();
            }

            //m_device.RasterizerState = RasterizerState.CullCounterClockwise;
            RasterizerState.CullCounterClockwise.Apply();

            // Render registered modules for this stage
            m_renderProfiler.StartProfilingBlock("MyRenderStage.LODDrawEnd");
            DrawRenderModules(MyRenderStage.LODDrawEnd);
            m_renderProfiler.EndProfilingBlock();

            m_renderProfiler.EndProfilingBlock();
        }