private void DialogDismissedHandler(IUICommand command) { // Start a scoped batch so we can register to completion event and hide the destination layer _scopeBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); // Start the hide animation to fade out the destination effect ScalarKeyFrameAnimation hideAnimation = _compositor.CreateScalarKeyFrameAnimation(); hideAnimation.InsertKeyFrame(0f, 1f); hideAnimation.InsertKeyFrame(1.0f, 0f); hideAnimation.Duration = TimeSpan.FromMilliseconds(1000); _destinationSprite.StartAnimation("Opacity", hideAnimation); // Use whichever effect is currently selected ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; switch ((EffectTypes)item.Tag) { case EffectTypes.Mask: { CompositionSurfaceBrush brush = ((CompositionEffectBrush)_destinationSprite.Brush).GetSourceParameter("SecondSource") as CompositionSurfaceBrush; Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation(); scaleAnimation.InsertKeyFrame(1f, new Vector2(2.0f, 2.0f)); scaleAnimation.Duration = TimeSpan.FromMilliseconds(1000); brush.StartAnimation("Scale", scaleAnimation); break; } case EffectTypes.VividLight: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; ColorKeyFrameAnimation coloAnimation = _compositor.CreateColorKeyFrameAnimation(); coloAnimation.InsertKeyFrame(1f, Color.FromArgb(255, 100, 100, 100)); coloAnimation.Duration = TimeSpan.FromMilliseconds(1500); brush.StartAnimation("Base.Color", coloAnimation); break; } case EffectTypes.Hue: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; ScalarKeyFrameAnimation rotateAnimation = _compositor.CreateScalarKeyFrameAnimation(); rotateAnimation.InsertKeyFrame(1f, 0f); rotateAnimation.Duration = TimeSpan.FromMilliseconds(1500); brush.StartAnimation("Hue.Angle", rotateAnimation); break; } default: break; } //Scoped batch completed event _scopeBatch.Completed += ScopeBatch_Completed; _scopeBatch.End(); }
private void SetupPropertySetExpression() { var blurAnimator = m_compositor.CreateExpressionAnimation(); blurAnimator.SetReferenceParameter("bluramount", m_blurVisual); blurAnimator.Expression = "bluramount.BlurValue"; m_blurBrush.StartAnimation("Blur.BlurAmount", blurAnimator); var fadeInAnimator = m_compositor.CreateExpressionAnimation(); fadeInAnimator.SetReferenceParameter("fadeInAmount", m_blurVisual); fadeInAnimator.Expression = "fadeInAmount.FadeValue"; m_blurBrush.StartAnimation("mixer.Source1Amount", fadeInAnimator); var fadeOutAnimator = m_compositor.CreateExpressionAnimation(); fadeOutAnimator.SetReferenceParameter("fadeOutAmount", m_blurVisual); fadeOutAnimator.Expression = "1-fadeOutAmount.FadeValue"; m_blurBrush.StartAnimation("mixer.Source2Amount", fadeOutAnimator); }
private void StartBlurAnimation() { ScalarKeyFrameAnimation blurAnimation = _compositor.CreateScalarKeyFrameAnimation(); blurAnimation.InsertKeyFrame(0.0f, 0.0f); blurAnimation.InsertKeyFrame(0.5f, 100.0f); blurAnimation.InsertKeyFrame(1.0f, 0.0f); blurAnimation.Duration = TimeSpan.FromSeconds(4); blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _brush.StartAnimation("Blur.BlurAmount", blurAnimation); }
private void BackgroundImage_ImageChanged(object sender, RoutedEventArgs e) { if (_crossFadeBatch == null) { TimeSpan duration = TimeSpan.FromMilliseconds(1000); // Create the animations for cross-fading ScalarKeyFrameAnimation fadeInAnimation = _compositor.CreateScalarKeyFrameAnimation(); fadeInAnimation.InsertKeyFrame(0, 0); fadeInAnimation.InsertKeyFrame(1, 1); fadeInAnimation.Duration = duration; ScalarKeyFrameAnimation fadeOutAnimation = _compositor.CreateScalarKeyFrameAnimation(); fadeOutAnimation.InsertKeyFrame(0, 1); fadeOutAnimation.InsertKeyFrame(1, 0); fadeOutAnimation.Duration = duration; // Create a batch object so we can cleanup when the cross-fade completes. _crossFadeBatch = _compositor.CreateScopedBatch(CompositionBatchTypes.Animation); // Set the sources _crossFadeBrush.SetSourceParameter("ImageSource", BackgroundImage.SurfaceBrush); _crossFadeBrush.SetSourceParameter("ImageSource2", _previousSurfaceBrush); // Animate the source amounts to fade between _crossFadeBrush.StartAnimation("CrossFade.Source1Amount", fadeInAnimation); _crossFadeBrush.StartAnimation("CrossFade.Source2Amount", fadeOutAnimation); // Update the image to use the cross fade brush BackgroundImage.Brush = _crossFadeBrush; _crossFadeBatch.Completed += Batch_CrossFadeCompleted; _crossFadeBatch.End(); } // Unhook the handler BackgroundImage.ImageOpened -= BackgroundImage_ImageChanged; }
/// <summary> /// Animates the effect brush property from the given starting value to the given ending /// value for the given duration. The default easing funciton is used. /// </summary> /// <param name="start">Starting value for the effect brush property.</param> /// <param name="end">The ending or target value for the effect brush property.</param> /// <param name="duration">Desired length of the animation.</param> public void Animate(float start, float end, double duration) { if (_brush != null && !String.IsNullOrEmpty(AnimatablePropertyName)) { // Create our animation. var compositor = _brush.Compositor; var animation = compositor.CreateScalarKeyFrameAnimation(); animation.InsertKeyFrame(0.0f, start); animation.InsertKeyFrame(1.0f, end); animation.Duration = TimeSpan.FromSeconds(duration); // Like with directly changing the effect property, the full effect name and effect // property name are needed to set an animation. _brush.StartAnimation(EffectName + "." + AnimatablePropertyName, animation); } }
private void ChangeBlurColor(Color newColor) { lastBlurColor = blurColor; blurColor = newColor; if (IsGlassOn) { effectBrush.Properties.InsertColor("NewColor.Color", newColor); ColorKeyFrameAnimation colorAnimation = compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0.0f, lastBlurColor); colorAnimation.InsertKeyFrame(1.0f, blurColor); colorAnimation.Duration = TimeSpan.FromSeconds(5); effectBrush.StartAnimation("NewColor.Color", colorAnimation); } else { TurnOnGlass(); } }
private void AnimateEffect(CompositionEffectBrush effectBrush) { // Create a scalar keyframe animation (since the Angle property // is just a single float). Additionally we don't want any easing // for our animation, so we create a simple linear easing function. var animation = _compositor.CreateScalarKeyFrameAnimation(); var easing = _compositor.CreateLinearEasingFunction(); // The Angle property in a HueRotation effect has a range of 0 - 2 * Pi, so // that's what we'll animate between. Make sure we set our easing function. animation.InsertKeyFrame(0.0f, 0.0f); animation.InsertKeyFrame(1.0f, (float)(2.0 * Math.PI), easing); // This animation will go on forever and one pass will take about 4 seconds. animation.IterationBehavior = AnimationIterationBehavior.Forever; animation.Duration = TimeSpan.FromMilliseconds(4000); // Start the animation using the same name that we specified when compiling the // effect above when creating our effect factory. effectBrush.StartAnimation("hueEffect.Angle", animation); }
private void EffectButton_Click(object sender, RoutedEventArgs e) { if (EffectButton.IsChecked == true) { // Create and start an animation that goes on forever. var easing = _compositor.CreateLinearEasingFunction(); var animation = _compositor.CreateScalarKeyFrameAnimation(); animation.InsertKeyFrame(0.0f, 0.0f); animation.InsertKeyFrame(1.0f, 2.0f * (float)Math.PI, easing); animation.Duration = TimeSpan.FromMilliseconds(5000); animation.IterationBehavior = AnimationIterationBehavior.Forever; _effectBrush.StartAnimation("HueRotation.Angle", animation); } else { // Settings the value directly will stop any animations that were running // on that property. _effectBrush.Properties.InsertScalar("HueRotation.Angle", 0.0f); } }
private async void CreateImageAndLights(Vector2 sizeLightBounds) { // // Image and effect setup // // Create the effect graph. We will combine the desaturated image with two diffuse lights IGraphicsEffect graphicsEffect = new CompositeEffect() { Mode = Microsoft.Graphics.Canvas.CanvasComposite.Add, Sources = { new SaturationEffect() { Saturation = 0, Source = new CompositionEffectSourceParameter("ImageSource") }, new PointDiffuseEffect() { Name = "Light1", DiffuseAmount = 1f, Source = new CompositionEffectSourceParameter("NormalMap"), }, new PointDiffuseEffect() { Name = "Light2", DiffuseAmount = 1f, Source = new CompositionEffectSourceParameter("NormalMap"), }, } }; // Create the normal map. For this sample, we want a flat surface with no bumps CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/NowPlaying/NormalMap.jpg")); CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(normalMap); surfaceBrush.Stretch = CompositionStretch.Fill; // Create the effect factory, we're going to animate the light positions and colors CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Light1.LightPosition", "Light1.LightColor", "Light2.LightPosition", "Light2.LightColor", }); // Create the effect brush and bind the normal map CompositionEffectBrush brush = effectFactory.CreateBrush(); brush.SetSourceParameter("NormalMap", surfaceBrush); // Update the CompositionImage to use the custom effect brush ArtistImage.Brush = brush; // // Animation setup // // Setup the first light's position, top and to the left in general LinearEasingFunction linear = _compositor.CreateLinearEasingFunction(); Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightPosition", positionAnimation); // Setup the first light's color animation, cycling through some brighter tones ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.Orange); colorAnimation.InsertKeyFrame(.2f, Colors.Orange); colorAnimation.InsertKeyFrame(.3f, Colors.Red); colorAnimation.InsertKeyFrame(.5f, Colors.Red); colorAnimation.InsertKeyFrame(.6f, Colors.Yellow); colorAnimation.InsertKeyFrame(.8f, Colors.Yellow); colorAnimation.InsertKeyFrame(.9f, Colors.Orange); colorAnimation.InsertKeyFrame(1f, Colors.Orange); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightColor", colorAnimation); // Setup the second light's position, down and to the right in general positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightPosition", positionAnimation); // Setup the second light's color animation, cycling through some darker tones colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.Blue); colorAnimation.InsertKeyFrame(.2f, Colors.Blue); colorAnimation.InsertKeyFrame(.3f, Colors.DarkGreen); colorAnimation.InsertKeyFrame(.5f, Colors.DarkGreen); colorAnimation.InsertKeyFrame(.6f, Colors.DarkBlue); colorAnimation.InsertKeyFrame(.8f, Colors.DarkBlue); colorAnimation.InsertKeyFrame(.9f, Colors.Blue); colorAnimation.InsertKeyFrame(1f, Colors.Blue); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightColor", colorAnimation); }
private void BlurTheImage_PointerEntered(object sender, PointerRoutedEventArgs e) { _springAnimation.FinalValue = 100f; effectBrush.StartAnimation("Blur.BlurAmount", _springAnimation); }
private async void ThumbnailList_ItemClick(object sender, ItemClickEventArgs e) { Thumbnail thumbnail = (Thumbnail)e.ClickedItem; // If we're in the middle of an animation, cancel it now if (_scopeBatch != null) { CleanupScopeBatch(); } // We're starting our transition, show the destination sprite _destinationSprite.IsVisible = true; // Animate from transparent to fully opaque ScalarKeyFrameAnimation showAnimation = _compositor.CreateScalarKeyFrameAnimation(); showAnimation.InsertKeyFrame(0f, 0f); showAnimation.InsertKeyFrame(1f, 1f); showAnimation.Duration = TimeSpan.FromMilliseconds(1500); _destinationSprite.StartAnimation("Opacity", showAnimation); // Use whichever effect is currently selected ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; switch ((EffectTypes)item.Tag) { case EffectTypes.Mask: { CompositionSurfaceBrush brush = ((CompositionEffectBrush)_destinationSprite.Brush).GetSourceParameter("SecondSource") as CompositionSurfaceBrush; Vector2KeyFrameAnimation scaleAnimation = _compositor.CreateVector2KeyFrameAnimation(); scaleAnimation.InsertKeyFrame(0f, new Vector2(1.25f, 1.25f)); scaleAnimation.InsertKeyFrame(1f, new Vector2(0f, 0f)); scaleAnimation.Duration = TimeSpan.FromMilliseconds(2000); brush.StartAnimation("Scale", scaleAnimation); break; } case EffectTypes.VividLight: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; ColorKeyFrameAnimation coloAnimation = _compositor.CreateColorKeyFrameAnimation(); coloAnimation.InsertKeyFrame(0f, Color.FromArgb(255, 255, 255, 255)); coloAnimation.InsertKeyFrame(0f, Color.FromArgb(255, 30, 30, 30)); coloAnimation.Duration = TimeSpan.FromMilliseconds(4000); brush.StartAnimation("Base.Color", coloAnimation); break; } case EffectTypes.Hue: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; ScalarKeyFrameAnimation rotateAnimation = _compositor.CreateScalarKeyFrameAnimation(); rotateAnimation.InsertKeyFrame(0f, 0f); rotateAnimation.InsertKeyFrame(1f, (float)Math.PI); rotateAnimation.Duration = TimeSpan.FromMilliseconds(4000); brush.StartAnimation("Hue.Angle", rotateAnimation); break; } case EffectTypes.RainbowBlur: { CompositionEffectBrush brush = (CompositionEffectBrush)_destinationSprite.Brush; ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0, Colors.Red); colorAnimation.InsertKeyFrame(.16f, Colors.Orange); colorAnimation.InsertKeyFrame(.32f, Colors.Yellow); colorAnimation.InsertKeyFrame(.48f, Colors.Green); colorAnimation.InsertKeyFrame(.64f, Colors.Blue); colorAnimation.InsertKeyFrame(.80f, Colors.Purple); colorAnimation.InsertKeyFrame(1, Colors.Red); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; colorAnimation.Duration = TimeSpan.FromMilliseconds(5000); brush.StartAnimation("Base.Color", colorAnimation); break; } default: break; } // Create the dialog var messageDialog = new MessageDialog(thumbnail.Name); messageDialog.Commands.Add(new UICommand("Close", new UICommandInvokedHandler(DialogDismissedHandler))); // Show the message dialog await messageDialog.ShowAsync(); }
private void CreateImageAndLights(Vector2 sizeLightBounds) { // // Image and effect setup // // Create the effect graph. We will combine the desaturated image with two diffuse lights IGraphicsEffect graphicsEffect = new CompositeEffect() { Mode = Microsoft.Graphics.Canvas.CanvasComposite.Add, Sources = { new SaturationEffect() { Saturation = 0, Source = new CompositionEffectSourceParameter("ImageSource") }, new PointDiffuseEffect() { Name = "Light1", DiffuseAmount = 1f, }, new PointDiffuseEffect() { Name = "Light2", DiffuseAmount = 1f, }, } }; // Create the effect factory, we're going to animate the light positions and colors CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Light1.LightPosition", "Light1.LightColor", "Light2.LightPosition", "Light2.LightColor", }); // Create the effect brush and bind the normal map CompositionEffectBrush brush = effectFactory.CreateBrush(); // Update the CompositionImage to use the custom effect brush ArtistImage.Brush = brush; // // Animation setup // // Setup the first light's position, top and to the left in general LinearEasingFunction linear = _compositor.CreateLinearEasingFunction(); Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightPosition", positionAnimation); // Setup the first light's color animation, cycling through some brighter tones ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.MidnightBlue); colorAnimation.InsertKeyFrame(.2f, Colors.Indigo); colorAnimation.InsertKeyFrame(.3f, Colors.RoyalBlue); colorAnimation.InsertKeyFrame(.5f, Colors.CornflowerBlue); colorAnimation.InsertKeyFrame(.6f, Colors.Thistle); colorAnimation.InsertKeyFrame(.8f, Colors.CornflowerBlue); colorAnimation.InsertKeyFrame(.9f, Colors.RoyalBlue); colorAnimation.InsertKeyFrame(1f, Colors.Indigo); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightColor", colorAnimation); // Setup the second light's position, down and to the right in general positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightPosition", positionAnimation); // Setup the second light's color animation, cycling through some darker tones colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.Firebrick); colorAnimation.InsertKeyFrame(.2f, Colors.DarkGoldenrod); colorAnimation.InsertKeyFrame(.3f, Colors.Chartreuse); colorAnimation.InsertKeyFrame(.5f, Colors.ForestGreen); colorAnimation.InsertKeyFrame(.6f, Colors.DarkTurquoise); colorAnimation.InsertKeyFrame(.8f, Colors.MidnightBlue); colorAnimation.InsertKeyFrame(.9f, Colors.DarkViolet); colorAnimation.InsertKeyFrame(1f, Colors.DarkSlateGray); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightColor", colorAnimation); }
private void InitializeFrostedGlass(UIElement glassHost) { //https://msdn.microsoft.com/en-us/windows/uwp/graphics/using-the-visual-layer-with-xaml CleanUp(); // Create a glass effect, requires Win2D NuGet package glassEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 10.0f, //original value: 15.0f BorderMode = EffectBorderMode.Hard, Source = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 0.5f, Source2Amount = 0.5f, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Name = "NewColor", Color = blurColor } } }; // Create an instance of the effect and set its source to a CompositionBackdropBrush effectFactory = compositor.CreateEffectFactory(glassEffect, new[] { "Blur.BlurAmount", "NewColor.Color" }); effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdropBrush", backdropBrush); glassVisual.Brush = effectBrush; if (Animate) { // https://blogs.windows.com/buildingapps/2016/09/12/creating-beautiful-effects-for-uwp/ ColorKeyFrameAnimation colorAnimation = compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0.0f, lastBlurColor); colorAnimation.InsertKeyFrame(1.0f, blurColor); colorAnimation.Duration = TimeSpan.FromSeconds(2); effectBrush.StartAnimation("NewColor.Color", colorAnimation); //ScalarKeyFrameAnimation blurAnimation = compositor.CreateScalarKeyFrameAnimation(); //blurAnimation.InsertKeyFrame(0.0f, 0.0f); //blurAnimation.InsertKeyFrame(0.5f, 100.0f); //blurAnimation.InsertKeyFrame(1.0f, 0.0f); //blurAnimation.Duration = TimeSpan.FromSeconds(4); //blurAnimation.StopBehavior = AnimationStopBehavior.SetToFinalValue; //effectBrush.StartAnimation("Blur.BlurAmount", blurAnimation); } // Add the blur as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(glassHost, glassVisual); // Make sure size of glass host and glass visual always stay in sync var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); glassVisual.StartAnimation("Size", bindSizeAnimation); SetValue(IsGlassOnProperty, true); }
private void TurnOffGlassInternal() { if (glassVisual != null) { CleanUp(); // Create a glass effect, requires Win2D NuGet package glassEffect = new GaussianBlurEffect { Name = "Blur", BlurAmount = 0.0f, BorderMode = EffectBorderMode.Hard, Source = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 0.5f, Source2Amount = 0.5f, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Name = "NewColor", Color = blurColor } } }; // Create an instance of the effect and set its source to a CompositionBackdropBrush effectFactory = compositor.CreateEffectFactory(glassEffect, new[] { "Blur.BlurAmount", "NewColor.Color" }); effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdropBrush", backdropBrush); // Create a Visual to contain the frosted glass effect glassVisual = compositor.CreateSpriteVisual(); glassVisual.Brush = effectBrush; if (Animate) { // https://blogs.windows.com/buildingapps/2016/09/12/creating-beautiful-effects-for-uwp/ ColorKeyFrameAnimation colorAnimation = compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0.0f, blurColor); colorAnimation.InsertKeyFrame(1.0f, Colors.Transparent); colorAnimation.Duration = TimeSpan.FromSeconds(2); effectBrush.StartAnimation("NewColor.Color", colorAnimation); } // Make sure size of glass host and glass visual always stay in sync var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); glassVisual.StartAnimation("Size", bindSizeAnimation); // Add the blur as a child of the host in the visual tree ElementCompositionPreview.SetElementChildVisual(GlassHost, glassVisual); //glassVisual.Dispose(); //glassVisual = null; } SetValue(IsGlassOnProperty, false); //ElementCompositionPreview.SetElementChildVisual(GlassHost, null); //turn off the glass }
private void SetImageEffect(CompositionImage image) { // Create the effect brush and bind the normal map CompositionEffectBrush brush = _effectFactory.CreateBrush(); ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem; switch ((LightingTypes)item.Tag) { case LightingTypes.SpotLightSpecular: case LightingTypes.PointSpecular: brush.StartAnimation("Light1.LightPosition", _lightPositionAnimation); brush.StartAnimation("Light1.LightColor", _lightColorAnimation); brush.StartAnimation("Light2.LightPosition", _lightPositionAnimation); brush.StartAnimation("Light2.LightColor", _lightColorAnimation); brush.SetSourceParameter("NormalMap", _circleNormalsBrush); break; case LightingTypes.DistantDiffuse: brush.SetSourceParameter("NormalMap", _circleNormalsBrush); brush.StartAnimation("Light1.Azimuth", _lightAzimuthAnimation); brush.StartAnimation("Light1.Elevation", _lightElevationAnimation); break; case LightingTypes.DistantSpecular: brush.SetSourceParameter("NormalMap", _circleNormalsBrush); brush.StartAnimation("Light1.Azimuth", _lightAzimuthAnimation); brush.StartAnimation("Light1.Elevation", _lightElevationAnimation); brush.StartAnimation("Light2.Azimuth", _lightAzimuthAnimation); brush.StartAnimation("Light2.Elevation", _lightElevationAnimation); break; default: brush.StartAnimation("Light1.LightPosition", _lightPositionAnimation); brush.StartAnimation("Light1.LightColor", _lightColorAnimation); brush.SetSourceParameter("NormalMap", _flatNormalsBrush); break; } // Update the CompositionImage to use the custom effect brush image.Brush = brush; }