Exemple #1
0
 //--------------------------------------------------------------
 public LightBufferRenderer(IGraphicsService graphicsService)
 {
     _graphicsService = graphicsService;
       LightRenderer = new LightRenderer(graphicsService);
       AmbientOcclusionType = AmbientOcclusionType.SSAO;
       _copyFilter = new CopyFilter(graphicsService);
 }
Exemple #2
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="LuminanceFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public LuminanceFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/LuminanceFilter");
            _useGeometricMeanParameter     = _effect.Parameters["UseGeometricMean"];
            _useAdaptionParameter          = _effect.Parameters["UseAdaption"];
            _deltaTimeParameter            = _effect.Parameters["DeltaTime"];
            _adaptionSpeedParameter        = _effect.Parameters["AdaptionSpeed"];
            _lastLuminanceTextureParameter = _effect.Parameters["LastLuminanceTexture"];
            _textureParameter    = _effect.Parameters["SourceTexture"];
            _sourceSizeParameter = _effect.Parameters["SourceSize"];
            _targetSizeParameter = _effect.Parameters["TargetSize"];
            _createPass          = _effect.CurrentTechnique.Passes["Create"];
            _downsamplePass      = _effect.CurrentTechnique.Passes["Downsample"];
            _finalPass           = _effect.CurrentTechnique.Passes["Final"];

            _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);
            _copyFilter       = PostProcessHelper.GetCopyFilter(graphicsService);

            UseGeometricMean = true;
            UseAdaption      = true;
            AdaptionSpeed    = 0.02f;

            DefaultTargetFormat = new RenderTargetFormat(1, 1, false, SurfaceFormat.HalfVector4, DepthFormat.None);
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="LuminanceFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public LuminanceFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/LuminanceFilter");
              _useGeometricMeanParameter = _effect.Parameters["UseGeometricMean"];
              _useAdaptionParameter = _effect.Parameters["UseAdaption"];
              _deltaTimeParameter = _effect.Parameters["DeltaTime"];
              _adaptionSpeedParameter = _effect.Parameters["AdaptionSpeed"];
              _lastLuminanceTextureParameter = _effect.Parameters["LastLuminanceTexture"];
              _textureParameter = _effect.Parameters["SourceTexture"];
              _sourceSizeParameter = _effect.Parameters["SourceSize"];
              _targetSizeParameter = _effect.Parameters["TargetSize"];
              _createPass = _effect.CurrentTechnique.Passes["Create"];
              _downsamplePass = _effect.CurrentTechnique.Passes["Downsample"];
              _finalPass = _effect.CurrentTechnique.Passes["Final"];

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);
              _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);

              UseGeometricMean = true;
              UseAdaption = true;
              AdaptionSpeed = 0.02f;

              DefaultTargetFormat = new RenderTargetFormat(1, 1, false, SurfaceFormat.HalfVector4, DepthFormat.None);
        }
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleMotionBlur"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SimpleMotionBlur(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SimpleMotionBlur");
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _strengthParameter = _effect.Parameters["Strength"];
              _sourceTextureParameter = _effect.Parameters["SourceTexture"];
              _lastSourceTextureParameter = _effect.Parameters["LastSourceTexture"];

              _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);

              Strength = 0.8f;
        }
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleMotionBlur"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SimpleMotionBlur(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/SimpleMotionBlur");
            _viewportSizeParameter      = _effect.Parameters["ViewportSize"];
            _strengthParameter          = _effect.Parameters["Strength"];
            _sourceTextureParameter     = _effect.Parameters["SourceTexture"];
            _lastSourceTextureParameter = _effect.Parameters["LastSourceTexture"];

            _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);

            Strength = 0.8f;
        }
Exemple #6
0
    public CopyFilterSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // A filter that copies the current image to a low resolution render target.
      var copyFilterA = new CopyFilter(GraphicsService)
      {
        DefaultTargetFormat = new RenderTargetFormat(320, 240, false, SurfaceFormat.Color, DepthFormat.None),
      };
      GraphicsScreen.PostProcessors.Add(copyFilterA);

      // A filter that copies the result of the first filter to the back buffer.
      var copyFilterB = new CopyFilter(GraphicsService);
      GraphicsScreen.PostProcessors.Add(copyFilterB);
    }
