private void DrawInternal(DeviceContext pContext, BitmapResource pBitmap, Vector2 pPosition, Size pSize) { _effects[0].SetInput(0, pBitmap.DirectXBitmap, false); float widthFactor; float heightFactor; if (_useTiledScaling) { widthFactor = Game.ActiveCamera.Zoom; heightFactor = Game.ActiveCamera.Zoom; } else { widthFactor = pSize.Width / pBitmap.Width; heightFactor = pSize.Height / pBitmap.Height; } var scale = new SharpDX.Direct2D1.Effect(_context, Scale); scale.SetValue(0, new RawVector2(widthFactor, heightFactor)); scale.SetInput(0, _effects[_effects.Count - 1].Output, false); if (pBitmap.Source.HasValue) { var r = pBitmap.Source.Value; var source = new RawRectangleF(r.Left, r.Top, r.Left + pSize.Width, r.Top + pSize.Height); pContext.DrawImage(scale.Output, pPosition, source, InterpolationMode.Linear, CompositeMode.SourceOver); } else { pContext.DrawImage(_effects[_effects.Count - 1].Output, pPosition); } }
private void Update() { float delta = clock.ElapsedMilliseconds / 1000.0f; if (!clock.IsRunning || delta > 4) { delta = 4; clock.Stop(); } _rippleEffect.SetValue((int)RippleProperties.Frequency, 140.0f - delta * 30.0f); _rippleEffect.SetValue((int)RippleProperties.Phase, -delta * 20.0f); _rippleEffect.SetValue((int)RippleProperties.Amplitude, 60.0f - delta * 15.0f); _rippleEffect.SetValue((int)RippleProperties.Spread, 0.01f + delta / 10.0f); }
public Effect AddTile(BitmapResource pResource) { var e = new SharpDX.Direct2D1.Effect(_context, Tile); var rect = pResource.Source.HasValue ? pResource.Source.Value : new Rectangle(0, 0, pResource.Width, pResource.Height); e.SetValue(0, rect); _effects.Add(e); _useTiledScaling = true; return(this); }
private void Update() { float delta = clock.ElapsedMilliseconds / 1000.0f; _waveEffect.SetValue((int)WaveProperties.WaveOffset, delta); }
protected SharpDX.Direct2D1.Image Output(DeviceContext rDc) { D2DBitmap ntdx = null; try { ntdx = D2DBitmap.FromWicBitmap(rDc, _Pelete); } catch (Exception e) { MessageBox.Show(e.ToString()); } Image result1; var blEf = new SharpDX.Direct2D1.Effect(rDc, Effect.Opacity); blEf.SetInput(0, ntdx, new RawBool()); blEf.SetValue(0, Opacity); result1 = blEf.Output; blEf.Dispose(); if (size_changed) { var tfEf = new SharpDX.Direct2D1.Effects.AffineTransform2D(rDc); tfEf.SetInput(0, result1, new RawBool()); result1.Dispose(); var x_rate = _Size.Width / (double)_Pelete.Size.Width; var y_rate = _Size.Height / (double)_Pelete.Size.Height; tfEf.TransformMatrix = new RawMatrix3x2((float)x_rate, 0f, 0f, (float)y_rate, 0f, 0f); result1 = tfEf.Output; tfEf.Dispose(); } if (Orientation != 1.0f) { var tfEf1 = new SharpDX.Direct2D1.Effects.AffineTransform2D(rDc); tfEf1.SetInput(0, result1, new RawBool()); result1.Dispose(); var mr32 = Matrix3x2.CreateRotation((float)Orientation, new Vector2(RotationPoint.X, RotationPoint.Y)); tfEf1.TransformMatrix = new RawMatrix3x2(mr32.M11, mr32.M12, mr32.M21, mr32.M22, mr32.M31, mr32.M32); result1 = tfEf1.Output; tfEf1.Dispose(); } if (this.Saturation != 1f) { var stEf = new SharpDX.Direct2D1.Effects.Saturation(rDc); stEf.SetInput(0, result1, new RawBool()); result1.Dispose(); stEf.Value = Saturation; result1 = stEf.Output; stEf.Dispose(); } if (this.Brightness != 0.5f) { var btEf = new SharpDX.Direct2D1.Effects.Brightness(rDc); btEf.SetInput(0, result1, new RawBool()); result1.Dispose(); btEf.BlackPoint = new RawVector2(1.0f - Brightness, Brightness); // btEf.WhitePoint =; result1 = btEf.Output; btEf.Dispose(); } ntdx.Dispose(); return(result1); }