Exemple #1
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        public SplitScreen(IServiceLocator services)
            : base(services.GetInstance <IGraphicsService>())
        {
            _spriteBatch       = new SpriteBatch(GraphicsService.GraphicsDevice);
            _meshRenderer      = new MeshRenderer();
            _decalRenderer     = new DecalRenderer(GraphicsService);
            _billboardRenderer = new BillboardRenderer(GraphicsService, 2048)
            {
                EnableSoftParticles = true,
            };
            _transparentSceneRenderer = new SceneRenderer();
            _transparentSceneRenderer.Renderers.Add(_meshRenderer);
            _transparentSceneRenderer.Renderers.Add(_billboardRenderer);
            _cloudMapRenderer       = new CloudMapRenderer(GraphicsService);
            _shadowMapRenderer      = new ShadowMapRenderer(_meshRenderer);
            _shadowMaskRenderer     = new ShadowMaskRenderer(GraphicsService, 2);
            _gBufferRenderer        = new GBufferRenderer(GraphicsService, _meshRenderer, _decalRenderer);
            _lightBufferRenderer    = new LightBufferRenderer(GraphicsService);
            _lensFlareRenderer      = new LensFlareRenderer(GraphicsService, _spriteBatch);
            _skyRenderer            = new SkyRenderer(GraphicsService);
            _fogRenderer            = new FogRenderer(GraphicsService);
            _internalDebugRenderer  = new DebugRenderer(GraphicsService, _spriteBatch, null);
            _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService);

            Scene = new Scene();

            PostProcessors = new PostProcessorChain(GraphicsService);
            PostProcessors.Add(new HdrFilter(GraphicsService)
            {
                MinExposure    = 0,
                MaxExposure    = 4,
                BloomIntensity = 1,
                BloomThreshold = 0.6f,
            });

            var contentManager = services.GetInstance <ContentManager>();

            _reticle = contentManager.Load <Texture2D>("Reticle");

            // Use the sprite font of the GUI.
            var uiContentManager = services.GetInstance <ContentManager>("UIContent");
            var spriteFont       = uiContentManager.Load <SpriteFont>("Default");

            DebugRenderer = new DebugRenderer(GraphicsService, spriteFont)
            {
                DefaultColor        = new Color(0, 0, 0),
                DefaultTextPosition = new Vector2F(10),
            };
        }
Exemple #2
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        public DeferredGraphicsScreen(IServiceLocator services)
            : base(services.GetInstance <IGraphicsService>())
        {
            _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);

            // Let's create the necessary scene node renderers:
            // The current sample contains MeshNodes (opaque and transparent), DecalNodes
            // and ParticleSystemNodes (transparent).
            _meshRenderer      = new MeshRenderer();
            _decalRenderer     = new DecalRenderer(GraphicsService);
            _billboardRenderer = new BillboardRenderer(GraphicsService, 2048)
            {
                EnableSoftParticles = true,

                // If you have an extreme amount of particles that cover the entire screen,
                // you can turn on offscreen rendering to improve performance.
                //EnableOffscreenRendering = true,
            };

            // The _alphaBlendSceneRenderer combines all renderers for transparent
            // (= alpha blended) objects.
            AlphaBlendSceneRenderer = new SceneRenderer();
            AlphaBlendSceneRenderer.Renderers.Add(_meshRenderer);
            AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer);

            // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.)
            _cloudMapRenderer = new CloudMapRenderer(GraphicsService);

            // Shadows
            _shadowMapRenderer  = new ShadowMapRenderer(_meshRenderer);
            _shadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2);

            // Renderers which create the intermediate render targets:
            // Those 2 renderers are implemented in this sample. Those functions could
            // be implemented directly in this class but we have created separate classes
            // to make the code more readable.
            _gBufferRenderer    = new GBufferRenderer(GraphicsService, _meshRenderer, _decalRenderer);
            LightBufferRenderer = new LightBufferRenderer(GraphicsService);

            // Other specialized renderers:
            _lensFlareRenderer      = new LensFlareRenderer(GraphicsService, _spriteBatch);
            _skyRenderer            = new SkyRenderer(GraphicsService);
            _fogRenderer            = new FogRenderer(GraphicsService);
            _internalDebugRenderer  = new DebugRenderer(GraphicsService, _spriteBatch, null);
            _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService);

            Scene = new Scene();

            // This screen needs a HDR filter to map high dynamic range values back to
            // low dynamic range (LDR).
            PostProcessors = new PostProcessorChain(GraphicsService);
            PostProcessors.Add(new HdrFilter(GraphicsService)
            {
                EnableBlueShift = true,
                BlueShiftCenter = 0.00007f,
                BlueShiftRange  = 0.5f,
                BlueShiftColor  = new Vector3F(0, 0, 2f),
                MinExposure     = 0,
                MaxExposure     = 10,
                BloomIntensity  = 1,
                BloomThreshold  = 0.6f,
            });

            // Use 2D texture for reticle.
            var contentManager = services.GetInstance <ContentManager>();

            _reticle = contentManager.Load <Texture2D>("Reticle");

            // Use the sprite font of the GUI.
            var uiContentManager = services.GetInstance <ContentManager>("UIContent");
            var spriteFont       = uiContentManager.Load <SpriteFont>("Default");

            DebugRenderer = new DebugRenderer(GraphicsService, _spriteBatch, spriteFont)
            {
                DefaultColor        = new Color(0, 0, 0),
                DefaultTextPosition = new Vector2F(10),
            };

            EnableLod = true;
        }