Exemple #7
0
    public DownsampleSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Create a DownsampleFilter which downsamples the current screen to a 64x64 pixel buffer.
      _downsampleFilter = new DownsampleFilter(GraphicsService)
      {
        // The PostProcessorChain reads the DefaultTargetFormat property. Here,
        // we can define the downsampled resolution.
        DefaultTargetFormat = new RenderTargetFormat(64, 64, false, SurfaceFormat.Color, DepthFormat.None),
      };
      GraphicsScreen.PostProcessors.Add(_downsampleFilter);

      // This CopyFilter copies the downsampled image to the back buffer.
      _copyFilter = new CopyFilter(GraphicsService);
      GraphicsScreen.PostProcessors.Add(_copyFilter);
    }
        public static CopyFilter GetCopyFilter(this IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

              const string Key = "__CopyFilter";
              object obj;
              graphicsService.Data.TryGetValue(Key, out obj);
              var instance = obj as CopyFilter;
              if (instance == null)
              {
            instance = new CopyFilter(graphicsService);
            graphicsService.Data[Key] = instance;
              }

              return instance;
        }
        public static CopyFilter GetCopyFilter(this IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            {
                throw new ArgumentNullException("graphicsService");
            }

            const string Key = "__CopyFilter";
            object       obj;

            graphicsService.Data.TryGetValue(Key, out obj);
            var instance = obj as CopyFilter;

            if (instance == null)
            {
                instance = new CopyFilter(graphicsService);
                graphicsService.Data[Key] = instance;
            }

            return(instance);
        }
Exemple #10
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="SsaoFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SsaoFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/SsaoFilter");
              _farParameter = _effect.Parameters["Far"];
              _radiusParameter = _effect.Parameters["Radius"];
              _strengthParameter = _effect.Parameters["Strength"];
              _maxDistancesParameter = _effect.Parameters["MaxDistances"];
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _sourceTextureParameter = _effect.Parameters["SourceTexture"];
              _gBuffer0Parameter = _effect.Parameters["GBuffer0"];
              _occlusionTextureParameter = _effect.Parameters["OcclusionTexture"];
              _createLinesAPass = _effect.CurrentTechnique.Passes["CreateLinesA"];
              _createLinesBPass = _effect.CurrentTechnique.Passes["CreateLinesB"];
              _blurHorizontalPass = _effect.CurrentTechnique.Passes["BlurHorizontal"];
              _blurVerticalPass = _effect.CurrentTechnique.Passes["BlurVertical"];
              _combinePass = _effect.CurrentTechnique.Passes["Combine"];
              _copyPass = _effect.CurrentTechnique.Passes["Copy"];

              Radii = new Vector2F(0.01f, 0.02f);
              MaxDistances = new Vector2F(0.5f, 1.0f);
              Strength = 1f;
              NumberOfBlurPasses = 1;
              DownsampleFactor = 2;
              Quality = 2;
              Scale = new Vector2F(0.5f, 2f);
              CombineWithSource = true;

              _blur = new Blur(graphicsService);
              _blur.InitializeGaussianBlur(7, 7 / 3, true);

              _copyFilter = PostProcessHelper.GetCopyFilter(graphicsService);
              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              Random random = new Random(123456);
              Vector3[] vectors = new Vector3[9];

              // 16 random vectors for Crytek-style point samples.
              //for (int i = 0; i < vectors.Length; i++)
              //  vectors[i] = (Vector3)random.NextQuaternionF().Rotate(Vector3F.One).Normalized;
              //    //* random.NextFloat(0.5f, 1) // Note: StarCraft 2 uses varying length to vary the sample offset length.

              // We create rotated random vectors with uniform distribution in 360°. Each random vector
              // is further rotated with small random angle.
              float jitterAngle = ConstantsF.TwoPi / vectors.Length / 4;
              for (int i = 0; i < vectors.Length; i++)
            vectors[i] = (Vector3)(Matrix33F.CreateRotationZ(ConstantsF.TwoPi * i / vectors.Length + random.NextFloat(-jitterAngle, jitterAngle)) * new Vector3F(1, 0, 0)).Normalized;

              // Permute randomVectors.
              for (int i = 0; i < vectors.Length; i++)
            MathHelper.Swap(ref vectors[i], ref vectors[random.Next(i, vectors.Length - 1)]);

              // Scale random vectors.
              for (int i = 0; i < vectors.Length; i++)
            vectors[i].Z = random.NextFloat(Scale.X, Scale.Y);

              _effect.Parameters["RandomVectors"].SetValue(vectors);
        }
