示例#1
0
    private void RenderVelocityBuffer(CameraFrustumQuery frustumQuery, RenderContext context)
    {
      // Create a render target for the velocity buffer and store it in the render context.
      RenderTarget2D velocityBuffer = GraphicsService.RenderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          false,
          SurfaceFormat.HalfVector2,
          DepthFormat.Depth24Stencil8));
      context.Data[RenderContextKeys.VelocityBuffer] = velocityBuffer;

      var graphicsDevice = GraphicsService.GraphicsDevice;
      graphicsDevice.SetRenderTarget(velocityBuffer);

      graphicsDevice.Clear(Color.Black);

      // Update the info in the render context. Some renderers or effects might use this info.
      context.RenderTarget = velocityBuffer;
      context.Viewport = graphicsDevice.Viewport;

      // We do not have a valid depth buffer. In this pass we do not want to render
      // all objects again, therefore we rebuild the hardware depth buffer from the
      // G-Buffer using the RebuildZBufferRenderer. (As a side effect, this also 
      // clears the color target.)
      _rebuildZBufferRenderer.Render(context, false);

      // Render the meshes using the "Velocity" material pass.
      // It is only necessary to render meshes that have moved since the last frame.
      foreach (var node in frustumQuery.SceneNodes)
      {
        if (node is MeshNode && node.LastPoseWorld.HasValue && node.LastPoseWorld.Value != node.PoseWorld)
          _movingMeshes.Add(node);
      }

      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.Opaque;
      context.RenderPass = "******";
      _meshRenderer.Render(_movingMeshes, context);
      context.RenderPass = null;

      _movingMeshes.Clear();
    }
示例#2
0
    private RenderTarget2D RenderScene(CameraFrustumQuery frustumQuery, RenderContext context)
    {
      // Set an offscreen render target. The size is determined by the current viewport.
      RenderTarget2D sceneRenderTarget = GraphicsService.RenderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          false,
          SurfaceFormat.Color,
          DepthFormat.Depth24Stencil8));

      var graphicsDevice = GraphicsService.GraphicsDevice;
      graphicsDevice.SetRenderTarget(sceneRenderTarget);

      // Update the info in the render context. Some renderers or effects might use this info.
      context.RenderTarget = sceneRenderTarget;
      context.Viewport = graphicsDevice.Viewport;

      graphicsDevice.Clear(Color.CornflowerBlue);

      // Render the meshes using the "Default" material.
      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.Opaque;
      graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap;
      context.RenderPass = "******";
      _meshRenderer.Render(frustumQuery.SceneNodes, context);
      context.RenderPass = null;

      // Render the sky.
      _skyRenderer.Render(frustumQuery.SceneNodes, context);

      // Set the render states for alpha blended objects and render BillboardNodes
      // and ParticleSystemNodes.
      graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
      graphicsDevice.RasterizerState = RasterizerState.CullNone;
      graphicsDevice.BlendState = BlendState.NonPremultiplied;
      graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
      _billboardRenderer.Render(frustumQuery.SceneNodes, context);

      return sceneRenderTarget;
    }
示例#3
0
    private void RenderGBuffer(CameraFrustumQuery frustumQuery, RenderContext context)
    {
      // Create render targets for the G-buffer.
      context.GBuffer0 = GraphicsService.RenderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          true,        // Note: Only the SaoFilter for SSAO requires mipmaps to boost performance.
          SurfaceFormat.Single,
          DepthFormat.Depth24Stencil8));
      context.GBuffer1 = GraphicsService.RenderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          false,
          SurfaceFormat.Color,
          DepthFormat.None));

      var graphicsDevice = GraphicsService.GraphicsDevice;

      _renderTargetBindings[0] = new RenderTargetBinding(context.GBuffer0);
      _renderTargetBindings[1] = new RenderTargetBinding(context.GBuffer1);
      graphicsDevice.SetRenderTargets(_renderTargetBindings);

      // Update the info in the render context. Some renderers or effects might use this info.
      context.RenderTarget = context.GBuffer0;
      context.Viewport = graphicsDevice.Viewport;

      // Clear the depth-stencil buffer.
      graphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.Black, 1, 0);

      // Reset the G-buffer to default values.
      _clearGBufferRenderer.Render(context);

      // Render the meshes using the "GBuffer" material pass.
      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.Opaque;
      context.RenderPass = "******";
      _meshRenderer.Render(frustumQuery.SceneNodes, context);
      context.RenderPass = null;
    }