//-------------------------------------------------------------- #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); }
//-------------------------------------------------------------- #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; }
//-------------------------------------------------------------- #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); }