public void SetLightingEffect(int lightingEffect) { switch (lightingEffect) { case (int)LightingEffect.PointSpecular: _effectGraph = _pointSpecularEffect; break; case (int)LightingEffect.SpotSpecular: _effectGraph = _spotSpecularEffect; break; case (int)LightingEffect.DistantSpecular: _effectGraph = _distantSpecularEffect; break; case (int)LightingEffect.PointDiffuse: _effectGraph = _pointDiffuseEffect; break; case (int)LightingEffect.SpotDiffuse: _effectGraph = _spotDiffuseEffect; break; case (int)LightingEffect.DistantDiffuse: _effectGraph = _distantDiffuseEffect; break; default: break; } }
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); } }
/// <summary> /// Gets the input object for an effect. /// </summary> /// <param name="device">The device for which to get the input.</param> IDisposable IImageInternal.GetImageObject(EngineDevice device) { if (device.IsUsingFallbackMethodFor2D) { return(null); } D2D.Effect effect = m_loadedEffects[device.DeviceIndex]; if (effect == null) { // Create the effect effect = BuildEffect(device); // Set input values for (int loop = 0; loop < m_effectInputs.Length; loop++) { using (D2D.Image actInput = m_effectInputs[loop].GetImageObject(device) as D2D.Image) { effect.SetInput(loop, actInput, new SharpDX.Mathematics.Interop.RawBool(false)); } } // Store loaded effect m_loadedEffects[device.DeviceIndex] = effect; } return(effect.Output); }
public Effect AddEffect(Guid pEffect) { var e = new SharpDX.Direct2D1.Effect(_context, pEffect); _effects.Add(e); return(this); }
private void UpdateEffectGraph() { _effectGraph = CreateEffectGraph( _formatConverter, Scale, BlurDeviation ); }
/// <summary> /// Unloads all resources loaded on the given device. /// </summary> /// <param name="engineDevice">The device for which to unload the resource.</param> internal override void UnloadResources(EngineDevice engineDevice) { D2D.Effect actEffect = m_loadedEffects[engineDevice.DeviceIndex]; if (actEffect != null) { GraphicsHelper.DisposeObject(actEffect); m_loadedEffects[engineDevice.DeviceIndex] = null; } }
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); }
/// <summary> /// Push a new effect. /// </summary> /// <param name="guid">GUID of the effect.</param> /// <returns>EffectChain.</returns> public EffectChain PushEffect(Guid guid) { var effect = new D2D.Effect(this.DeviceContext, guid); if (this.Effects.Count != 0) { effect.SetInputEffect(0, this.Effects.Last(), false); } this.Effects.Add(effect); this.CompositeEffect.SetInputEffect(0, effect, false); return(this); }
private void CreateEffectGraph(SharpDX.WIC.FormatConverter formatConverter) { // Setup local variables var d2dDevice = _deviceManager.DeviceDirect2D; var d2dContext = _deviceManager.ContextDirect2D; // Effect 1 : BitmapSource - take decoded image data and get a BitmapSource from it bitmapSourceEffect = new SharpDX.Direct2D1.Effects.BitmapSource(d2dContext); bitmapSourceEffect.WicBitmapSource = formatConverter; bitmapSourceEffect.Cached = true; // Because the image will not be changing, we should cache the effect for performance reasons. // Effect 2 : PointSpecular _deviceManager.FactoryDirect2D.RegisterEffect <WaveEffect>(); _waveEffect = new Effect <WaveEffect>(_deviceManager.ContextDirect2D); _waveEffect.SetInputEffect(0, bitmapSourceEffect); }
private void CreateEffectGraph(SharpDX.WIC.FormatConverter formatConverter) { // Setup local variables var d2dDevice = _deviceManager.DeviceDirect2D; var d2dContext = _deviceManager.ContextDirect2D; // Effect 1 : BitmapSource - take decoded image data and get a BitmapSource from it bitmapSource = new SharpDX.Direct2D1.Effects.BitmapSource(d2dContext); bitmapSource.WicBitmapSource = formatConverter; bitmapSource.Cached = true; // Because the image will not be changing, we should cache the effect for performance reasons. // Effect 2 : PointSpecular _deviceManager.FactoryDirect2D.RegisterEffect<RippleEffect>(); _rippleEffect = new Effect<RippleEffect>(_deviceManager.ContextDirect2D); _rippleEffect.SetInputEffect(0, bitmapSource); }
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); }
/// <summary> /// Sets the input by using the output of a given effect. /// </summary> /// <param name="index">Index of the input</param> /// <param name="effect">Effect output to use as input</param> /// <param name="invalidate">To invalidate</param> public void SetInputEffect(int index, Effect effect, bool invalidate = true) { using (var output = effect.Output) SetInput(index, output, invalidate); }