Ejemplo n.º 1
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="GodRayFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public GodRayFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            Effect effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/GodRayFilter");

            _viewportSizeParameter    = effect.Parameters["ViewportSize"];
            _parameters0Parameter     = effect.Parameters["Parameters0"];
            _parameters1Parameter     = effect.Parameters["Parameters1"];
            _intensityParameter       = effect.Parameters["Intensity"];
            _numberOfSamplesParameter = effect.Parameters["NumberOfSamples"];
            _sourceTextureParameter   = effect.Parameters["SourceTexture"];
            _gBuffer0Parameter        = effect.Parameters["GBuffer0"];
            _rayTextureParameter      = effect.Parameters["RayTexture"];
            _createMaskPass           = effect.CurrentTechnique.Passes["CreateMask"];
            _blurPass    = effect.CurrentTechnique.Passes["Blur"];
            _combinePass = effect.CurrentTechnique.Passes["Combine"];

            _downsampleFilter = graphicsService.GetDownsampleFilter();

            Scale            = 1;
            LightDirection   = new Vector3F(0, -1, 0);
            LightRadius      = 0.2f;
            Intensity        = new Vector3F(1, 1, 1);
            DownsampleFactor = 4;
            NumberOfSamples  = 8;
            NumberOfPasses   = 2;
            Softness         = 1;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="GodRayFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public GodRayFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            Effect effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/GodRayFilter");
              _viewportSizeParameter = effect.Parameters["ViewportSize"];
              _parameters0Parameter = effect.Parameters["Parameters0"];
              _parameters1Parameter = effect.Parameters["Parameters1"];
              _intensityParameter = effect.Parameters["Intensity"];
              _numberOfSamplesParameter = effect.Parameters["NumberOfSamples"];
              _sourceTextureParameter = effect.Parameters["SourceTexture"];
              _gBuffer0Parameter = effect.Parameters["GBuffer0"];
              _rayTextureParameter = effect.Parameters["RayTexture"];
              _createMaskPass = effect.CurrentTechnique.Passes["CreateMask"];
              _blurPass = effect.CurrentTechnique.Passes["Blur"];
              _combinePass = effect.CurrentTechnique.Passes["Combine"];

              _downsampleFilter = graphicsService.GetDownsampleFilter();

              Scale = 1;
              LightDirection = new Vector3F(0, -1, 0);
              LightRadius = 0.2f;
              Intensity = new Vector3F(1, 1, 1);
              DownsampleFactor = 4;
              NumberOfSamples = 8;
              NumberOfPasses = 2;
              Softness = 1;
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------
        /// <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);
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="DepthOfFieldFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public DepthOfFieldFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/DepthOfFieldFilter");
            _screenSizeParameter        = _effect.Parameters["ScreenSize"];
            _depthTextureParameter      = _effect.Parameters["DepthTexture"];
            _nearBlurDistanceParameter  = _effect.Parameters["NearBlurDistance"];
            _nearFocusDistanceParameter = _effect.Parameters["NearFocusDistance"];
            _farFocusDistanceParameter  = _effect.Parameters["FarFocusDistance"];
            _farBlurDistanceParameter   = _effect.Parameters["FarBlurDistance"];
            _farParameter                     = _effect.Parameters["Far"];
            _blurTextureParameter             = _effect.Parameters["BlurTexture"];
            _downsampledDepthTextureParameter = _effect.Parameters["DownsampledDepthTexture"];
            _downsampledCocTextureParameter   = _effect.Parameters["DownsampledCocTexture"];
            _offsetsParameter                 = _effect.Parameters["Offsets"];
            _weightsParameter                 = _effect.Parameters["Weights"];
            _sceneTextureParameter            = _effect.Parameters["SceneTexture"];
            _circleOfConfusionPass            = _effect.CurrentTechnique.Passes["CircleOfConfusion"];
            _blurPass         = _effect.CurrentTechnique.Passes["Blur"];
            _depthOfFieldPass = _effect.CurrentTechnique.Passes["DepthOfField"];

            _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

            _cocBlur = new Blur(graphicsService);
            _cocBlur.InitializeBoxBlur(5, false);

            NearBlurDistance  = 2;
            NearFocusDistance = 5;
            FarFocusDistance  = 6;
            FarBlurDistance   = 10;
            _downsampleFactor = 2;
            BlurStrength      = 1;
        }
