private void RenderAlphaBlended(WeightedBlendedOITQuery query, RenderContext context)
        {
            var graphicsDevice = GraphicsService.GraphicsDevice;

            graphicsDevice.Clear(Color.CornflowerBlue);

            // Render opaque mesh nodes.
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            graphicsDevice.BlendState        = BlendState.Opaque;
            context.RenderPass = "******";
            _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
            context.RenderPass = null;

            // Render transparent mesh nodes with alpha blending.
            graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            graphicsDevice.BlendState        = BlendState.AlphaBlend;
            context.RenderPass = "******";
            _meshRenderer.Render(query.TransparentNodes, context, RenderOrder.Default);
            context.RenderPass = null;
        }
Пример #2
0
    private void RenderWeightedBlendedOIT(WeightedBlendedOITQuery query, RenderContext context)
    {
      var graphicsDevice = GraphicsService.GraphicsDevice;

      var target = context.RenderTarget;
      var viewport = context.Viewport;

      // ----- Transparent pass
      // Set up WBOIT render targets.
      var renderTargetPool = GraphicsService.RenderTargetPool;
      var renderTargetA = renderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          false,
          SurfaceFormat.HdrBlendable,
          DepthFormat.Depth24Stencil8));
      var renderTargetB = renderTargetPool.Obtain2D(
        new RenderTargetFormat(
          context.Viewport.Width,
          context.Viewport.Height,
          false,
#if MONOGAME
          SurfaceFormat.HalfSingle,
#else
          SurfaceFormat.HdrBlendable,
#endif
          DepthFormat.None));

      _renderTargetBindings[0] = new RenderTargetBinding(renderTargetA);
      _renderTargetBindings[1] = new RenderTargetBinding(renderTargetB);
      graphicsDevice.SetRenderTargets(_renderTargetBindings);

      context.RenderTarget = renderTargetA;
      context.Viewport = graphicsDevice.Viewport;

      // Clear render targets to (0, 0, 0, 1).
      graphicsDevice.Clear(Color.Black);

      // Make a Z-only pass to render opaque objects in to the depth buffer.
      // (Color output is disabled.)
      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = GraphicsHelper.BlendStateNoColorWrite;
      context.RenderPass = "******";
      _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
      context.RenderPass = null;

      // Render transparent objects into the WBOIT render targets.
      graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
      graphicsDevice.RasterizerState = RasterizerState.CullNone;
      graphicsDevice.BlendState = _wboitRenderBlendState;
      context.RenderPass = "******";
      _meshRenderer.Render(query.TransparentNodes, context, RenderOrder.Default);
      context.RenderPass = null;

      _renderTargetBindings[0] = default(RenderTargetBinding);
      _renderTargetBindings[1] = default(RenderTargetBinding);

      // ----- Opaque pass
      // Switch back to original render target.
      graphicsDevice.SetRenderTarget(target);
      context.RenderTarget = target;
      context.Viewport = viewport;

      graphicsDevice.Clear(Color.CornflowerBlue);

      // Render opaque objects.
      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.Opaque;
      context.RenderPass = "******";
      _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
      context.RenderPass = null;

      // ----- Combine pass
      // Combine the WBOIT render targets with the scene.
      graphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
      graphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
      graphicsDevice.DepthStencilState = DepthStencilState.None;
      graphicsDevice.RasterizerState = RasterizerState.CullNone;
      graphicsDevice.BlendState = _wboitCombineBlendState;
      _parameterViewportSize.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
      _parameterTextureA.SetValue(renderTargetA);
      _parameterTextureB.SetValue(renderTargetB);
      _wboitEffect.CurrentTechnique.Passes[0].Apply();
      graphicsDevice.DrawFullScreenQuad();
      _parameterTextureA.SetValue((Texture2D)null);
      _parameterTextureB.SetValue((Texture2D)null);

      renderTargetPool.Recycle(renderTargetA);
      renderTargetPool.Recycle(renderTargetB);
    }
