Exemple #1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            GL.Enable(EnableCap.ClipDistance0);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Blend);

            // Shadow rendering
            shadows.ShadowBuffer.Bind();
            GL.Clear(ClearBufferMask.DepthBufferBit);
            assets.RenderShadowMap(shadows, terrain);
            terrain.RenderShadowMap(camera, shadows, ClipPlane.ClipBottom);

            GL.ClipControl(ClipOrigin.LowerLeft, ClipDepthMode.ZeroToOne);

            // Water refraction rendering
            water.RefractionBuffer.Bind();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            terrain.Render(camera, light, null, ClipPlane.ClipTop);
            assets.Render(camera, light, null, terrain, ClipPlane.ClipTop);

            // Water reflection rendering
            camera.InvertY();
            water.ReflectionBuffer.Bind();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            terrain.Render(camera, light, null, ClipPlane.ClipBottom);
            assets.Render(camera, light, null, terrain, ClipPlane.ClipBottom);
            sky.Render(camera, light);
            GL.Disable(EnableCap.ClipDistance0);
            camera.Reset();

            // Main rendering
            multisampling.Bind();
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.PolygonMode(MaterialFace.FrontAndBack, State.PolygonMode);

            sky.Render(camera, light);
            terrain.Render(camera, light, shadows, ClipPlane.ClipBottom);
            water.Render(camera, light, shadows);

            GL.Enable(EnableCap.SampleShading);
            assets.Render(camera, light, shadows, terrain, ClipPlane.ClipBottom);
            GL.Disable(EnableCap.SampleShading);

            // UI and debug
            GL.Enable(EnableCap.Blend);
            GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
            GL.Disable(EnableCap.DepthTest);
            GL4.GL.BlendFuncSeparate(GL4.BlendingFactorSrc.SrcAlpha, GL4.BlendingFactorDest.OneMinusSrcAlpha, GL4.BlendingFactorSrc.One, GL4.BlendingFactorDest.One);

            GL.ClipControl(ClipOrigin.LowerLeft, ClipDepthMode.NegativeOneToOne);
            ui.Render();
            // shadows.ShadowBuffer.DrawDepthBuffer();

            // Draw to screen
            multisampling.Draw();

            SwapBuffers();
            State.Time.CountFPS();
        }