Ejemplo n.º 6
0
        public GBufferRenderer(IGraphicsService graphicsService, SceneNodeRenderer sceneNodeRenderer, DecalRenderer decalRenderer)
        {
            _clearGBufferRenderer = new ClearGBufferRenderer(graphicsService);
              _sceneNodeRenderer = sceneNodeRenderer;
              _decalRenderer = decalRenderer;

              // This filter is used to downsample the depth buffer (GBuffer0).
              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 8
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="HdrFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public HdrFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/HdrFilter");
            _viewportSizeParameter     = _effect.Parameters["ViewportSize"];
            _bloomThresholdParameter   = _effect.Parameters["BloomThreshold"];
            _middleGrayParameter       = _effect.Parameters["MiddleGray"];
            _minExposureParameter      = _effect.Parameters["MinExposure"];
            _maxExposureParameter      = _effect.Parameters["MaxExposure"];
            _blueShiftColorParameter   = _effect.Parameters["BlueShiftColor"];
            _blueShiftParameter        = _effect.Parameters["BlueShift"];
            _bloomIntensityParameter   = _effect.Parameters["BloomIntensity"];
            _sceneTextureParameter     = _effect.Parameters["SceneTexture"];
            _luminanceTextureParameter = _effect.Parameters["LuminanceTexture"];
            _bloomTextureParameter     = _effect.Parameters["BloomTexture"];
            _brightnessPass            = _effect.CurrentTechnique.Passes["Brightness"];
            _combinePass = _effect.CurrentTechnique.Passes["Combine"];
            _combineWithBlueShiftPass = _effect.CurrentTechnique.Passes["CombineWithBlueShift"];

            BloomIntensity   = 1;
            BloomThreshold   = 0.2f;
            DownsampleFactor = 4;
            MiddleGray       = 0.18f;
            MinExposure      = 0.01f;
            MaxExposure      = 2.0f;

            // The physically based blue shift color is in CIE Yxy: x = 0.3 and y = 0.3.
            // As RGB this is (1.05, 0.97, 1.27). This color should be scaled by a user-defined
            // scale. The scotopic luminance computed in the shader is usually in the range [0, 4].
            // Therefore, we apply a scale factor of 0.25 as a default.
            BlueShiftColor  = new Vector3F(1.05f, 0.97f, 1.27f) * 0.25f;
            BlueShiftCenter = 0.04f;
            BlueShiftRange  = 1;

            _blur = new Blur(graphicsService);
            _blur.InitializeGaussianBlur(7, 7.0f / 3.0f, true);
            _luminance       = new LuminanceFilter(graphicsService);
            _luminanceTarget = graphicsService.RenderTargetPool.Obtain2D(_luminance.DefaultTargetFormat);

            _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

            var defaultTargetFormat = DefaultTargetFormat;

            defaultTargetFormat.SurfaceFormat = SurfaceFormat.Color;
            DefaultTargetFormat = defaultTargetFormat;
        }
Ejemplo n.º 9
0
        public static DownsampleFilter GetDownsampleFilter(this IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            throw new ArgumentNullException("graphicsService");

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

              return instance;
        }
Ejemplo n.º 10
0
        public static DownsampleFilter GetDownsampleFilter(this IGraphicsService graphicsService)
        {
            if (graphicsService == null)
            {
                throw new ArgumentNullException("graphicsService");
            }

            const string Key = "__DownsampleFilter";
            object       obj;

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

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

            return(instance);
        }
Ejemplo n.º 11
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="BloomFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public BloomFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/BloomFilter");
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _bloomThresholdParameter = _effect.Parameters["BloomThreshold"];
              _bloomIntensityParameter = _effect.Parameters["BloomIntensity"];
              _bloomSaturationParameter = _effect.Parameters["BloomSaturation"];
              _sceneTextureParameter = _effect.Parameters["SceneTexture"];
              _bloomTextureParameter = _effect.Parameters["BloomTexture"];
              _brightnessPass = _effect.CurrentTechnique.Passes["Brightness"];
              _combinePass = _effect.CurrentTechnique.Passes["Combine"];

              _blur = new Blur(graphicsService);
              _blur.InitializeGaussianBlur(7, 7.0f / 3.0f, true);

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              Threshold = 0.7f;
              Intensity = 1.5f;
              Saturation = 0.5f;
              DownsampleFactor = 4;
        }