Пример #3
0
    private void RenderAlphaBlended(WeightedBlendedOITQuery query, RenderContext context)
    {
      var graphicsDevice = GraphicsService.GraphicsDevice;

      graphicsDevice.Clear(Color.CornflowerBlue);

      // Render opaque mesh nodes.
      graphicsDevice.DepthStencilState = DepthStencilState.Default;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.Opaque;
      context.RenderPass = "******";
      _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
      context.RenderPass = null;

      // Render transparent mesh nodes with alpha blending.
      graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
      graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
      graphicsDevice.BlendState = BlendState.AlphaBlend;
      context.RenderPass = "******";
      _meshRenderer.Render(query.TransparentNodes, context, RenderOrder.Default);
      context.RenderPass = null;
    }
        private void RenderWeightedBlendedOIT(WeightedBlendedOITQuery query, RenderContext context)
        {
            var graphicsDevice = GraphicsService.GraphicsDevice;

            var target   = context.RenderTarget;
            var viewport = context.Viewport;

            // ----- Transparent pass
            // Set up WBOIT render targets.
            var renderTargetPool = GraphicsService.RenderTargetPool;
            var renderTargetA    = renderTargetPool.Obtain2D(
                new RenderTargetFormat(
                    context.Viewport.Width,
                    context.Viewport.Height,
                    false,
                    SurfaceFormat.HdrBlendable,
                    DepthFormat.Depth24Stencil8));
            var renderTargetB = renderTargetPool.Obtain2D(
                new RenderTargetFormat(
                    context.Viewport.Width,
                    context.Viewport.Height,
                    false,
#if MONOGAME
                    SurfaceFormat.HalfSingle,
#else
                    SurfaceFormat.HdrBlendable,
#endif
                    DepthFormat.None));

            _renderTargetBindings[0] = new RenderTargetBinding(renderTargetA);
            _renderTargetBindings[1] = new RenderTargetBinding(renderTargetB);
            graphicsDevice.SetRenderTargets(_renderTargetBindings);

            context.RenderTarget = renderTargetA;
            context.Viewport     = graphicsDevice.Viewport;

            // Clear render targets to (0, 0, 0, 1).
            graphicsDevice.Clear(Color.Black);

            // Make a Z-only pass to render opaque objects in to the depth buffer.
            // (Color output is disabled.)
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            graphicsDevice.BlendState        = GraphicsHelper.BlendStateNoColorWrite;
            context.RenderPass = "******";
            _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
            context.RenderPass = null;

            // Render transparent objects into the WBOIT render targets.
            graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
            graphicsDevice.RasterizerState   = RasterizerState.CullNone;
            graphicsDevice.BlendState        = _wboitRenderBlendState;
            context.RenderPass = "******";
            _meshRenderer.Render(query.TransparentNodes, context, RenderOrder.Default);
            context.RenderPass = null;

            _renderTargetBindings[0] = default(RenderTargetBinding);
            _renderTargetBindings[1] = default(RenderTargetBinding);

            // ----- Opaque pass
            // Switch back to original render target.
            graphicsDevice.SetRenderTarget(target);
            context.RenderTarget = target;
            context.Viewport     = viewport;

            graphicsDevice.Clear(Color.CornflowerBlue);

            // Render opaque objects.
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
            graphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            graphicsDevice.BlendState        = BlendState.Opaque;
            context.RenderPass = "******";
            _meshRenderer.Render(query.SceneNodes, context, RenderOrder.Default);
            context.RenderPass = null;

            // ----- Combine pass
            // Combine the WBOIT render targets with the scene.
            graphicsDevice.SamplerStates[0]  = SamplerState.PointClamp;
            graphicsDevice.SamplerStates[1]  = SamplerState.PointClamp;
            graphicsDevice.DepthStencilState = DepthStencilState.None;
            graphicsDevice.RasterizerState   = RasterizerState.CullNone;
            graphicsDevice.BlendState        = _wboitCombineBlendState;
            _parameterViewportSize.SetValue(new Vector2(graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height));
            _parameterTextureA.SetValue(renderTargetA);
            _parameterTextureB.SetValue(renderTargetB);
            _wboitEffect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawFullScreenQuad();
            _parameterTextureA.SetValue((Texture2D)null);
            _parameterTextureB.SetValue((Texture2D)null);

            renderTargetPool.Recycle(renderTargetA);
            renderTargetPool.Recycle(renderTargetB);
        }