コード例 #1
0
    public PostProcessingGraphicsScreen(IServiceLocator services)
      : base(services.GetInstance<IGraphicsService>())
    {
      _sampleFramework = services.GetInstance<SampleFramework>();

      _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice);
      _clearGBufferRenderer = new ClearGBufferRenderer(GraphicsService);
      _rebuildZBufferRenderer = new RebuildZBufferRenderer(GraphicsService);
      _meshRenderer = new MeshRenderer();
      _skyRenderer = new SkyRenderer(GraphicsService);
      _billboardRenderer = new BillboardRenderer(GraphicsService, 2048);

      Scene = new Scene();
      PostProcessors = new PostProcessorChain(GraphicsService);

      // 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>("UI Themes/BlendBlue/Default");
      DebugRenderer = new DebugRenderer(GraphicsService, spriteFont)
      {
        DefaultColor = new Color(0, 0, 0),
        DefaultTextPosition = new Vector2F(10),
      };
    }
コード例 #2
0
    //--------------------------------------------------------------
    #region Creation & Cleanup
    //--------------------------------------------------------------

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

      SpriteBatch = GraphicsService.GetSpriteBatch();

      // Let's create the necessary scene node renderers:
#if !XBOX360
      TerrainRenderer = new TerrainRenderer(GraphicsService);
#endif
      MeshRenderer = new MeshRenderer();

      // The _opaqueMeshSceneRenderer combines all renderers for opaque
      // (= not alpha blended) meshes.
      _opaqueMeshSceneRenderer = new SceneRenderer();
#if !XBOX360
      _opaqueMeshSceneRenderer.Renderers.Add(TerrainRenderer);
#endif
      _opaqueMeshSceneRenderer.Renderers.Add(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));
      AlphaBlendSceneRenderer.Renderers.Add(new FogSphereRenderer(GraphicsService));
      AlphaBlendSceneRenderer.Renderers.Add(new VolumetricLightRenderer(GraphicsService));

#if !XBOX360
      // Update terrain clipmaps. (Only necessary if TerrainNodes are used.)
      _terrainClipmapRenderer = new TerrainClipmapRenderer(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 which 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 which 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);

        var planarReflectionNode = (PlanarReflectionNode)context.ReferenceNode;

        // Planar reflections are often for WaterNodes. These nodes should not be rendered 
        // into their own reflection map because when the water surface is displaced by waves, 
        // some waves could be visible in the reflection. 
        // --> Remove the water node from the renderable nodes. (In our samples, the water
        // node is the parent of the reflection node.)
        if (planarReflectionNode.Parent is WaterNode)
        {
          var index = sceneQuery.RenderableNodes.IndexOf(planarReflectionNode.Parent);
          if (index >= 0)
            sceneQuery.RenderableNodes[index] = 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);

      // The shadow map renderer renders a depth image from the viewpoint of the light and
      // stores it in LightNode.Shadow.ShadowMap.
      ShadowMapRenderer = new ShadowMapRenderer(context =>
      {
        var query = context.Scene.Query<ShadowCasterQuery>(context.CameraNode, context);
        if (query.ShadowCasters.Count == 0)
          return false;

        _opaqueMeshSceneRenderer.Render(query.ShadowCasters, context);
        return true;
      });

      // The shadow mask renderer evaluates the shadow maps, does shadow filtering 
      // and stores the resulting shadow factor in a screen space image 
      //(see LightNode.Shadow.ShadowMask/ShadowMaskChannel).
      ShadowMaskRenderer = new ShadowMaskRenderer(GraphicsService, 2);

      // Optionally, we can blur the shadow mask to make the shadows smoother.
      var blur = new Blur(GraphicsService)
      {
        IsAnisotropic = false,
        IsBilateral = true,
        EdgeSoftness = 0.05f,
        Scale = 1f,
        Enabled = false,  // Disable blur by default.
      };
      blur.InitializeGaussianBlur(11, 3, true);
      ShadowMaskRenderer.Filter = blur;

      // 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, _opaqueMeshSceneRenderer, _decalRenderer);
      LightBufferRenderer = new LightBufferRenderer(GraphicsService);

      // Other specialized renderers:
      _lensFlareRenderer = new LensFlareRenderer(GraphicsService);
      _skyRenderer = new SkyRenderer(GraphicsService);
      _fogRenderer = new FogRenderer(GraphicsService);
      _internalDebugRenderer = new DebugRenderer(GraphicsService, 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.0004f,
        BlueShiftRange = 0.5f,
        //BlueShiftColor = new Vector3F(1.05f / 4f, 0.97f / 4f, 1.27f / 4f),  // Default physically-based blue-shift
        BlueShiftColor = new Vector3F(0.25f, 0.25f, 0.7f),  // More dramatic blue-shift
        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>("UI Themes/BlendBlue/Default");
      DebugRenderer = new DebugRenderer(GraphicsService, spriteFont)
      {
        DefaultColor = new Color(0, 0, 0),
        DefaultTextPosition = new Vector2F(10),
      };

      EnableLod = true;
    }