private ICanvasImage CreateArithmeticComposite() { // Combine two tiger images, the second one slightly rotated. var arithmeticEffect = new ArithmeticCompositeEffect { Source1 = bitmapTiger, Source2 = new Transform2DEffect { Source = bitmapTiger, TransformMatrix = Matrix3x2.CreateRotation(0.5f) } }; // Animate the effect by changing parameters using sine waves of different frequencies. animationFunction = elapsedTime => { arithmeticEffect.MultiplyAmount = (float)Math.Sin(elapsedTime * 23) * Math.Max(0, (float)Math.Sin(elapsedTime * 0.7)); arithmeticEffect.Source1Amount = (float)Math.Sin(elapsedTime * 1.1); arithmeticEffect.Source2Amount = (float)Math.Sin(elapsedTime * 1.7); arithmeticEffect.Offset = (float)Math.Sin(elapsedTime * 0.2) / 2 + 0.25f; }; return(arithmeticEffect); }
private CompositionBrush CreateNormalMapBrush(Compositor compositor, ICompositionSurface normalMapImage, ICompositionSurface colorMapImage) { var colorMapParameter = new CompositionEffectSourceParameter("ColorMap"); var normalMapParameter = new CompositionEffectSourceParameter("NormalMap"); var compositeEffect = new ArithmeticCompositeEffect() { Source1 = colorMapParameter, Source2 = new SceneLightingEffect() { NormalMapSource = normalMapParameter } }; var normalMapBrush = compositor.CreateSurfaceBrush(normalMapImage); var colorMapBrush = compositor.CreateSurfaceBrush(colorMapImage); normalMapBrush.Stretch = CompositionStretch.Fill; colorMapBrush.Stretch = CompositionStretch.Fill; var brush = compositor.CreateEffectFactory(compositeEffect).CreateBrush(); brush.SetSourceParameter(colorMapParameter.Name, colorMapBrush); brush.SetSourceParameter(normalMapParameter.Name, normalMapBrush); return(brush); }
private CompositionEffectBrush CreateBlurEffect(Compositor compositor) { var blendEffect0 = new ArithmeticCompositeEffect() { MultiplyAmount = 0, Source1Amount = _backdropFactor, Source2Amount = _tintColorFactor, Source1 = new CompositionEffectSourceParameter(SOURCE_KEY), Source2 = new ColorSourceEffect() { Color = _tintColor } }; var effect = new GaussianBlurEffect() { BlurAmount = _blurAmount, BorderMode = EffectBorderMode.Soft, Source = blendEffect0 }; var effectFactory = compositor.CreateEffectFactory(effect); var effectBrush = effectFactory.CreateBrush(); return(effectBrush); }
public void ArithmeticCompositeEffectCustomizations() { var effect = new ArithmeticCompositeEffect(); // Verify defaults. Assert.AreEqual(1.0f, effect.MultiplyAmount); Assert.AreEqual(0.0f, effect.Source1Amount); Assert.AreEqual(0.0f, effect.Source2Amount); Assert.AreEqual(0.0f, effect.Offset); Assert.IsTrue(((float[])effect.Properties[0]).SequenceEqual(new float[] { 1, 0, 0, 0 })); // Changing the boxed value should change all the associated properties. effect.Properties[0] = new float[] { 2, 3, 4, 5 }; Assert.AreEqual(2.0f, effect.MultiplyAmount); Assert.AreEqual(3.0f, effect.Source1Amount); Assert.AreEqual(4.0f, effect.Source2Amount); Assert.AreEqual(5.0f, effect.Offset); // Change properties one at a time, and verify that the boxed value changes to match. effect.MultiplyAmount = 23; Assert.IsTrue(((float[])effect.Properties[0]).SequenceEqual(new float[] { 23, 3, 4, 5 })); effect.Source1Amount = 42; Assert.IsTrue(((float[])effect.Properties[0]).SequenceEqual(new float[] { 23, 42, 4, 5 })); effect.Source2Amount = -1; Assert.IsTrue(((float[])effect.Properties[0]).SequenceEqual(new float[] { 23, 42, -1, 5 })); effect.Offset = 100; Assert.IsTrue(((float[])effect.Properties[0]).SequenceEqual(new float[] { 23, 42, -1, 100 })); }
#pragma warning disable 1998 public override async Task <CompositionDrawingSurface> LoadResources() { // Create the effect template var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("EffectSource"), Source2Amount = 0, MultiplyAmount = 0 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); // Create the animations _animationDecreasing = _compositor.CreateScalarKeyFrameAnimation(); _animationDecreasing.InsertKeyFrame(1f, 0f); _animationDecreasing.Duration = TimeSpan.FromMilliseconds(1000); _animationDecreasing.IterationBehavior = AnimationIterationBehavior.Count; _animationDecreasing.IterationCount = 1; _animationIncreasing = _compositor.CreateScalarKeyFrameAnimation(); _animationIncreasing.InsertKeyFrame(1f, 1f); _animationIncreasing.Duration = TimeSpan.FromMilliseconds(1000); _animationIncreasing.IterationBehavior = AnimationIterationBehavior.Count; _animationIncreasing.IterationCount = 1; _loadEffectHandler = ApplyBlurEffect; return(null); }
public void ArithmeticCompositeEffectCustomizations() { var effect = new ArithmeticCompositeEffect(); // Verify defaults. Assert.AreEqual(1.0f, effect.MultiplyAmount); Assert.AreEqual(0.0f, effect.Source1Amount); Assert.AreEqual(0.0f, effect.Source2Amount); Assert.AreEqual(0.0f, effect.Offset); Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 1, 0, 0, 0 })); // Change properties one at a time, and verify that the boxed value changes to match. effect.MultiplyAmount = 23; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 0, 0, 0 })); effect.Source1Amount = 42; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, 0, 0 })); effect.Source2Amount = -1; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, -1, 0 })); effect.Offset = 100; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, -1, 100 })); }
public CompositionBrush Build( Color luminosityColor) { var adjustedTintOpacity = Math.Clamp(TintOpacity, 0, 1); adjustedTintOpacity = 0.3f + 0.7f * adjustedTintOpacity; IGraphicsEffectSource backDropEffectSource = new CompositionEffectSourceParameter("Backdrop"); var luminosityColorEffect = new ColorSourceEffect() { Name = "LuminosityColor", Color = luminosityColor }; var graphicsEffect = new ArithmeticCompositeEffect { Source1 = backDropEffectSource, Source2 = luminosityColorEffect, MultiplyAmount = 0, Source1Amount = 1 - adjustedTintOpacity, Source2Amount = adjustedTintOpacity, Offset = 0 }; //IGraphicsEffectSource noiseEffectSource = new CompositionEffectSourceParameter("Noise"); //var noiseBorderEffect = new BorderEffect() //{ // ExtendX = CanvasEdgeBehavior.Wrap, // ExtendY = CanvasEdgeBehavior.Wrap, // Source = noiseEffectSource, //}; //var noiseOpacityEffect = new OpacityEffect() //{ // Name = "NoiseOpacity", // Opacity = 0.5f, // Source = noiseBorderEffect, //}; //var finalEffect = new CrossFadeEffect() //{ // Name = "FadeInOut", // Source1 = graphicsEffect, // Source2 = noiseOpacityEffect //}; var effectFactory = Window.Current.Compositor.CreateEffectFactory(graphicsEffect); CompositionEffectBrush brush = effectFactory.CreateBrush(); var hostBackdropBrush = Window.Current.Compositor.CreateHostBackdropBrush(); brush.SetSourceParameter("Backdrop", hostBackdropBrush); return(brush); }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .25f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Assets/NormalMapsAndMasks/conemap.jpg")); // Create the animations float sweep = (float)Math.PI / 10f; float fullCircle = (float)Math.PI * -2f; _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.1f, fullCircle); _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep); _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep); _enterAnimation.InsertKeyFrame(1.0f, fullCircle); _enterAnimation.Duration = TimeSpan.FromMilliseconds(4500); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, 0f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; var propsNode = ExpressionValues.Reference.CreatePropertySetReference("props"); var propsCenterPointOffset = propsNode.GetVector2Property("CenterPointOffset"); var propsRotation = propsNode.GetScalarProperty("Rotation"); var propsScale = propsNode.GetScalarProperty("Scale"); _transformExpressionNode = EF.CreateTranslation(-propsCenterPointOffset) * EF.Matrix3x2(EF.Cos(propsRotation) * propsScale, EF.Sin(propsRotation), -EF.Sin(propsRotation), EF.Cos(propsRotation) * propsScale, 0, 0) * EF.CreateTranslation(propsCenterPointOffset + propsNode.GetVector2Property("Translate")); return(null); }
public void LinkLayerEffects(Layer nextLayer) { IGraphicsEffect source = _inputEffect; _chainedEffect = null; // Link the effect chain foreach (var effect in Effects) { if (effect.Enabled) { effect.GraphicsEffect.GetType().GetProperties().FirstOrDefault(x => x.Name == "Source").SetValue(effect.GraphicsEffect, source); source = effect.GraphicsEffect; _chainedEffect = effect.GraphicsEffect; } } if (nextLayer != null) { IGraphicsEffect layerEffect = EffectRoot; IGraphicsEffect blendEffect; blendEffect = Helpers.GetEffectFromBlendMode(_blendMode); if (blendEffect is BlendEffect) { BlendEffect blend = (BlendEffect)blendEffect; blend.Foreground = nextLayer.GenerateEffectGraph(false); blend.Background = layerEffect; _blendEffect = blend; } else if (blendEffect is CompositeEffect) { CompositeEffect composite = (CompositeEffect)blendEffect; composite.Sources.Add(nextLayer.GenerateEffectGraph(false)); composite.Sources.Add(layerEffect); _blendEffect = composite; } else if (blendEffect is ArithmeticCompositeEffect) { ArithmeticCompositeEffect arith = (ArithmeticCompositeEffect)blendEffect; arith.Source1 = layerEffect; arith.Source2 = nextLayer.GenerateEffectGraph(false); _blendEffect = arith; } else { Debug.Assert(false); } } else { _blendEffect = null; } }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Assets/NormalMapsAndMasks/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; var propsNode = ExpressionValues.Reference.CreatePropertySetReference("props"); var propsCenterPointOffset = propsNode.GetVector2Property("CenterPointOffset"); var propsTranslate = propsNode.GetVector2Property("Translate"); var propsScale = propsNode.GetScalarProperty("Scale"); _transformExpressionNode = EF.Matrix3x2(propsScale, 0, 0, propsScale, propsCenterPointOffset.X * (1 - propsScale) + (propsTranslate.X * propsCenterPointOffset.X * 2), propsCenterPointOffset.Y * (1 - propsScale) + (propsTranslate.Y * propsCenterPointOffset.Y * 2)); return(null); }
/// <summary> /// Function is responsible for creating the circular alpha masked profile brush /// </summary> /// <returns></returns> private CompositionEffectBrush InitializeCrossFadeEffect() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("EffectSource"), Source2Amount = 0, MultiplyAmount = 0 }; var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); return(factory.CreateBrush()); }
protected override void OnConnected() { if (CompositionBrush == null) { IsConnected = true; canvasDevice = CanvasDevice.GetSharedDevice(); graphicsDevice = CanvasComposition.CreateCompositionGraphicsDevice(Compositor, canvasDevice); surface1 = graphicsDevice.CreateDrawingSurface( new Windows.Foundation.Size(100, 100), Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, Windows.Graphics.DirectX.DirectXAlphaMode.Premultiplied); surface2 = graphicsDevice.CreateDrawingSurface( new Windows.Foundation.Size(100, 100), Windows.Graphics.DirectX.DirectXPixelFormat.B8G8R8A8UIntNormalized, Windows.Graphics.DirectX.DirectXAlphaMode.Premultiplied); surfaceBrush1 = Compositor.CreateSurfaceBrush(surface1); surfaceBrush2 = Compositor.CreateSurfaceBrush(surface2); surfaceBrush1.Stretch = CompositionStretch.Fill; surfaceBrush2.Stretch = CompositionStretch.Fill; colorBrush1 = Compositor.CreateColorBrush(); colorBrush2 = Compositor.CreateColorBrush(); Source1Animation = Compositor.CreateScalarKeyFrameAnimation(); Source1Animation.InsertKeyFrame(0f, 1f); Source1Animation.InsertKeyFrame(1f, 0f); Source1Animation.Duration = Duration; Source2Animation = Compositor.CreateScalarKeyFrameAnimation(); Source2Animation.InsertKeyFrame(0f, 0f); Source2Animation.InsertKeyFrame(1f, 1f); Source2Animation.Duration = Duration; var effect = new ArithmeticCompositeEffect() { Name = "effect", Source1 = new CompositionEffectSourceParameter("source1"), Source2 = new CompositionEffectSourceParameter("source2"), Source1Amount = 1f, Source2Amount = 0f, MultiplyAmount = 0, }; CompositionBrush = Compositor.CreateEffectFactory(effect, new[] { "effect.Source1Amount", "effect.Source2Amount" }).CreateBrush(); } }
public void ArithmeticCompositeEffectCustomizations() { var effect = new ArithmeticCompositeEffect(); // Verify defaults. Assert.AreEqual(1.0f, effect.MultiplyAmount); Assert.AreEqual(0.0f, effect.Source1Amount); Assert.AreEqual(0.0f, effect.Source2Amount); Assert.AreEqual(0.0f, effect.Offset); Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 1, 0, 0, 0 })); // Change properties one at a time, and verify that the boxed value changes to match. effect.MultiplyAmount = 23; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 0, 0, 0 })); effect.Source1Amount = 42; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, 0, 0 })); effect.Source2Amount = -1; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, -1, 0 })); effect.Offset = 100; Assert.IsTrue(((float[])EffectAccessor.GetProperty(effect, 0)).SequenceEqual(new float[] { 23, 42, -1, 100 })); // Validate that IGraphicsEffectD2D1Interop reports the right customizations. int index; EffectPropertyMapping mapping; EffectAccessor.GetNamedPropertyMapping(effect, "MultiplyAmount", out index, out mapping); Assert.AreEqual(0, index); Assert.AreEqual(EffectPropertyMapping.VectorX, mapping); EffectAccessor.GetNamedPropertyMapping(effect, "Source1Amount", out index, out mapping); Assert.AreEqual(0, index); Assert.AreEqual(EffectPropertyMapping.VectorY, mapping); EffectAccessor.GetNamedPropertyMapping(effect, "Source2Amount", out index, out mapping); Assert.AreEqual(0, index); Assert.AreEqual(EffectPropertyMapping.VectorZ, mapping); EffectAccessor.GetNamedPropertyMapping(effect, "Offset", out index, out mapping); Assert.AreEqual(0, index); Assert.AreEqual(EffectPropertyMapping.VectorW, mapping); }
private void InitializedFrostedHostGlass(UIElement glassHost, Color color) { string sv = AnalyticsInfo.VersionInfo.DeviceFamilyVersion; ulong v = ulong.Parse(sv); ulong v1 = (v & 0xFFFF000000000000L) >> 48; ulong v2 = (v & 0x0000FFFF00000000L) >> 32; ulong v3 = (v & 0x00000000FFFF0000L) >> 16; ulong v4 = (v & 0x000000000000FFFFL); string version = $"{v1}.{v2}.{v3}.{v4}"; System.Diagnostics.Debug.WriteLine(version); if (v3 > 14393 && AppSetting.IsNotMobile) { Visual hostVisual = ElementCompositionPreview.GetElementVisual(glassHost); Compositor compositor = hostVisual.Compositor; var colorEffect = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 0.3f, Source2Amount = 0.7f, Source1 = new CompositionEffectSourceParameter("backdropBrush"), Source2 = new ColorSourceEffect { Color = color } }; var effectFactory = compositor.CreateEffectFactory(colorEffect); var backdropBrush = compositor.CreateHostBackdropBrush(); var effectBrush = effectFactory.CreateBrush(); effectBrush.SetSourceParameter("backdropBrush", backdropBrush); var glassVisual = compositor.CreateSpriteVisual(); glassVisual.Brush = effectBrush; ElementCompositionPreview.SetElementChildVisual(glassHost, glassVisual); var bindSizeAnimation = compositor.CreateExpressionAnimation("hostVisual.Size"); bindSizeAnimation.SetReferenceParameter("hostVisual", hostVisual); glassVisual.StartAnimation("Size", bindSizeAnimation); } }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .25f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await ImageLoader.Instance.LoadFromUriAsync(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/conemap.jpg")); // Create the animations float sweep = (float)Math.PI / 10f; float fullCircle = (float)Math.PI * -2f; _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.1f, fullCircle); _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep); _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep); _enterAnimation.InsertKeyFrame(1.0f, fullCircle); _enterAnimation.Duration = TimeSpan.FromMilliseconds(4500); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, 0f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2.CreateFromTranslation(-props.CenterPointOffset) * Matrix3x2(cos(props.Rotation) * props.Scale, sin(props.Rotation), -sin(props.Rotation), cos(props.Rotation) * props.Scale, 0, 0) * Matrix3x2.CreateFromTranslation(props.CenterPointOffset + props.Translate)"); return(null); }
public static async Task <IGraphicsEffect> ConcatenateEffectWithTintAndBorderAsync( [NotNull] Compositor compositor, [NotNull] IGraphicsEffectSource source, [NotNull] IDictionary <String, CompositionBrush> parameters, Color color, float colorMix, [CanBeNull] CanvasControl canvas, [NotNull] Uri uri, int timeThreshold = 1000, bool reload = false) { // Setup the tint effect ArithmeticCompositeEffect tint = new ArithmeticCompositeEffect { MultiplyAmount = 0, Source1Amount = 1 - colorMix, Source2Amount = colorMix, // Mix the background with the desired tint color Source1 = source, Source2 = new ColorSourceEffect { Color = color } }; // Get the noise brush using Win2D CompositionSurfaceBrush noiseBitmap = canvas == null ? await LoadWin2DSurfaceBrushFromImageAsync(compositor, uri, reload) : await LoadWin2DSurfaceBrushFromImageAsync(compositor, canvas, uri, timeThreshold, reload); // Make sure the Win2D brush was loaded correctly if (noiseBitmap != null) { // Layer 4 - Noise effect BorderEffect borderEffect = new BorderEffect { ExtendX = CanvasEdgeBehavior.Wrap, ExtendY = CanvasEdgeBehavior.Wrap, Source = new CompositionEffectSourceParameter(nameof(noiseBitmap)) }; BlendEffect blendEffect = new BlendEffect { Background = tint, Foreground = borderEffect, Mode = BlendEffectMode.Overlay }; parameters.Add(nameof(noiseBitmap), noiseBitmap); return(blendEffect); } return(tint); }
private CompositionEffectBrush BuildColoredBlurMixerBrush() { var arithmeticComposit = new ArithmeticCompositeEffect { Name = "Mixer", Source1Amount = 0.0f, Source2Amount = 0.0f, MultiplyAmount = 0, Source2 = new ColorSourceEffect { Name = "ColorSource", Color = Colors.LightSkyBlue }, Source1 = new BlendEffect { Mode = BlendEffectMode.Multiply, Foreground = new ColorSourceEffect { Name = "ColorSource2", Color = Colors.WhiteSmoke }, Background = new GaussianBlurEffect { Name = "Blur", Source = new CompositionEffectSourceParameter("source"), BlurAmount = 0.0f, //15 BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced } } }; var factory = m_compositor.CreateEffectFactory(arithmeticComposit, new string[] { "Blur.BlurAmount", "Mixer.Source1Amount", "Mixer.Source2Amount" }); var brush = factory.CreateBrush(); brush.Properties.InsertScalar("Blur.BlurAmount", 0.0f); brush.Properties.InsertScalar("Mixer.Source1Amount", 1.0f); brush.Properties.InsertScalar("Mixer.Source2Amount", 0.0f); return(brush); }
public void Composite() { // Create the graphics effect var graphicsEffect = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("source1"), Source2 = new SaturationEffect { Saturation = 0, Source = new CompositionEffectSourceParameter("source2") }, MultiplyAmount = 0, Source1Amount = 0.5f, Source2Amount = 0.5f, Offset = 0 }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); // Create and setup an instance of the effect for the visual CompositionSurfaceBrush surfaceBrush1 = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush1, new Uri("ms-appx:///Assets/cat.png")); CompositionSurfaceBrush surfaceBrush2 = _compositor.CreateSurfaceBrush(); LoadImage(surfaceBrush2, new Uri("ms-appx:///Assets/dog.png")); var effect = effectFactory.CreateBrush(); effect.SetSourceParameter("source1", surfaceBrush1); effect.SetSourceParameter("source2", surfaceBrush2); // Create the visual and add it to the composition tree var visual = _compositor.CreateSpriteVisual(); visual.Brush = effect; visual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(visual); }
private ICanvasImage CombineDiffuseAndSpecular(ICanvasImage diffuse, ICanvasImage specular, float x, float y) { var composite = new ArithmeticCompositeEffect { Source1 = new ArithmeticCompositeEffect { Source1 = bitmapTiger, Source2 = diffuse, Source1Amount = 0, Source2Amount = 0, MultiplyAmount = 1, }, Source2 = specular, Source1Amount = 1, Source2Amount = 1, MultiplyAmount = 0, }; return(AddTextOverlay(composite, x, y)); }
public override async Task <CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2(props.Scale, 0, 0, props.Scale, props.CenterPointOffset.X * (1-props.Scale) + (props.Translate.X * props.CenterPointOffset.X * 2), props.CenterPointOffset.Y * (1-props.Scale) + (props.Translate.Y * props.CenterPointOffset.Y * 2))"); return(null); }
/// <summary> /// Function is responsible for creating the circular alpha masked profile brush /// </summary> /// <returns></returns> private CompositionEffectBrush InitializeCrossFadeEffect() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("BlurImage"), Source2Amount = 0, MultiplyAmount = 0 }; var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); CompositionEffectBrush crossFadeBrush = factory.CreateBrush();; crossFadeBrush.SetSourceParameter("ImageSource", ParallaxingImage.SurfaceBrush); crossFadeBrush.SetSourceParameter("BlurImage", _blurSurface.Brush); return(crossFadeBrush); }
public void Composite() { // Create the graphics effect var graphicsEffect = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("source1"), Source2 = new SaturationEffect { Saturation = 0, Source = new CompositionEffectSourceParameter("source2") }, MultiplyAmount = 0, Source1Amount = 0.5f, Source2Amount = 0.5f, Offset = 0 }; // Compile the effect var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); // Create and setup an instance of the effect for the visual var graphicsDevice = _compositor.DefaultGraphicsDevice; var image1 = graphicsDevice.CreateImageFromUri( new Uri("ms-appx:///Assets/cat.png")); var image2 = graphicsDevice.CreateImageFromUri( new Uri("ms-appx:///Assets/dog.png")); var effect = effectFactory.CreateEffect(); effect.SetSourceParameter("source1", image1); effect.SetSourceParameter("source2", image2); // Create the visual and add it to the composition tree var visual = _compositor.CreateEffectVisual(); visual.Effect = effect; visual.Size = new Vector2(219, 300); _root.Children.InsertAtBottom(visual); }
/// <summary> /// Private constructor as Show() is responsible for creating an instance /// </summary> private ImagePopupViewer(Func <object, bool, Uri> photoGetter, string initialPhoto) { this.InitializeComponent(); _imageUriGetterFunc = photoGetter; _transition = new ConnectedTransition(); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; this.Loaded += ImagePopupViewer_Loaded; this.Unloaded += ImagePopupViewer_Unloaded; // Bring the selected item into view _initialPhoto = initialPhoto; // Hide until the content is available this.Opacity = 0; BackgroundImage.ImageOpened += BackgroundImage_FirstOpened; // Disable the placeholder as we'll be using a transition PrimaryImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1); BackgroundImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1); BackgroundImage.LoadTimeEffectHandler = SampleImageColor; BackgroundImage.SharedSurface = true; // Create a crossfade brush to animate image transitions IGraphicsEffect graphicsEffect = new ArithmeticCompositeEffect() { Name = "CrossFade", Source1Amount = 0, Source2Amount = 1, MultiplyAmount = 0, Source1 = new CompositionEffectSourceParameter("ImageSource"), Source2 = new CompositionEffectSourceParameter("ImageSource2"), }; CompositionEffectFactory factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "CrossFade.Source1Amount", "CrossFade.Source2Amount" }); _crossFadeBrush = factory.CreateBrush(); }
/// <summary> /// Private constructor as Show() is responsible for creating an instance /// </summary> private ImagePopupViewer(Func<object, bool, Uri> photoGetter, string initialPhoto) { this.InitializeComponent(); _imageUriGetterFunc = photoGetter; _transition = new ConnectedTransition(); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; this.Loaded += ImagePopupViewer_Loaded; this.Unloaded += ImagePopupViewer_Unloaded; // Bring the selected item into view _initialPhoto = initialPhoto; // Hide until the content is available this.Opacity = 0; BackgroundImage.ImageOpened += BackgroundImage_FirstOpened; // Disable the placeholder as we'll be using a transition PrimaryImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1); BackgroundImage.PlaceholderDelay = TimeSpan.FromMilliseconds(-1); BackgroundImage.LoadTimeEffectHandler = SampleImageColor; BackgroundImage.SharedSurface = true; // Create a crossfade brush to animate image transitions IGraphicsEffect graphicsEffect = new ArithmeticCompositeEffect() { Name = "CrossFade", Source1Amount = 0, Source2Amount = 1, MultiplyAmount = 0, Source1 = new CompositionEffectSourceParameter("ImageSource"), Source2 = new CompositionEffectSourceParameter("ImageSource2"), }; CompositionEffectFactory factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "CrossFade.Source1Amount", "CrossFade.Source2Amount" }); _crossFadeBrush = factory.CreateBrush(); }
private static CompositionEffectBrush CreateBackdropBrush() { var systemChromeMediumColor = (Color)Application.Current.Resources["SystemChromeMediumColor"]; var effect = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("hostbackdrop"), Source2 = new ColorSourceEffect { Color = systemChromeMediumColor, }, Source1Amount = 0.75f, Source2Amount = 0.25f }; var factory = Compositor.CreateEffectFactory(effect, null); var brush = factory.CreateBrush(); brush.SetSourceParameter("hostbackdrop", Compositor.CreateHostBackdropBrush()); return(brush); }
/// <summary> /// Function is responsible for creating the circular alpha masked profile brush /// </summary> /// <returns></returns> private async Task <CompositionEffectBrush> InitializeCrossFadeEffect(Uri uri) { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("BlurImage"), Source2Amount = 0, MultiplyAmount = 0 }; var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); CompositionDrawingSurface blurSurface = await SurfaceLoader.LoadFromUri(uri, Size.Empty, ApplyBlurEffect); CompositionEffectBrush crossFadeBrush = factory.CreateBrush();; crossFadeBrush.SetSourceParameter("ImageSource", ParallaxingImage.SurfaceBrush); crossFadeBrush.SetSourceParameter("BlurImage", _compositor.CreateSurfaceBrush(blurSurface)); return(crossFadeBrush); }
private ICanvasImage CreateLuminanceToAlpha() { var contrastAdjustedTiger = new LinearTransferEffect { Source = bitmapTiger, RedOffset = -3, GreenOffset = -3, BlueOffset = -3, }; var tigerAlpha = new LuminanceToAlphaEffect { Source = contrastAdjustedTiger }; var tigerAlphaWithWhiteRgb = new LinearTransferEffect { Source = tigerAlpha, RedOffset = 1, GreenOffset = 1, BlueOffset = 1, RedSlope = 0, GreenSlope = 0, BlueSlope = 0, }; var recombinedRgbAndAlpha = new ArithmeticCompositeEffect { Source1 = tigerAlphaWithWhiteRgb, Source2 = bitmapTiger, }; var movedTiger = new Transform2DEffect { Source = recombinedRgbAndAlpha }; const float turbulenceSize = 128; var backgroundImage = new CropEffect { Source = new TileEffect { Source = new TurbulenceEffect { Octaves = 8, Size = new Vector2(turbulenceSize), Tileable = true }, SourceRectangle= new Rect(0, 0, turbulenceSize, turbulenceSize) }, SourceRectangle = new Rect((bitmapTiger.Size.ToVector2() * -0.5f).ToPoint(), (bitmapTiger.Size.ToVector2() * 1.5f).ToPoint()) }; var tigerOnBackground = new BlendEffect { Foreground = movedTiger, Background = backgroundImage }; // Animation moves the alpha bitmap around, and alters color transfer settings to change how solid it is. animationFunction = elapsedTime => { contrastAdjustedTiger.RedSlope = contrastAdjustedTiger.GreenSlope = contrastAdjustedTiger.BlueSlope = ((float)Math.Sin(elapsedTime * 0.9) + 2) * 3; var dx = (float)Math.Cos(elapsedTime) * 50; var dy = (float)Math.Sin(elapsedTime) * 50; movedTiger.TransformMatrix = Matrix3x2.CreateTranslation(dx, dy); }; return tigerOnBackground; }
private ICanvasImage CombineDiffuseAndSpecular(ICanvasImage diffuse, ICanvasImage specular, float x, float y) { var composite = new ArithmeticCompositeEffect { Source1 = new ArithmeticCompositeEffect { Source1 = bitmapTiger, Source2 = diffuse, Source1Amount = 0, Source2Amount = 0, MultiplyAmount = 1, }, Source2 = specular, Source1Amount = 1, Source2Amount = 1, MultiplyAmount = 0, }; return AddTextOverlay(composite, x, y); }
private ICanvasImage CreateArithmeticComposite() { // Combine two tiger images, the second one slightly rotated. var arithmeticEffect = new ArithmeticCompositeEffect { Source1 = bitmapTiger, Source2 = new Transform2DEffect { Source = bitmapTiger, TransformMatrix = Matrix3x2.CreateRotation(0.5f) } }; // Animate the effect by changing parameters using sine waves of different frequencies. animationFunction = elapsedTime => { arithmeticEffect.MultiplyAmount = (float)Math.Sin(elapsedTime * 23) * Math.Max(0, (float)Math.Sin(elapsedTime * 0.7)); arithmeticEffect.Source1Amount = (float)Math.Sin(elapsedTime * 1.1); arithmeticEffect.Source2Amount = (float)Math.Sin(elapsedTime * 1.7); arithmeticEffect.Offset = (float)Math.Sin(elapsedTime * 0.2) / 2 + 0.25f; }; return arithmeticEffect; }
#pragma warning disable 1998 public override async Task<CompositionDrawingSurface> LoadResources() { // Create the effect template var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("EffectSource"), Source2Amount = 0, MultiplyAmount = 0 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); // Create the animations _animationDecreasing = _compositor.CreateScalarKeyFrameAnimation(); _animationDecreasing.InsertKeyFrame(1f, 0f); _animationDecreasing.Duration = TimeSpan.FromMilliseconds(1000); _animationDecreasing.IterationBehavior = AnimationIterationBehavior.Count; _animationDecreasing.IterationCount = 1; _animationIncreasing = _compositor.CreateScalarKeyFrameAnimation(); _animationIncreasing.InsertKeyFrame(1f, 1f); _animationIncreasing.Duration = TimeSpan.FromMilliseconds(1000); _animationIncreasing.IterationBehavior = AnimationIterationBehavior.Count; _animationIncreasing.IterationCount = 1; _loadEffectHandler = ApplyBlurEffect; return null; }
private async void UpdateEffect() { if (_compositor != null) { ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; IGraphicsEffect graphicsEffect = null; CompositionBrush secondaryBrush = null; string[] animatableProperties = null; // // Create the appropriate effect graph and resources // switch ((EffectTypes)item.Tag) { case EffectTypes.Desaturation: { graphicsEffect = new SaturationEffect() { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("ImageSource") }; } break; case EffectTypes.Hue: { graphicsEffect = new HueRotationEffect() { Name = "Hue", Angle = 3.14f, Source = new CompositionEffectSourceParameter("ImageSource") }; animatableProperties = new[] { "Hue.Angle" }; } break; case EffectTypes.VividLight: { graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.VividLight, Foreground = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255,80,40,40) }, Background = new CompositionEffectSourceParameter("ImageSource"), }; animatableProperties = new[] { "Base.Color" }; } break; case EffectTypes.Mask: { graphicsEffect = new CompositeEffect() { Mode = CanvasComposite.DestinationOver, Sources = { new CompositeEffect() { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("ImageSource"), new CompositionEffectSourceParameter("SecondSource") } }, new ColorSourceEffect() { Color = Color.FromArgb(200,255,255,255) }, } }; CompositionDrawingSurface backgroundSurface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/ForegroundFocusEffects/mask.png")); CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush(backgroundSurface); maskBrush.Stretch = CompositionStretch.UniformToFill; maskBrush.CenterPoint = backgroundSurface.Size.ToVector2() / 2; secondaryBrush = maskBrush; } break; case EffectTypes.Blur: { graphicsEffect = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, }; } break; case EffectTypes.LightenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 255, 255, 255), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; } break; case EffectTypes.DarkenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode= EffectBorderMode.Hard, } }; } break; case EffectTypes.RainbowBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .3f, Source2Amount = .7f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; animatableProperties = new[] { "Base.Color" }; } break; default: break; } // Create the effect factory and instantiate a brush CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, animatableProperties); CompositionEffectBrush brush = _effectFactory.CreateBrush(); // Set the destination brush as the source of the image content brush.SetSourceParameter("ImageSource", _compositor.CreateBackdropBrush()); // If his effect uses a secondary brush, set it now if (secondaryBrush != null) { brush.SetSourceParameter("SecondSource", secondaryBrush); } // Update the destination layer with the fully configured brush _destinationSprite.Brush = brush; } }
/// <summary> /// Function is responsible for creating the circular alpha masked profile brush /// </summary> /// <returns></returns> private CompositionEffectBrush InitializeCrossFadeEffect() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("EffectSource"), Source2Amount = 0, MultiplyAmount = 0 }; var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); return factory.CreateBrush(); }
private async void UpdateEffect() { if (_compositor != null) { ComboBoxItem item = EffectSelection.SelectedValue as ComboBoxItem; IGraphicsEffect graphicsEffect = null; CompositionBrush secondaryBrush = null; string[] animatableProperties = null; // // Create the appropriate effect graph and resources // switch ((EffectTypes)item.Tag) { case EffectTypes.Desaturation: { graphicsEffect = new SaturationEffect() { Saturation = 0.0f, Source = new CompositionEffectSourceParameter("ImageSource") }; } break; case EffectTypes.Hue: { graphicsEffect = new HueRotationEffect() { Name = "Hue", Angle = 3.14f, Source = new CompositionEffectSourceParameter("ImageSource") }; animatableProperties = new[] { "Hue.Angle" }; } break; case EffectTypes.VividLight: { graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.VividLight, Foreground = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 80, 40, 40) }, Background = new CompositionEffectSourceParameter("ImageSource"), }; animatableProperties = new[] { "Base.Color" }; } break; case EffectTypes.Mask: { graphicsEffect = new CompositeEffect() { Mode = CanvasComposite.DestinationOver, Sources = { new CompositeEffect() { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("ImageSource"), new CompositionEffectSourceParameter("SecondSource") } }, new ColorSourceEffect() { Color = Color.FromArgb(200, 255, 255, 255) }, } }; CompositionDrawingSurface backgroundSurface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/ForegroundFocusEffects/mask.png")); CompositionSurfaceBrush maskBrush = _compositor.CreateSurfaceBrush(backgroundSurface); maskBrush.Stretch = CompositionStretch.UniformToFill; maskBrush.CenterPoint = _destinationSprite.Size * .5f; secondaryBrush = maskBrush; } break; case EffectTypes.Blur: { graphicsEffect = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, }; } break; case EffectTypes.LightenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 255, 255, 255), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; } break; case EffectTypes.DarkenBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .4f, Source2Amount = .6f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; } break; case EffectTypes.RainbowBlur: { graphicsEffect = new ArithmeticCompositeEffect() { Source1Amount = .3f, Source2Amount = .7f, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Base", Color = Color.FromArgb(255, 0, 0, 0), }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("ImageSource"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, } }; animatableProperties = new[] { "Base.Color" }; } break; default: break; } // Create the effect factory and instantiate a brush CompositionEffectFactory _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, animatableProperties); CompositionEffectBrush brush = _effectFactory.CreateBrush(); // Set the destination brush as the source of the image content brush.SetSourceParameter("ImageSource", _compositor.CreateBackdropBrush()); // If his effect uses a secondary brush, set it now if (secondaryBrush != null) { brush.SetSourceParameter("SecondSource", secondaryBrush); } // Update the destination layer with the fully configured brush _destinationSprite.Brush = brush; } }
private void MainGridLoaded(object sender, RoutedEventArgs e) { m_compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor; m_root = m_compositor.CreateContainerVisual(); ElementCompositionPreview.SetElementChildVisual(MainGrid, m_root); Size imageSize; m_noEffectBrush = CreateBrushFromAsset( "Bruno'sFamily2015 (13)-X2.jpg", out imageSize); m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height; m_sprite = m_compositor.CreateSpriteVisual(); ResizeImage(new Size(MainGrid.ActualWidth, MainGrid.ActualHeight)); m_root.Children.InsertAtTop(m_sprite); // Image with alpha channel as an mask. var alphaMaskEffectDesc = new CompositeEffect { Mode = CanvasComposite.DestinationIn, Sources = { new CompositionEffectSourceParameter("Image"), new Transform2DEffect { Name = "MaskTransform", Source = new CompositionEffectSourceParameter("Mask") } } }; m_alphaMaskEffectBrush = m_compositor.CreateEffectFactory( alphaMaskEffectDesc, new[] { "MaskTransform.TransformMatrix" } ).CreateBrush(); m_alphaMaskEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); m_alphaMaskEffectBrush.SetSourceParameter( "Mask", CreateBrushFromAsset("CircleMask.png")); // Arithmetic operations between two images. var arithmeticEffectDesc = new ArithmeticCompositeEffect { Name = "effect", ClampOutput = false, Source1 = new CompositionEffectSourceParameter("Source1"), Source2 = new CompositionEffectSourceParameter("Source2") }; m_arithmeticEffectBrush = m_compositor.CreateEffectFactory( arithmeticEffectDesc, new[] { "effect.MultiplyAmount", "effect.Source1Amount", "effect.Source2Amount", "effect.Offset" } ).CreateBrush(); m_arithmeticEffectBrush.SetSourceParameter( "Source1", m_noEffectBrush); m_arithmeticEffectBrush.SetSourceParameter( "Source2", CreateBrushFromAsset("_P2A8041.jpg")); // Creates a blend effect that combines two images. var foregroundBrush = CreateBrushFromAsset("Checkerboard_100x100.png"); m_blendEffectBrushes = new CompositionEffectBrush[m_supportedBlendModes.Length]; for (int i = 0; i < m_supportedBlendModes.Length; i++) { var blendEffectDesc = new BlendEffect { Mode = m_supportedBlendModes[i], Background = new CompositionEffectSourceParameter("Background"), Foreground = new CompositionEffectSourceParameter("Foreground") }; m_blendEffectBrushes[i] = m_compositor.CreateEffectFactory( blendEffectDesc ).CreateBrush(); m_blendEffectBrushes[i].SetSourceParameter( "Background", m_noEffectBrush); m_blendEffectBrushes[i].SetSourceParameter( "Foreground", foregroundBrush); } // Generates an image containing a solid color. var colorSourceEffectDesc = new ColorSourceEffect // FloodEffect { Name = "effect" }; m_colorSourceEffectBrush = m_compositor.CreateEffectFactory( colorSourceEffectDesc, new[] { "effect.Color" } ).CreateBrush(); // Changes the contrast of an image. var contrastEffectDesc = new ContrastEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_contrastEffectBrush = m_compositor.CreateEffectFactory( contrastEffectDesc, new[] { "effect.Contrast" } ).CreateBrush(); m_contrastEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Changes the exposure of an image. var exposureEffectDesc = new ExposureEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_exposureEffectBrush = m_compositor.CreateEffectFactory( exposureEffectDesc, new[] { "effect.Exposure" } ).CreateBrush(); m_exposureEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the colors of an image by applying a per-channel gamma transfer function. var gammaTransferEffectDesc = new GammaTransferEffect { Name = "effect", RedDisable = false, GreenDisable = false, BlueDisable = false, AlphaDisable = false, Source = new CompositionEffectSourceParameter("Image") }; m_gammaTransferEffectBrush = m_compositor.CreateEffectFactory( gammaTransferEffectDesc, new[] { "effect.RedAmplitude", "effect.RedExponent", "effect.RedOffset", "effect.GreenAmplitude", "effect.GreenExponent", "effect.GreenOffset", "effect.BlueAmplitude", "effect.BlueExponent", "effect.BlueOffset" } ).CreateBrush(); m_gammaTransferEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to monochromatic gray. var grayscaleEffectDesc = new GrayscaleEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_grayscaleEffectBrush = m_compositor.CreateEffectFactory( grayscaleEffectDesc ).CreateBrush(); m_grayscaleEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the color of an image by rotating its hue values. var hueRotationEffectDesc = new HueRotationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_hueRotationEffectBrush = m_compositor.CreateEffectFactory( hueRotationEffectDesc, new[] { "effect.Angle" } ).CreateBrush(); m_hueRotationEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Inverts the colors of an image. var invertEffectDesc = new InvertEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_invertEffectBrush = m_compositor.CreateEffectFactory( invertEffectDesc ).CreateBrush(); m_invertEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Alters the saturation of an image. var saturationEffectDesc = new SaturationEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_saturateEffectBrush = m_compositor.CreateEffectFactory( saturationEffectDesc, new[] { "effect.Saturation" } ).CreateBrush(); m_saturateEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Converts an image to sepia tones. var supportedAlphaModes = new[] { CanvasAlphaMode.Premultiplied, CanvasAlphaMode.Straight }; m_sepiaEffectBrushes = new CompositionEffectBrush[supportedAlphaModes.Length]; for (int i = 0; i < supportedAlphaModes.Length; i++) { var sepiaEffectDesc = new SepiaEffect { Name = "effect", AlphaMode = supportedAlphaModes[i], Source = new CompositionEffectSourceParameter("Image") }; m_sepiaEffectBrushes[i] = m_compositor.CreateEffectFactory( sepiaEffectDesc, new[] { "effect.Intensity" } ).CreateBrush(); m_sepiaEffectBrushes[i].SetSourceParameter( "Image", m_noEffectBrush); } // Adjusts the temperature and/or tint of an image. var temperatureAndTintEffectDesc = new TemperatureAndTintEffect { Name = "effect", Source = new CompositionEffectSourceParameter("Image") }; m_temperatureAndTintEffectBrush = m_compositor.CreateEffectFactory( temperatureAndTintEffectDesc, new[] { "effect.Temperature", "effect.Tint" } ).CreateBrush(); m_temperatureAndTintEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // Applies a 2D affine transform matrix to an image. var transform2DEffectDesc = new Transform2DEffect { TransformMatrix = new Matrix3x2( -1, 0, 0, 1, m_sprite.Size.X, 0), Source = new CompositionEffectSourceParameter("Image") }; m_transform2DEffectBrush = m_compositor.CreateEffectFactory( transform2DEffectDesc ).CreateBrush(); m_transform2DEffectBrush.SetSourceParameter( "Image", m_noEffectBrush); // For simplying UI states switch, put effect parameter grids in an array m_effectParamsGrids = new Grid[(int)EffectType.NumEffectTypes]; m_effectParamsGrids[(int)EffectType.NoEffect] = null; m_effectParamsGrids[(int)EffectType.AlphaMask] = AlphaMaskParams; m_effectParamsGrids[(int)EffectType.Arithmetic] = ArithmeticParams; m_effectParamsGrids[(int)EffectType.Blend] = BlendParams; m_effectParamsGrids[(int)EffectType.ColorSource] = ColorSourceParams; m_effectParamsGrids[(int)EffectType.Contrast] = ContrastParams; m_effectParamsGrids[(int)EffectType.Exposure] = ExposureParams; m_effectParamsGrids[(int)EffectType.GammaTransfer] = GammaTransferParams; m_effectParamsGrids[(int)EffectType.Grayscale] = null; m_effectParamsGrids[(int)EffectType.HueRotation] = HueRotationParams; m_effectParamsGrids[(int)EffectType.Invert] = null; m_effectParamsGrids[(int)EffectType.Saturation] = SaturationParams; m_effectParamsGrids[(int)EffectType.Sepia] = SepiaParams; m_effectParamsGrids[(int)EffectType.TemperatureAndTint] = TemperatureAndTintParams; m_effectParamsGrids[(int)EffectType.Transform2D] = null; // Same as grids m_effectBrushes = new CompositionBrush[(int)EffectType.NumEffectTypes]; m_effectBrushes[(int)EffectType.NoEffect] = m_noEffectBrush; m_effectBrushes[(int)EffectType.AlphaMask] = m_alphaMaskEffectBrush; m_effectBrushes[(int)EffectType.Arithmetic] = m_arithmeticEffectBrush; m_effectBrushes[(int)EffectType.Blend] = m_blendEffectBrushes[m_activeBlendMode]; m_effectBrushes[(int)EffectType.ColorSource] = m_colorSourceEffectBrush; m_effectBrushes[(int)EffectType.Contrast] = m_contrastEffectBrush; m_effectBrushes[(int)EffectType.Exposure] = m_exposureEffectBrush; m_effectBrushes[(int)EffectType.GammaTransfer] = m_gammaTransferEffectBrush; m_effectBrushes[(int)EffectType.Grayscale] = m_grayscaleEffectBrush; m_effectBrushes[(int)EffectType.HueRotation] = m_hueRotationEffectBrush; m_effectBrushes[(int)EffectType.Invert] = m_invertEffectBrush; m_effectBrushes[(int)EffectType.Saturation] = m_saturateEffectBrush; m_effectBrushes[(int)EffectType.Sepia] = m_sepiaEffectBrushes[m_activeSepiaAlphaMode]; m_effectBrushes[(int)EffectType.TemperatureAndTint] = m_temperatureAndTintEffectBrush; m_effectBrushes[(int)EffectType.Transform2D] = m_transform2DEffectBrush; this.InitializeValues(); }
public override async Task<CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .1f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/pointmap.jpg")); // Create the animations CubicBezierEasingFunction easeIn = _compositor.CreateCubicBezierEasingFunction(new Vector2(0.0f, 0.51f), new Vector2(1.0f, 0.51f)); _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.33f, 1.25f, easeIn); _enterAnimation.InsertKeyFrame(0.66f, 0.75f, easeIn); _enterAnimation.InsertKeyFrame(1.0f, 1.0f, easeIn); _enterAnimation.Duration = TimeSpan.FromMilliseconds(5000); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Forever; _exitAnimation = _compositor.CreateVector2KeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, new Vector2(0, 0)); _exitAnimation.Duration = TimeSpan.FromMilliseconds(750); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2(props.Scale, 0, 0, props.Scale, props.CenterPointOffset.X * (1-props.Scale) + (props.Translate.X * props.CenterPointOffset.X * 2), props.CenterPointOffset.Y * (1-props.Scale) + (props.Translate.Y * props.CenterPointOffset.Y * 2))"); return null; }
private void InitializeEffect() { Effect = new ArithmeticCompositeEffect { Name = "effect", ClampOutput = false, Source1 = new CompositionEffectSourceParameter("Source1"), Source2 = new CompositionEffectSourceParameter("Source2"), Source1Amount = 0.0f, Source2Amount = 0.0f, MultiplyAmount = 0.0f }; }
/// <summary> /// 背景模糊特性 /// </summary> /// <param name="panel"></param> private void ApplyAcrylicAccent(FrameworkElement panel) { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _hostSprite = _compositor.CreateSpriteVisual(); _hostSprite.Size = new Vector2((float)panel.ActualWidth, (float)panel.ActualHeight); ElementCompositionPreview.SetElementChildVisual(panel, _hostSprite); // TODO 14393 15063 _hostSprite.Brush = _compositor.CreateHostBackdropBrush(); var bloomEffectDesc = new ArithmeticCompositeEffect { Name = "Bloom", Source1Amount = 1, Source2Amount = 2, MultiplyAmount = 0, Source1 = new CompositionEffectSourceParameter("source"), Source2 = new GaussianBlurEffect { Name = "Blur", BorderMode = EffectBorderMode.Hard, BlurAmount = 40, Source = new BlendEffect { Mode = BlendEffectMode.Multiply, Background = new CompositionEffectSourceParameter("source2"), Foreground = new CompositionEffectSourceParameter("source2") } } }; var bloomEffectFactory = _compositor.CreateEffectFactory(bloomEffectDesc, new[] { "Bloom.Source2Amount", "Blur.BlurAmount" }); var brush = bloomEffectFactory.CreateBrush(); var backdropBrush = _compositor.CreateHostBackdropBrush(); brush.SetSourceParameter("source", backdropBrush); brush.SetSourceParameter("source2", backdropBrush); // Setup some animations for the bloom effect var blurAnimation = _compositor.CreateScalarKeyFrameAnimation(); blurAnimation.InsertKeyFrame(0, 0); blurAnimation.InsertKeyFrame(.5f, 2); blurAnimation.InsertKeyFrame(1, 0); blurAnimation.Duration = TimeSpan.FromMilliseconds(5000); blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever; var bloomAnimation = _compositor.CreateScalarKeyFrameAnimation(); bloomAnimation.InsertKeyFrame(0, 0); bloomAnimation.InsertKeyFrame(.5f, 40); bloomAnimation.InsertKeyFrame(1, 0); bloomAnimation.Duration = TimeSpan.FromMilliseconds(5000); bloomAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Bloom.Source2Amount", blurAnimation); brush.StartAnimation("Blur.BlurAmount", bloomAnimation); _hostSprite.Brush = brush; }
/// <summary> /// Function is responsible for creating the circular alpha masked profile brush /// </summary> /// <returns></returns> private async Task<CompositionEffectBrush> InitializeCrossFadeEffect(Uri uri) { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = 1, Source2 = new CompositionEffectSourceParameter("BlurImage"), Source2Amount = 0, MultiplyAmount = 0 }; var factory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Arithmetic.Source1Amount", "Arithmetic.Source2Amount" }); CompositionDrawingSurface blurSurface = await SurfaceLoader.LoadFromUri(uri, Size.Empty, ApplyBlurEffect); CompositionEffectBrush crossFadeBrush = factory.CreateBrush(); ; crossFadeBrush.SetSourceParameter("ImageSource", ParallaxingImage.SurfaceBrush); crossFadeBrush.SetSourceParameter("BlurImage", _compositor.CreateSurfaceBrush(blurSurface)); return crossFadeBrush; }
protected override void OnConnected() { if (DesignMode.DesignModeEnabled) { return; } compositor = ElementCompositionPreview.GetElementVisual(Window.Current.Content as UIElement).Compositor; var tintOpacity = Convert.ToSingle(TintOpacity); if (tintOpacity < 0f) { tintOpacity = 0f; } if (tintOpacity > 1f) { tintOpacity = 1f; } var arithmeticEffect = new ArithmeticCompositeEffect() { Name = "arithmetic", MultiplyAmount = 0, Source1Amount = 1f - tintOpacity, Source2Amount = tintOpacity, Source1 = new ArithmeticCompositeEffect() { MultiplyAmount = 0f, Source1Amount = 0.95f, Source2Amount = 0.05f, Source1 = new GaussianBlurEffect() { Name = "blur", BlurAmount = Convert.ToSingle(BlurAmount), BorderMode = EffectBorderMode.Hard, Optimization = EffectOptimization.Balanced, Source = new CompositionEffectSourceParameter("source"), }, Source2 = new BorderEffect() { Source = new CompositionEffectSourceParameter("image"), ExtendX = CanvasEdgeBehavior.Wrap, ExtendY = CanvasEdgeBehavior.Wrap, } }, Source2 = new ColorSourceEffect() { Name = "tintcolor", Color = TintColor } }; Brush = compositor.CreateEffectFactory(arithmeticEffect, new[] { "arithmetic.Source1Amount", "arithmetic.Source2Amount", "tintcolor.Color" }).CreateBrush(); var imagesurface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///FluentDesignSystem/Sketch/SketchTexture.jpg")); var imagebrush = compositor.CreateSurfaceBrush(imagesurface); imagebrush.Stretch = CompositionStretch.None; Brush.SetSourceParameter("image", imagebrush); switch (BackgroundSource) { case AcrylicBackgroundSource.Backdrop: Brush.SetSourceParameter("source", compositor.CreateBackdropBrush()); break; case AcrylicBackgroundSource.Hostbackdrop: Brush.SetSourceParameter("source", compositor.CreateHostBackdropBrush()); break; } CompositionBrush = Brush; var line = compositor.CreateLinearEasingFunction(); TintOpacityFillAnimation = compositor.CreateScalarKeyFrameAnimation(); TintOpacityFillAnimation.InsertExpressionKeyFrame(0f, "TintOpacity", line); TintOpacityFillAnimation.InsertKeyFrame(1f, 1f, line); TintOpacityFillAnimation.Duration = TimeSpan.FromSeconds(0.1d); TintOpacityFillAnimation.Target = "arithmetic.Source2Amount"; HostOpacityZeroAnimation = compositor.CreateScalarKeyFrameAnimation(); HostOpacityZeroAnimation.InsertExpressionKeyFrame(0f, "1f - TintOpacity", line); HostOpacityZeroAnimation.InsertKeyFrame(1f, 0f, line); HostOpacityZeroAnimation.Duration = TimeSpan.FromSeconds(0.1d); HostOpacityZeroAnimation.Target = "arithmetic.Source1Amount"; TintToFallBackAnimation = compositor.CreateColorKeyFrameAnimation(); TintToFallBackAnimation.InsertKeyFrame(0f, TintColor, line); TintToFallBackAnimation.InsertKeyFrame(1f, FallbackColor, line); TintToFallBackAnimation.Duration = TimeSpan.FromSeconds(0.1d); TintToFallBackAnimation.Target = "tintcolor.Color"; //Window.Current.Activated += Current_Activated; //Window.Current.VisibilityChanged += Current_VisibilityChanged; CoreWindow.GetForCurrentThread().Activated += AcrylicBrush_Activated; CoreWindow.GetForCurrentThread().VisibilityChanged += AcrylicBrush_VisibilityChanged; }
public override async Task<CompositionDrawingSurface> LoadResources() { var graphicsEffect = new ArithmeticCompositeEffect { Name = "Arithmetic", Source1 = new CompositionEffectSourceParameter("ImageSource"), Source1Amount = .25f, Source2 = new Transform2DEffect { Name = "LightMapTransform", Source = new CompositionEffectSourceParameter("LightMap") }, Source2Amount = 0, MultiplyAmount = 1 }; _effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "LightMapTransform.TransformMatrix" }); // Create the image _lightMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 10586/PointerEnterEffects/conemap.jpg")); // Create the animations float sweep = (float)Math.PI / 10f; float fullCircle = (float)Math.PI * -2f; _enterAnimation = _compositor.CreateScalarKeyFrameAnimation(); _enterAnimation.InsertKeyFrame(0.1f, fullCircle); _enterAnimation.InsertKeyFrame(0.4f, fullCircle + sweep); _enterAnimation.InsertKeyFrame(0.8f, fullCircle - sweep); _enterAnimation.InsertKeyFrame(1.0f, fullCircle); _enterAnimation.Duration = TimeSpan.FromMilliseconds(4500); _enterAnimation.IterationBehavior = AnimationIterationBehavior.Count; _enterAnimation.IterationCount = 1; _exitAnimation = _compositor.CreateScalarKeyFrameAnimation(); _exitAnimation.InsertKeyFrame(1.0f, 0f); _exitAnimation.Duration = TimeSpan.FromMilliseconds(1000); _exitAnimation.IterationBehavior = AnimationIterationBehavior.Count; _exitAnimation.IterationCount = 1; _transformExpression = _compositor.CreateExpressionAnimation("Matrix3x2.CreateFromTranslation(-props.CenterPointOffset) * Matrix3x2(cos(props.Rotation) * props.Scale, sin(props.Rotation), -sin(props.Rotation), cos(props.Rotation) * props.Scale, 0, 0) * Matrix3x2.CreateFromTranslation(props.CenterPointOffset + props.Translate)"); return null; }
protected override void OnConnected() { Compositor compositor = Window.Current.Compositor; // CompositionCapabilities: Are Effects supported? bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported(); FallbackColor = Color.FromArgb(100, 60, 60, 60); if (usingFallback) { // If Effects are not supported, use Fallback Solid Color CompositionBrush = compositor.CreateColorBrush(FallbackColor); return; } // Load NormalMap onto an ICompositionSurface using LoadedImageSurface _surface = LoadedImageSurface.StartLoadFromUri(new Uri("ms-appx:///Assets/Damaged_NormalMap.jpg"), new Size(400, 400)); // Load Surface onto SurfaceBrush CompositionSurfaceBrush normalMap = compositor.CreateSurfaceBrush(_surface); normalMap.Stretch = CompositionStretch.Uniform; // Define Effect graph const float glassLightAmount = 0.5f; const float glassBlurAmount = 0.95f; Color tintColor = Color.FromArgb(255, 128, 128, 128); var graphicsEffect = new ArithmeticCompositeEffect() { Name = "LightComposite", Source1Amount = 1, Source2Amount = glassLightAmount, MultiplyAmount = 0, Source1 = new ArithmeticCompositeEffect() { Name = "BlurComposite", Source1Amount = 1 - glassBlurAmount, Source2Amount = glassBlurAmount, MultiplyAmount = 0, Source1 = new ColorSourceEffect() { Name = "Tint", Color = tintColor, }, Source2 = new GaussianBlurEffect() { BlurAmount = 20, Source = new CompositionEffectSourceParameter("Backdrop"), Optimization = EffectOptimization.Balanced, BorderMode = EffectBorderMode.Hard, }, }, Source2 = new SceneLightingEffect() { AmbientAmount = 0.15f, DiffuseAmount = 1, SpecularAmount = 0.1f, NormalMapSource = new CompositionEffectSourceParameter("NormalMap") }, }; // Create EffectFactory and EffectBrush CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect); CompositionEffectBrush effectBrush = effectFactory.CreateBrush(); // Create BackdropBrush CompositionBackdropBrush backdrop = compositor.CreateBackdropBrush(); // Set Sources to Effect effectBrush.SetSourceParameter("NormalMap", normalMap); effectBrush.SetSourceParameter("Backdrop", backdrop); // Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement CompositionBrush = effectBrush; }
private void SamplePage_Loaded(object sender, RoutedEventArgs e) { //get interop compositor _compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor; //get image brush and image visual _image = Image; _imageVisual = _image.SpriteVisual; _imageBrush = _image.SurfaceBrush; //load height map to surface brush _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); _normalMapSurface = _imageLoader.CreateManagedSurfaceFromUri(new Uri("ms-appx:///Samples/SDK Insider/ImageLightingPlayground/rocks_NM_height.png")); _normalMapBrush = _compositor.CreateSurfaceBrush(); _normalMapBrush.Surface = _normalMapSurface.Surface; //set up lighting effects: // DISTANT DIFFUSE // Effect description var distantDiffuseDesc = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("Image"), Source2 = new DistantDiffuseEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Source1Amount = 0, Source2Amount = 0, MultiplyAmount = 1 }; //Create (Light)EffectBrush from EffectFactory and specify animatable properties _distantDiffuseLightBrush = _compositor.CreateEffectFactory( distantDiffuseDesc, new[] { "light.Azimuth", "light.Elevation", "light.DiffuseAmount", "light.LightColor" } ).CreateBrush(); //set source parameters to image and normal map _distantDiffuseLightBrush.SetSourceParameter( "Image", _imageBrush); _distantDiffuseLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); // DISTANT SPECULAR // Effect description var distantSpecularDesc = new BlendEffect { Foreground = new CompositionEffectSourceParameter("Image"), Background = new DistantSpecularEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Mode = BlendEffectMode.Screen }; //Create (Light)EffectBrush from EffectFactory and specify animatable properties _distantSpecularLightBrush = _compositor.CreateEffectFactory( distantSpecularDesc, new[] { "light.Azimuth", "light.Elevation", "light.SpecularExponent", "light.SpecularAmount", "light.LightColor" } ).CreateBrush(); //set source parameters to image and normal map _distantSpecularLightBrush.SetSourceParameter( "Image", _imageBrush); _distantSpecularLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); // POINT DIFFUSE // Effect description var pointDiffuseDesc = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("Image"), Source2 = new PointDiffuseEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Source1Amount = 0, Source2Amount = 0, MultiplyAmount = 1 }; //Create (Light)EffectBrush from EffectFactory and specify animatable properties _pointDiffuseLightBrush = _compositor.CreateEffectFactory( pointDiffuseDesc, new[] { "light.LightPosition", "light.DiffuseAmount", "light.HeightMapScale", "light.LightColor" } ).CreateBrush(); // set source parameters to image and normal map _pointDiffuseLightBrush.SetSourceParameter( "Image", _imageBrush); _pointDiffuseLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); // POINT SPECUALR // Effect description var pointSpecularDesc = new BlendEffect { Foreground = new CompositionEffectSourceParameter("Image"), Background = new PointSpecularEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Mode = BlendEffectMode.Screen }; //Create (Light)EffectBrush from EffectFactory and specify animatable properties _pointSpecularLightBrush = _compositor.CreateEffectFactory( pointSpecularDesc, new[] { "light.LightPosition", "light.SpecularExponent", "light.SpecularAmount", "light.HeightMapScale", "light.LightColor" } ).CreateBrush(); // set source parameters to image and normal map _pointSpecularLightBrush.SetSourceParameter( "Image", _imageBrush); _pointSpecularLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); //SPOT DIFFUSE // Effect description var spotDiffuseDesc = new ArithmeticCompositeEffect { Source1 = new CompositionEffectSourceParameter("Image"), Source2 = new SpotDiffuseEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Source1Amount = 0, Source2Amount = 0, MultiplyAmount = 1 }; //Create (Light)EffectBrush from EffectFactory and specify animatable properties _spotDiffuseLightBrush = _compositor.CreateEffectFactory( spotDiffuseDesc, new[] { "light.LightPosition", "light.LightTarget", "light.Focus", "light.LimitingConeAngle", "light.DiffuseAmount", "light.HeightMapScale", "light.LightColor" } ).CreateBrush(); // set source parameters to image and normal map _spotDiffuseLightBrush.SetSourceParameter( "Image", _imageBrush); _spotDiffuseLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); // SPOT SPECULAR // Effect description var spotSpecularDesc = new BlendEffect { Foreground = new CompositionEffectSourceParameter("Image"), Background = new SpotSpecularEffect { Name = "light", Source = new CompositionEffectSourceParameter("NormalMap") }, Mode = BlendEffectMode.Screen }; //Create (Light)EffectBrush from EffectFactory _spotSpecularLightBrush = _compositor.CreateEffectFactory( spotSpecularDesc, new[] { "light.LightPosition", "light.LightTarget", "light.Focus", "light.LimitingConeAngle", "light.SpecularExponent", "light.SpecularAmount", "light.HeightMapScale", "light.LightColor" } ).CreateBrush(); // set source parameters to image and normal map _spotSpecularLightBrush.SetSourceParameter( "Image", _imageBrush); _spotSpecularLightBrush.SetSourceParameter( "NormalMap", _normalMapBrush); // For simplying UI states switch, put light parameter grids in an array _lightParamsGrids = new Grid[(int)LightType.NumLightTypes]; _lightParamsGrids[(int)LightType.NoLight] = null; _lightParamsGrids[(int)LightType.DistantDiffuse] = DistantDiffuseParams; _lightParamsGrids[(int)LightType.DistantSpecular] = DistantSpecularParams; _lightParamsGrids[(int)LightType.PointDiffuse] = PointDiffuseParams; _lightParamsGrids[(int)LightType.PointSpecular] = PointSpecularParams; _lightParamsGrids[(int)LightType.SpotDiffuse] = SpotDiffuseParams; _lightParamsGrids[(int)LightType.SpotSpecular] = SpotSpecularParams; // Same as grids _lightBrushes = new CompositionBrush[(int)LightType.NumLightTypes]; _lightBrushes[(int)LightType.NoLight] = _imageBrush; _lightBrushes[(int)LightType.DistantDiffuse] = _distantDiffuseLightBrush; _lightBrushes[(int)LightType.DistantSpecular] = _distantSpecularLightBrush; _lightBrushes[(int)LightType.PointDiffuse] = _pointDiffuseLightBrush; _lightBrushes[(int)LightType.PointSpecular] = _pointSpecularLightBrush; _lightBrushes[(int)LightType.SpotDiffuse] = _spotDiffuseLightBrush; _lightBrushes[(int)LightType.SpotSpecular] = _spotSpecularLightBrush; //Initialize values for all light types InitializeValues(); }