Ejemplo n.º 12
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="BloomFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public BloomFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/BloomFilter");
            _viewportSizeParameter    = _effect.Parameters["ViewportSize"];
            _bloomThresholdParameter  = _effect.Parameters["BloomThreshold"];
            _bloomIntensityParameter  = _effect.Parameters["BloomIntensity"];
            _bloomSaturationParameter = _effect.Parameters["BloomSaturation"];
            _sceneTextureParameter    = _effect.Parameters["SceneTexture"];
            _bloomTextureParameter    = _effect.Parameters["BloomTexture"];
            _brightnessPass           = _effect.CurrentTechnique.Passes["Brightness"];
            _combinePass = _effect.CurrentTechnique.Passes["Combine"];

            _blur = new Blur(graphicsService);
            _blur.InitializeGaussianBlur(7, 7.0f / 3.0f, true);

            _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

            Threshold        = 0.7f;
            Intensity        = 1.5f;
            Saturation       = 0.5f;
            DownsampleFactor = 4;
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="DepthOfFieldFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public DepthOfFieldFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/DepthOfFieldFilter");
              _screenSizeParameter = _effect.Parameters["ScreenSize"];
              _depthTextureParameter = _effect.Parameters["DepthTexture"];
              _nearBlurDistanceParameter = _effect.Parameters["NearBlurDistance"];
              _nearFocusDistanceParameter = _effect.Parameters["NearFocusDistance"];
              _farFocusDistanceParameter = _effect.Parameters["FarFocusDistance"];
              _farBlurDistanceParameter = _effect.Parameters["FarBlurDistance"];
              _farParameter = _effect.Parameters["Far"];
              _blurTextureParameter = _effect.Parameters["BlurTexture"];
              _downsampledDepthTextureParameter = _effect.Parameters["DownsampledDepthTexture"];
              _downsampledCocTextureParameter = _effect.Parameters["DownsampledCocTexture"];
              _offsetsParameter = _effect.Parameters["Offsets"];
              _weightsParameter = _effect.Parameters["Weights"];
              _sceneTextureParameter = _effect.Parameters["SceneTexture"];
              _circleOfConfusionPass = _effect.CurrentTechnique.Passes["CircleOfConfusion"];
              _blurPass = _effect.CurrentTechnique.Passes["Blur"];
              _depthOfFieldPass = _effect.CurrentTechnique.Passes["DepthOfField"];

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              _cocBlur = new Blur(graphicsService);
              _cocBlur.InitializeBoxBlur(5, false);

              NearBlurDistance = 2;
              NearFocusDistance = 5;
              FarFocusDistance = 6;
              FarBlurDistance = 10;
              _downsampleFactor = 2;
              BlurStrength = 1;
        }
Ejemplo n.º 15
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="HdrFilter"/> class.
        /// </summary>
        /// <param name="graphicsService">The graphics service.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="graphicsService"/> is <see langword="null"/>.
        /// </exception>
        public HdrFilter(IGraphicsService graphicsService)
            : base(graphicsService)
        {
            _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/HdrFilter");
              _viewportSizeParameter = _effect.Parameters["ViewportSize"];
              _bloomThresholdParameter = _effect.Parameters["BloomThreshold"];
              _middleGrayParameter = _effect.Parameters["MiddleGray"];
              _minExposureParameter = _effect.Parameters["MinExposure"];
              _maxExposureParameter = _effect.Parameters["MaxExposure"];
              _blueShiftColorParameter = _effect.Parameters["BlueShiftColor"];
              _blueShiftParameter = _effect.Parameters["BlueShift"];
              _bloomIntensityParameter = _effect.Parameters["BloomIntensity"];
              _sceneTextureParameter = _effect.Parameters["SceneTexture"];
              _luminanceTextureParameter = _effect.Parameters["LuminanceTexture"];
              _bloomTextureParameter = _effect.Parameters["BloomTexture"];
              _brightnessPass = _effect.CurrentTechnique.Passes["Brightness"];
              _combinePass = _effect.CurrentTechnique.Passes["Combine"];
              _combineWithBlueShiftPass = _effect.CurrentTechnique.Passes["CombineWithBlueShift"];

              BloomIntensity = 1;
              BloomThreshold = 0.2f;
              DownsampleFactor = 4;
              MiddleGray = 0.18f;
              MinExposure = 0.01f;
              MaxExposure = 2.0f;

              // The physically based blue shift color is in CIE Yxy: x = 0.3 and y = 0.3.
              // As RGB this is (1.05, 0.97, 1.27). This color should be scaled by a user-defined
              // scale. The scotopic luminance computed in the shader is usually in the range [0, 4].
              // Therefore, we apply a scale factor of 0.25 as a default.
              BlueShiftColor = new Vector3F(1.05f, 0.97f, 1.27f) * 0.25f;
              BlueShiftCenter = 0.04f;
              BlueShiftRange = 1;

              _blur = new Blur(graphicsService);
              _blur.InitializeGaussianBlur(7, 7.0f / 3.0f, true);
              _luminance = new LuminanceFilter(graphicsService);
              _luminanceTarget = graphicsService.RenderTargetPool.Obtain2D(_luminance.DefaultTargetFormat);

              _downsampleFilter = PostProcessHelper.GetDownsampleFilter(graphicsService);

              var defaultTargetFormat = DefaultTargetFormat;
              defaultTargetFormat.SurfaceFormat = SurfaceFormat.Color;
              DefaultTargetFormat = defaultTargetFormat;
        }
Ejemplo n.º 16
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);
        }