Exemple #11
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="SsaoFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public SsaoFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect                    = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/SsaoFilter");
            _farParameter              = _effect.Parameters["Far"];
            _radiusParameter           = _effect.Parameters["Radius"];
            _strengthParameter         = _effect.Parameters["Strength"];
            _maxDistancesParameter     = _effect.Parameters["MaxDistances"];
            _viewportSizeParameter     = _effect.Parameters["ViewportSize"];
            _sourceTextureParameter    = _effect.Parameters["SourceTexture"];
            _gBuffer0Parameter         = _effect.Parameters["GBuffer0"];
            _occlusionTextureParameter = _effect.Parameters["OcclusionTexture"];
            _createLinesAPass          = _effect.CurrentTechnique.Passes["CreateLinesA"];
            _createLinesBPass          = _effect.CurrentTechnique.Passes["CreateLinesB"];
            _blurHorizontalPass        = _effect.CurrentTechnique.Passes["BlurHorizontal"];
            _blurVerticalPass          = _effect.CurrentTechnique.Passes["BlurVertical"];
            _combinePass               = _effect.CurrentTechnique.Passes["Combine"];
            _copyPass                  = _effect.CurrentTechnique.Passes["Copy"];

            Radii              = new Vector2F(0.01f, 0.02f);
            MaxDistances       = new Vector2F(0.5f, 1.0f);
            Strength           = 1f;
            NumberOfBlurPasses = 1;
            DownsampleFactor   = 2;
            Quality            = 2;
            Scale              = new Vector2F(0.5f, 2f);
            CombineWithSource  = true;

            _blur = new Blur(graphicsService);
            _blur.InitializeGaussianBlur(7, 7 / 3, true);

            _copyFilter       = PostProcessHelper.GetCopyFilter(graphicsService);
            _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

            Random random = new Random(123456);

            Vector3[] vectors = new Vector3[9];

            // 16 random vectors for Crytek-style point samples.
            //for (int i = 0; i < vectors.Length; i++)
            //  vectors[i] = (Vector3)random.NextQuaternionF().Rotate(Vector3F.One).Normalized;
            //    //* random.NextFloat(0.5f, 1) // Note: StarCraft 2 uses varying length to vary the sample offset length.

            // We create rotated random vectors with uniform distribution in 360°. Each random vector
            // is further rotated with small random angle.
            float jitterAngle = ConstantsF.TwoPi / vectors.Length / 4;

            for (int i = 0; i < vectors.Length; i++)
            {
                vectors[i] = (Vector3)(Matrix33F.CreateRotationZ(ConstantsF.TwoPi * i / vectors.Length + random.NextFloat(-jitterAngle, jitterAngle)) * new Vector3F(1, 0, 0)).Normalized;
            }

            // Permute randomVectors.
            for (int i = 0; i < vectors.Length; i++)
            {
                MathHelper.Swap(ref vectors[i], ref vectors[random.Next(i, vectors.Length - 1)]);
            }

            // Scale random vectors.
            for (int i = 0; i < vectors.Length; i++)
            {
                vectors[i].Z = random.NextFloat(Scale.X, Scale.Y);
            }

            _effect.Parameters["RandomVectors"].SetValue(vectors);
        }