Beispiel #1
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;
        }
Beispiel #2
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;
        }