Exemple #3
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        public DeferredGraphicsScreen(IServiceLocator services)
            : base(services.GetInstance <IGraphicsService>())
        {
            var contentManager = services.GetInstance <ContentManager>();

            SpriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);

            // Let's create the necessary scene node renderers:
            // The current sample contains MeshNodes (opaque and transparent), DecalNodes
            // and ParticleSystemNodes (transparent).
            MeshRenderer       = new MeshRenderer();
            _decalRenderer     = new DecalRenderer(GraphicsService);
            _billboardRenderer = new BillboardRenderer(GraphicsService, 2048)
            {
                EnableSoftParticles = true,

                // If you have an extreme amount of particles that cover the entire screen,
                // you can turn on offscreen rendering to improve performance.
                //EnableOffscreenRendering = true,
            };

            // The _alphaBlendSceneRenderer combines all renderers for transparent
            // (= alpha blended) objects.
            AlphaBlendSceneRenderer = new SceneRenderer();
            AlphaBlendSceneRenderer.Renderers.Add(MeshRenderer);
            AlphaBlendSceneRenderer.Renderers.Add(_billboardRenderer);
            AlphaBlendSceneRenderer.Renderers.Add(new WaterRenderer(GraphicsService));
#if !TRIAL
            // The FogSphereSample is not included in the trial version.
            AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService));
#endif

            // Renderer for cloud maps. (Only necessary if LayeredCloudMaps are used.)
            _cloudMapRenderer = new CloudMapRenderer(GraphicsService);

            // Renderer for SceneCaptureNodes. See also SceneCapture2DSample.
            // In the constructor we specify a method is called in SceneCaptureRenderer.Render()
            // when the scene must be rendered for the SceneCaptureNodes.
            _sceneCaptureRenderer = new SceneCaptureRenderer(context =>
            {
                // Get scene nodes which are visible by the current camera.
                CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context);
                // Render scene (with post-processing, with lens flares, no debug rendering, no reticle).
                RenderScene(sceneQuery, context, true, true, false, false);
            });

            // Renderer for PlanarReflectionNodes. See also PlanarReflectionSample.
            // In the constructor we specify a method is called in PlanarReflectionRenderer.Render()
            // to create the reflection images.
            _planarReflectionRenderer = new PlanarReflectionRenderer(context =>
            {
                // Get scene nodes which are visible by the current camera.
                CustomSceneQuery sceneQuery = Scene.Query <CustomSceneQuery>(context.CameraNode, context);

                // Planar reflections are often for WaterNodes. These nodes should not be rendered
                // into their own reflection map. But when the water surface is displaced by waves,
                // some waves could be visible in the reflection.
                // Simple solution: Do not render any water nodes into the reflection map.
                for (int i = 0; i < sceneQuery.RenderableNodes.Count; i++)
                {
                    if (sceneQuery.RenderableNodes[i] is WaterNode)
                    {
                        sceneQuery.RenderableNodes[i] = null;
                    }
                }

                // Render scene (no post-processing, no lens flares, no debug rendering, no reticle).
                RenderScene(sceneQuery, context, false, false, false, false);
            });

            _waterWavesRenderer = new WaterWavesRenderer(GraphicsService);

            // Shadows
            _shadowMapRenderer  = new ShadowMapRenderer(MeshRenderer);
            _shadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2);

            // Renderers which create the intermediate render targets:
            // Those 2 renderers are implemented in this sample. Those functions could
            // be implemented directly in this class but we have created separate classes
            // to make the code more readable.
            _gBufferRenderer    = new GBufferRenderer(GraphicsService, MeshRenderer, _decalRenderer);
            LightBufferRenderer = new LightBufferRenderer(GraphicsService);

            // Other specialized renderers:
            _lensFlareRenderer      = new LensFlareRenderer(GraphicsService, SpriteBatch);
            _skyRenderer            = new SkyRenderer(GraphicsService);
            _fogRenderer            = new FogRenderer(GraphicsService);
            _internalDebugRenderer  = new DebugRenderer(GraphicsService, SpriteBatch, null);
            _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService);

            Scene = new Scene();

            // This screen needs a HDR filter to map high dynamic range values back to
            // low dynamic range (LDR).
            PostProcessors = new PostProcessorChain(GraphicsService);
            PostProcessors.Add(new HdrFilter(GraphicsService)
            {
                EnableBlueShift = true,
                BlueShiftCenter = 0.00007f,
                BlueShiftRange  = 0.5f,
                BlueShiftColor  = new Vector3F(0, 0, 2f),
                MinExposure     = 0,
                MaxExposure     = 10,
                BloomIntensity  = 1,
                BloomThreshold  = 0.6f,
            });
            _underwaterPostProcessor = new UnderwaterPostProcessor(GraphicsService, contentManager);
            PostProcessors.Add(_underwaterPostProcessor);

            // Use 2D texture for reticle.
            _reticle = contentManager.Load <Texture2D>("Reticle");

            // Use the sprite font of the GUI.
            var uiContentManager = services.GetInstance <ContentManager>("UIContent");
            var spriteFont       = uiContentManager.Load <SpriteFont>("Default");
            DebugRenderer = new DebugRenderer(GraphicsService, SpriteBatch, spriteFont)
            {
                DefaultColor        = new Color(0, 0, 0),
                DefaultTextPosition = new Vector2F(10),
            };

            EnableLod = true;
        }