/// <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; }
/// <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; }
/// <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 Vector3(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; }
/// <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; }
/// <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.NextQuaternion().Rotate(Vector3.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)(Matrix.CreateRotationZ(ConstantsF.TwoPi * i / vectors.Length + random.NextFloat(-jitterAngle, jitterAngle)) * new Vector3(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); }