private void applyBlurBackDrop(Panel panel)
        {
            _compositor      = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _blurSprite      = _compositor.CreateSpriteVisual();
            _blurSprite.Size = new Vector2((float)panel.ActualWidth, (float)panel.ActualHeight);
            ElementCompositionPreview.SetElementChildVisual(panel, _blurSprite);

            // Create an effect description
            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                Name         = "Blur",
                BlurAmount   = 2.0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced
            };

            blurEffect.Source = new CompositionEffectSourceParameter("source");

            CompositionEffectFactory blurEffectFactory = _compositor.CreateEffectFactory(blurEffect);
            CompositionEffectBrush   blurBrush         = blurEffectFactory.CreateBrush();

            // Create a BackdropBrush and bind it to the EffectSourceParameter “source”
            CompositionBackdropBrush backdropBrush = _compositor.CreateBackdropBrush();

            blurBrush.SetSourceParameter("source", backdropBrush);

            _blurSprite.Brush = blurBrush;
        }
Example #2
0
        private void setupBlurEffect()
        {
            Compositor compositor = Window.Current.Compositor;

            GaussianBlurEffect blurEffect = new GaussianBlurEffect()
            {
                BlurAmount   = BlurAmount,
                BorderMode   = EffectBorderMode.Soft,
                Optimization = EffectOptimization.Balanced,
                Source       = new ArithmeticCompositeEffect()
                {
                    MultiplyAmount = 0,
                    Source1Amount  = .7f,
                    Source2Amount  = .3f,
                    Source1        = new CompositionEffectSourceParameter("backdrop"),
                    // Source2 = new CompositionEffectSourceParameter("backdrop")
                    Source2 = new ColorSourceEffect()
                    {
                        Color = BlurColor
                    }
                }
            };

            var backdropBrush = compositor.CreateHostBackdropBrush();

            CompositionEffectFactory effectFacotory = compositor.CreateEffectFactory(blurEffect);
            var blurBrush = effectFacotory.CreateBrush();

            blurBrush.SetSourceParameter("backdrop", backdropBrush);

            CompositionBrush = blurBrush;
        }
Example #3
0
        public BackDrop()
        {
            visual        = ElementCompositionPreview.GetElementVisual(this);
            compositor    = visual.Compositor;
            blurredVisual = compositor.CreateSpriteVisual();

            var graphicsEffect = new BlendEffect
            {
                Mode       = BlendEffectMode.HardLight,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Color.FromArgb(175, 0, 0, 0),
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name         = "Blur",
                    Source       = new CompositionEffectSourceParameter("source"),
                    BlurAmount   = 10f,
                    Optimization = EffectOptimization.Balanced,
                    BorderMode   = EffectBorderMode.Hard,
                }
            };

            effectFactory = compositor.CreateEffectFactory(graphicsEffect);
            var effectBrush = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("source", compositor.CreateBackdropBrush());

            blurredVisual.Brush = effectBrush;
            ElementCompositionPreview.SetElementChildVisual(this, blurredVisual);

            this.SizeChanged += BackDrop_SizeChanged;
        }
Example #4
0
        public void UpdateLightingEffect_DistantDiffuse(float AmbientAmount  = 0, float DiffuseAmount    = .5f,
                                                        float SpecularAmount = 0, string NormalMapSource = "NormalMap", bool forceUpdate = false, BrushType brushType = BrushType.Flat)
        {
            //_currentBrushType = brushType;
            var sceneLightingEffect = new SceneLightingEffect()
            {
                AmbientAmount   = AmbientAmount,
                DiffuseAmount   = DiffuseAmount,
                SpecularAmount  = SpecularAmount,
                NormalMapSource = new CompositionEffectSourceParameter(NormalMapSource),
            };

            IGraphicsEffect graphicsEffect = new CompositeEffect()
            {
                Mode    = CanvasComposite.Add,
                Sources =
                {
                    new CompositionEffectSourceParameter("ImageSource"),
                    sceneLightingEffect
                }
            };

            _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);


            if (forceUpdate)
            {
                UpdateEffectBrush(_currentBrushType);
            }
        }
Example #5
0
        private void Initialize()
        {
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;

            _frostEffect = new GaussianBlurEffect {
                Name         = "Blur",
                BlurAmount   = 0.0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter("backdropBrush")
            };

            // Create an instance of the effect and set its source to a CompositionBackdropBrush
            _effectFactory = _compositor.CreateEffectFactory(_frostEffect);
            _backdropBrush = _compositor.CreateHostBackdropBrush();
            _effectBrush   = _effectFactory.CreateBrush();

            // Create a Visual to contain the frosted glass effect
            _frostVisual       = _compositor.CreateSpriteVisual();
            _frostVisual.Brush = _effectBrush;
            _frostVisual.Size  = new Vector2((float)ActualWidth, (float)ActualHeight);

            _effectBrush.SetSourceParameter("backdropBrush", _backdropBrush);

            // Add the blur as a child of the host in the visual tree
            ElementCompositionPreview.SetElementChildVisual(this, _frostVisual);
        }
Example #6
0
        private void Department_Loaded(object sender, RoutedEventArgs e)
        {
            effectVisual = compositor.CreateSpriteVisual();
            var destinationBrush = compositor.CreateBackdropBrush();
            //Create the Effect you want
            var graphicsEffect = new GaussianBlurEffect
            {
                Name         = "Blur",
                BlurAmount   = 0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter("Background")
            };



            effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
            effectBrush   = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Background", destinationBrush);

            effectVisual.Brush = effectBrush;
            effectVisual.Size  = new System.Numerics.Vector2(900, 400);

            ElementCompositionPreview.SetElementChildVisual(CoverImage, effectVisual);

            //Create Spring Animation for nature increase and decrease value
            _springAnimation        = compositor.CreateSpringScalarAnimation();
            _springAnimation.Period = TimeSpan.FromSeconds(0.70);
            //_springAnimation.DampingRatio = 0.25f;
        }
Example #7
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //Create Visual to contain effect
            effectVisual = compositor.CreateSpriteVisual();
            var destinationBrush = compositor.CreateBackdropBrush();
            //Create the Effect you want
            var graphicsEffect = new GaussianBlurEffect
            {
                Name       = "Blur",
                BlurAmount = 0f,
                BorderMode = EffectBorderMode.Hard,
                Source     = new CompositionEffectSourceParameter("Background")
            };



            effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
            effectBrush   = effectFactory.CreateBrush();
            effectBrush.SetSourceParameter("Background", destinationBrush);

            effectVisual.Brush = effectBrush;
            //By the default the Visual have the size width and height (defined in Vector 2) 0 and 0
            ResizeVisual();

            ElementCompositionPreview.SetElementChildVisual(Back, effectVisual);

            //Create Spring Animation for nature increase and decrease value
            _springAnimation              = compositor.CreateSpringScalarAnimation();
            _springAnimation.Period       = TimeSpan.FromSeconds(0.5);
            _springAnimation.DampingRatio = 0.75f;
        }
        private Visual MakeImageVisualforFollower(Uri imageUri, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            CompositeEffect maskComposite = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();

            maskComposite.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskComposite.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskComposite.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskComposite.Name = "Mask";

            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskComposite);

            CompositionEffect maskEffect = effectFactory.CreateEffect();

            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();

            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size   = size;

            return(profileImageVisual);
        }
Example #9
0
        /// <inheritdoc cref="XamlCompositionBrushBase"/>
        protected override void OnConnected()
        {
            if (CompositionBrush == null)
            {
                // Effects setup
                SceneLightingEffect sceneLightingEffect = new SceneLightingEffect // Base lighting effect
                {
                    Name           = "Light",
                    SpecularShine  = (float)SpecularShine,
                    SpecularAmount = (float)SpecularAmount,
                    DiffuseAmount  = (float)DiffuseAmount,
                    AmbientAmount  = 0
                };
                _LuminanceEffect = new LuminanceToAlphaEffect {
                    Source = sceneLightingEffect
                };                                                                              // Map the bright areas of the light to an opacity mask
                _InverseEffect = new InvertEffect {
                    Source = _LuminanceEffect
                };                                                               // Invert the colors to make the brighter areas white
                _Factory = Window.Current.Compositor.CreateEffectFactory(_InverseEffect, new[] { "Light.DiffuseAmount", "Light.SpecularShine", "Light.SpecularAmount" });

                // Create and store the brush
                _Brush           = _Factory.CreateBrush();
                CompositionBrush = _Brush;
            }
            base.OnConnected();
        }
        private void AddImageVisualForFollower(Uri imageUri, Vector3 offset, Vector2 size)
        {
            //Load profile image into a CompositionImage
            CompositionImage profileImage =
                _compositor.DefaultGraphicsDevice.CreateImageFromUri(imageUri);

            CompositionImage maskImage = _compositor.DefaultGraphicsDevice.CreateImageFromUri(new Uri("ms-appx:///Assets/CircularAlphaMaskInflated.png"));

            //Configure effect graph
            CompositeEffect maskCompositEffectDescription = new Microsoft.Graphics.Canvas.Effects.CompositeEffect();

            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("image"));
            maskCompositEffectDescription.Sources.Add(new CompositionEffectSourceParameter("maskImage"));
            maskCompositEffectDescription.Mode = Microsoft.Graphics.Canvas.CanvasComposite.DestinationIn;
            maskCompositEffectDescription.Name = "Mask";

            //Create an effect factory for the graph
            CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(maskCompositEffectDescription);

            //Create an instance of the effect and set source parameters
            CompositionEffect maskEffect = effectFactory.CreateEffect();

            maskEffect.SetSourceParameter("image", profileImage);
            maskEffect.SetSourceParameter("maskImage", maskImage);

            //Add main profile picture visual
            EffectVisual profileImageVisual = _compositor.CreateEffectVisual();

            profileImageVisual.Effect = maskEffect;
            profileImageVisual.Size   = size;
            profileImageVisual.Offset = offset;

            //Add ImageVisual to tree
            _rootVisual.Children.InsertAtTop(profileImageVisual);
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            _compositor       = ElementCompositionPreview.GetElementVisual(this)?.Compositor;
            _visual           = ElementCompositionPreview.GetElementVisual(Image);
            _pointLight       = _compositor.CreatePointLight();
            _pointLight.Color = Colors.White;

            var graphicsEffect = new CompositeEffect
            {
                Mode    = CanvasComposite.Add,
                Sources =
                {
                    new CompositionEffectSourceParameter("ImageSource"),
                    new SceneLightingEffect()
                    {
                        AmbientAmount  = 0,
                        DiffuseAmount  = .75f,
                        SpecularAmount = 0,
                    }
                }
            };

            _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

            var lightRootVisual = ElementCompositionPreview.GetElementVisual(this);

            _pointLight.CoordinateSpace = lightRootVisual;
            _pointLight.Targets.Add(lightRootVisual);

            var brush = _effectFactory.CreateBrush();

            PointerMoved += Lighting_PointerMoved;
        }
        protected override void OnConnected()
        {
            // return if Uri String is null or empty
            if (String.IsNullOrEmpty(ImageUriString))
            {
                return;
            }

            Compositor compositor = Window.Current.Compositor;

            // Use LoadedImageSurface API to get ICompositionSurface from image uri provided
            _surface = LoadedImageSurface.StartLoadFromUri(new Uri(ImageUriString));

            // Load Surface onto SurfaceBrush
            _surfaceBrush         = compositor.CreateSurfaceBrush(_surface);
            _surfaceBrush.Stretch = CompositionStretch.UniformToFill;

            // CompositionCapabilities: Are Tint+Temperature and Saturation supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            if (usingFallback)
            {
                // If Effects are not supported, Fallback to image without effects
                CompositionBrush = _surfaceBrush;
                return;
            }

            // Define Effect graph
            IGraphicsEffect graphicsEffect = new SaturationEffect
            {
                Name       = "Saturation",
                Saturation = 0.3f,
                Source     = new TemperatureAndTintEffect
                {
                    Name        = "TempAndTint",
                    Temperature = 0,
                    Source      = new CompositionEffectSourceParameter("Surface"),
                }
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "TempAndTint.Temperature" });
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("Surface", _surfaceBrush);

            // Set EffectBrush to paint Xaml UIElement
            CompositionBrush = effectBrush;

            // Trivial looping animation to demonstrate animated effect
            ScalarKeyFrameAnimation tempAnim = compositor.CreateScalarKeyFrameAnimation();

            tempAnim.InsertKeyFrame(0, 0);
            tempAnim.InsertKeyFrame(0.5f, 1f);
            tempAnim.InsertKeyFrame(1, 0);
            tempAnim.Duration          = TimeSpan.FromSeconds(5);
            tempAnim.IterationBehavior = Windows.UI.Composition.AnimationIterationBehavior.Forever;
            effectBrush.Properties.StartAnimation("TempAndTint.Temperature", tempAnim);
        }
        async Task CreateTintEffectBrushAsync(Uri uri)
        {
            Xamarin.Forms.Image element = this.Element as Xamarin.Forms.Image;

            if (Control == null || Element == null || element.Width < 0 || element.Height < 0)
            {
                return;
            }

            SetupCompositor();

            spriteVisual      = compositor.CreateSpriteVisual();
            spriteVisual.Size = new Vector2((float)element.Width, (float)element.Height);

            imageSurface = await generator.CreateImageSurfaceAsync(uri, new Windows.Foundation.Size(element.Width, element.Height), ImageSurfaceOptions.DefaultOptimized);

            CompositionSurfaceBrush surfaceBrush = compositor.CreateSurfaceBrush(imageSurface.Surface);

            CompositionBrush targetBrush = surfaceBrush;

            if (this.TintColor == Color.Transparent)
            {
                // Don't apply tint effect
                effectBrush = null;
            }
            else
            {
                // Set target brush to tint effect brush

                Windows.UI.Color nativeColor = GetNativeColor(this.TintColor);

                IGraphicsEffect graphicsEffect = new CompositeEffect
                {
                    Mode    = CanvasComposite.DestinationIn,
                    Sources =
                    {
                        new ColorSourceEffect
                        {
                            Name  = "colorSource",
                            Color = nativeColor
                        },
                        new CompositionEffectSourceParameter("mask")
                    }
                };

                CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect,
                                                                                        new[] { "colorSource.Color" });

                effectBrush = effectFactory.CreateBrush();
                effectBrush.SetSourceParameter("mask", surfaceBrush);

                SetTint(nativeColor);

                targetBrush = effectBrush;
            }

            spriteVisual.Brush = targetBrush;
            ElementCompositionPreview.SetElementChildVisual(Control, spriteVisual);
        }
Example #14
0
        public static async Task <AttachedAnimatableCompositionEffect <T> > AttachCompositionAnimatableInAppCustomAcrylicEffectAsync <TSource, T>(
            [NotNull] this TSource element, [NotNull] T target,
            float on, float off, bool initiallyVisible,
            Color color, float colorMix, [CanBeNull] CanvasControl canvas, [NotNull] Uri uri,
            int timeThreshold = 1000, bool reload = false, bool disposeOnUnload = false)
            where TSource : FrameworkElement
            where T : FrameworkElement
        {
            // Get the compositor
            Visual visual = await DispatcherHelper.GetFromUIThreadAsync(element.GetVisual);

            Compositor compositor = visual.Compositor;

            // Create the blur effect and the effect factory
            CompositionBackdropBrush backdropBrush = compositor.CreateBackdropBrush();
            GaussianBlurEffect       blurEffect    = new GaussianBlurEffect
            {
                Name         = "Blur",
                BlurAmount   = 0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter(nameof(backdropBrush))
            };
            const String animationPropertyName = "Blur.BlurAmount";

            // Prepare the dictionary with the parameters to add
            IDictionary <String, CompositionBrush> sourceParameters = new Dictionary <String, CompositionBrush>
            {
                { nameof(backdropBrush), backdropBrush }
            };

            // Get the noise brush using Win2D
            IGraphicsEffect source = await AcrylicEffectHelper.ConcatenateEffectWithTintAndBorderAsync(compositor,
                                                                                                       blurEffect, sourceParameters, color, colorMix, canvas, uri, timeThreshold, reload);

            // Make sure the Win2D brush was loaded correctly
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(source, new[] { animationPropertyName });

            // Create the effect factory and apply the final effect
            CompositionEffectBrush effectBrush = effectFactory.CreateBrush();

            foreach (KeyValuePair <String, CompositionBrush> pair in sourceParameters)
            {
                effectBrush.SetSourceParameter(pair.Key, pair.Value);
            }

            // Assign the effect to a brush and display it
            SpriteVisual sprite = compositor.CreateSpriteVisual();

            sprite.Brush = effectBrush;
            await AddToTreeAndBindSizeAsync(target.GetVisual(), target, sprite);

            if (initiallyVisible)
            {
                await DispatcherHelper.RunOnUIThreadAsync(() => element.Opacity = 1);
            }
            return(new AttachedAnimatableCompositionEffect <T>(target, sprite, new CompositionAnimationParameters(animationPropertyName, on, off), disposeOnUnload));
        }
Example #15
0
 private void CreateEffect()
 {
     effect = new Microsoft.Graphics.Canvas.Effects.InvertEffect()
     {
         Name   = EffectName,
         Source = new CompositionEffectSourceParameter(EffectSource)
     };
     effectFactory = compositor.CreateEffectFactory(effect);
 }
Example #16
0
        public void UpdateLightingEffect_SpotLightSpecular(float AmbientAmount1    = 0.6f, float DiffuseAmount1        = 1f,
                                                           float SpecularAmount1   = 0, string NormalMapSource1        = "NormalMap", float AmbientAmount2 = 0,
                                                           float DiffuseAmount2    = 0f, float SpecularAmount2         = 1, float SpecularShine2           = 100f,
                                                           string NormalMapSource2 = "NormalMap", float InnerConeAngle = 15,
                                                           float OuterConeAngle    = 10, bool forceUpdate = false, BrushType brushType = BrushType.Flat)
        {
            //_currentBrushType = brushType;
            IGraphicsEffect graphicsEffect = new CompositeEffect()
            {
                Mode    = CanvasComposite.DestinationIn,
                Sources =
                {
                    new ArithmeticCompositeEffect()
                    {
                        Source1Amount  = 1,
                        Source2Amount  = 1,
                        MultiplyAmount = 0,

                        Source1 = new ArithmeticCompositeEffect()
                        {
                            MultiplyAmount = 1,
                            Source1Amount  = 0,
                            Source2Amount  = 0,
                            Source1        = new CompositionEffectSourceParameter("ImageSource"),
                            Source2        = new SceneLightingEffect()
                            {
                                AmbientAmount   = AmbientAmount1,
                                DiffuseAmount   = DiffuseAmount1,
                                SpecularAmount  = SpecularAmount1,
                                NormalMapSource = new CompositionEffectSourceParameter(NormalMapSource1),
                            }
                        },
                        Source2 = new SceneLightingEffect()
                        {
                            AmbientAmount   = AmbientAmount2,
                            DiffuseAmount   = DiffuseAmount2,
                            SpecularAmount  = SpecularAmount2,
                            SpecularShine   = SpecularShine2,
                            NormalMapSource = new CompositionEffectSourceParameter(NormalMapSource2),
                        }
                    },
                    new CompositionEffectSourceParameter("NormalMap"),
                }
            };

            _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

            _spotLight.InnerConeAngle = (float)(Math.PI / InnerConeAngle);
            _spotLight.OuterConeAngle = (float)(Math.PI / OuterConeAngle);

            if (forceUpdate)
            {
                UpdateEffectBrush(_currentBrushType);
            }
        }
Example #17
0
        public static async Task <AttachedCompositeAnimatableCompositionEffect <T> > AttachCompositionAnimatableBlurAndSaturationEffectAsync <T>(
            [NotNull] this T element, float onBlur, float offBlur, float onSaturation, float offSaturation, bool initiallyVisible, bool disposeOnUnload = false)
            where T : FrameworkElement
        {
            // Get the compositor
            Visual visual = await DispatcherHelper.GetFromUIThreadAsync(element.GetVisual);

            Compositor compositor = visual.Compositor;

            // Create the blur effect, the saturation effect and the effect factory
            GaussianBlurEffect blurEffect = new GaussianBlurEffect
            {
                Name         = "Blur",
                BlurAmount   = 0f,
                BorderMode   = EffectBorderMode.Hard,
                Optimization = EffectOptimization.Balanced,
                Source       = new CompositionEffectSourceParameter("source")
            };
            SaturationEffect saturationEffect = new SaturationEffect
            {
                Name       = "SEffect",
                Saturation = initiallyVisible ? offSaturation : onSaturation,
                Source     = blurEffect
            };
            const String             blurParameter = "Blur.BlurAmount", saturationParameter = "SEffect.Saturation";
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(saturationEffect, new[]
            {
                blurParameter,
                saturationParameter
            });

            // Setup the rest of the effect
            CompositionEffectBrush effectBrush = effectFactory.CreateBrush();

            effectBrush.SetSourceParameter("source", compositor.CreateBackdropBrush());

            // Assign the effect to a brush and display it
            SpriteVisual sprite = compositor.CreateSpriteVisual();

            sprite.Brush = effectBrush;
            await AddToTreeAndBindSizeAsync(visual, element, sprite);

            if (initiallyVisible)
            {
                await DispatcherHelper.RunOnUIThreadAsync(() => element.Opacity = 1);
            }

            // Prepare and return the wrapped effect
            return(new AttachedCompositeAnimatableCompositionEffect <T>(element, sprite,
                                                                        new Dictionary <String, CompositionAnimationValueParameters>
            {
                { blurParameter, new CompositionAnimationValueParameters(onBlur, offBlur) },
                { saturationParameter, new CompositionAnimationValueParameters(onSaturation, offSaturation) }
            }, disposeOnUnload));
        }
        protected override void OnConnected()
        {
            Compositor compositor = Window.Current.Compositor;

            // CompositionCapabilities: Are Effects supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            if (usingFallback)
            {
                // If Effects are not supported, use Fallback Solid Color
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                return;
            }

            // Define Effect graph
            var graphicsEffect = new BlendEffect
            {
                Mode       = BlendEffectMode.LinearBurn,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Windows.UI.Colors.Silver,
                },
                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 0,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount" });
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            // Create BackdropBrush
            CompositionBackdropBrush backdrop = compositor.CreateBackdropBrush();

            effectBrush.SetSourceParameter("backdrop", backdrop);

            // Trivial looping animation to demonstrate animated effects
            TimeSpan _duration = TimeSpan.FromSeconds(5);
            ScalarKeyFrameAnimation blurAnimation = compositor.CreateScalarKeyFrameAnimation();

            blurAnimation.InsertKeyFrame(0, 0);
            blurAnimation.InsertKeyFrame(0.5f, 10f);
            blurAnimation.InsertKeyFrame(1, 0);
            blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
            blurAnimation.Duration          = _duration;
            effectBrush.Properties.StartAnimation("Blur.BlurAmount", blurAnimation);

            // Set EffectBrush to paint Xaml UIElement
            CompositionBrush = effectBrush;
        }
Example #19
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.SaturationEffect()
            {
                Name       = EffectName,
                Saturation = 0.0f,
                Source     = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateLevel();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { SaturationEffectPath });
        }
Example #20
0
 private void CreateEffect()
 {
     effect = new Microsoft.Graphics.Canvas.Effects.ShadowEffect()
     {
         Name        = EffectName,
         BlurAmount  = 1.5f,
         ShadowColor = Colors.Black,
         Source      = new CompositionEffectSourceParameter(EffectSource)
     };
     //Level = 1.5d;
     //UpdateLevel();
     effectFactory = compositor.CreateEffectFactory(effect, new[] { BlurEffectPath });
 }
Example #21
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.GammaTransferEffect()
            {
                Name          = EffectName,
                BlueExponent  = 1.0f,
                GreenExponent = 1.0f,
                RedExponent   = 1.0f,
                Source        = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateRedExponent();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { BlueExponentEffectPath, GreenExponentEffectPath, RedExponentEffectPath });
        }
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.TemperatureAndTintEffect()
            {
                Name        = EffectName,
                Temperature = 0f,
                Tint        = 0f,
                Source      = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateTemperature();
            UpdateTint();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { TemperatureEffectPath, TintEffectPath });
        }
Example #23
0
        /// <summary>
        /// Returns the effect brush for this model. If a brush has not beeen created, one is created
        /// given CreateEffectFactory has been assigned.
        /// </summary>
        /// <returns>CompositionEffectBrush</returns>
        public CompositionEffectBrush GetEffectBrush()
        {
            if (_brush == null && CreateEffectFactory != null)
            {
                if (_factory == null)
                {
                    _factory = CreateEffectFactory();
                }

                _brush = _factory.CreateBrush();
            }

            return _brush;
        }
Example #24
0
        /// <summary>
        /// Returns the effect brush for this model. If a brush has not beeen created, one is created
        /// given CreateEffectFactory has been assigned.
        /// </summary>
        /// <returns>CompositionEffectBrush</returns>
        public CompositionEffectBrush GetEffectBrush()
        {
            if (_brush == null && CreateEffectFactory != null)
            {
                if (_factory == null)
                {
                    _factory = CreateEffectFactory();
                }

                _brush = _factory.CreateBrush();
            }

            return(_brush);
        }
Example #25
0
        ScalarKeyFrameAnimation imageFlipAnimation, textFlipAnimation;     //MediaTransport Image, Textbox animations

        void setupAnimations()
        {
            visual        = ElementCompositionPreview.GetElementVisual(this);
            compositor    = visual.Compositor;
            blurredVisual = compositor.CreateSpriteVisual();
            imageFactory  = CompositionImageFactory.CreateCompositionImageFactory(compositor);

            var graphicsEffect = new BlendEffect
            {
                Mode       = BlendEffectMode.HardLight,
                Background = new ColorSourceEffect()
                {
                    Name  = "Tint",
                    Color = Color.FromArgb(200, 0, 0, 0),
                },

                Foreground = new GaussianBlurEffect()
                {
                    Name         = "Blur",
                    Source       = new CompositionEffectSourceParameter("source"),
                    BlurAmount   = 20.0f,
                    Optimization = EffectOptimization.Balanced,
                    BorderMode   = EffectBorderMode.Hard,
                }
            };

            effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "Blur.BlurAmount", "Tint.Color" });

            fadeOutAnimation = compositor.CreateScalarKeyFrameAnimation();
            fadeOutAnimation.InsertExpressionKeyFrame(0.0f, "1");
            fadeOutAnimation.InsertExpressionKeyFrame(1f, "0");
            fadeOutAnimation.Duration = TimeSpan.FromMilliseconds(500);

            fadeInAnimation = compositor.CreateScalarKeyFrameAnimation();
            fadeInAnimation.InsertExpressionKeyFrame(0.0f, "0");
            fadeInAnimation.InsertExpressionKeyFrame(1f, "1");
            fadeInAnimation.Duration = TimeSpan.FromMilliseconds(500);

            imageFlipAnimation = compositor.CreateScalarKeyFrameAnimation();
            imageFlipAnimation.InsertExpressionKeyFrame(0.0f, "-60");
            imageFlipAnimation.InsertExpressionKeyFrame(1f, "0");
            imageFlipAnimation.Duration = TimeSpan.FromMilliseconds(500);

            textFlipAnimation = compositor.CreateScalarKeyFrameAnimation();
            textFlipAnimation.InsertExpressionKeyFrame(0.0f, "-90");
            textFlipAnimation.InsertExpressionKeyFrame(1f, "0");
            textFlipAnimation.Duration = TimeSpan.FromMilliseconds(300);
        }
Example #26
0
        private void OnLayerChanged(object sender, string property)
        {
            try
            {
                IGraphicsEffect          effectGraph   = Layer.GenerateEffectGraph(true);
                CompositionEffectFactory effectFactory = _previewSprite.Compositor.CreateEffectFactory(effectGraph, null);
                _previewSprite.Brush = effectFactory.CreateBrush();
                Layer.UpdateResourceBindings((CompositionEffectBrush)_previewSprite.Brush);
            }
            catch
            {
                _previewSprite.Brush = null;
            }

            LayerDescription.Text = Layer.Description;
        }
Example #27
0
        protected override void OnConnected()
        {
            Compositor compositor = Window.Current.Compositor;

            // CompositionCapabilities: Are Effects supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsSupported();

            FallbackColor = Color.FromArgb(100, 100, 100, 100);

            if (usingFallback)
            {
                // If Effects are not supported, use Fallback Solid Color
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                return;
            }

            // Define Effect graph
            var graphicsEffect = new BlendEffect
            {
                Mode       = BlendEffectMode.SoftLight,
                Background = new ColorSourceEffect()
                {
                    Name = "Tint",
                    //Color = Color.FromArgb(180, 255, 255, 255),
                    Color = Color.FromArgb(150, 255, 255, 255),
                },
                Foreground = new GaussianBlurEffect()
                {
                    Name       = "Blur",
                    Source     = new CompositionEffectSourceParameter("Backdrop"),
                    BlurAmount = 20,
                    BorderMode = EffectBorderMode.Hard,
                }
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect);
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            // Create BackdropBrush
            CompositionBackdropBrush backdrop = compositor.CreateBackdropBrush();

            effectBrush.SetSourceParameter("Backdrop", backdrop);

            // Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement
            CompositionBrush = effectBrush;
        }
Example #28
0
        override protected void OnConnected()
        {
            Compositor compositor = Window.Current.Compositor;

            // CompositionCapabilities: Are HostBackdrop Effects supported?
            bool usingFallback = !CompositionCapabilities.GetForCurrentView().AreEffectsFast();

            if (usingFallback)
            {
                // If Effects are not supported, use Fallback Solid Color
                CompositionBrush = compositor.CreateColorBrush(FallbackColor);
                return;
            }

            // Define Effect graph
            var graphicsEffect = new BlendEffect
            {
                Mode       = BlendEffectMode.Overlay,
                Background = new CompositionEffectSourceParameter("Backdrop"),
                Foreground = new ColorSourceEffect()
                {
                    Name  = "OverlayColor",
                    Color = OverlayColor,
                },
            };

            // Create EffectFactory and EffectBrush
            CompositionEffectFactory effectFactory = compositor.CreateEffectFactory(graphicsEffect, new[] { "OverlayColor.Color" });
            CompositionEffectBrush   effectBrush   = effectFactory.CreateBrush();

            // Create HostBackdropBrush, a kind of BackdropBrush that provides blurred backdrop content
            CompositionBackdropBrush hostBrush = compositor.CreateHostBackdropBrush();

            effectBrush.SetSourceParameter("Backdrop", hostBrush);

            // Set EffectBrush as the brush that XamlCompBrushBase paints onto Xaml UIElement
            CompositionBrush = effectBrush;

            // When the Window loses focus, animate HostBackdrop to FallbackColor
            Window.Current.CoreWindow.Activated += CoreWindow_Activated;

            // Configure color animation to for state change
            _stateChangeAnimation = compositor.CreateColorKeyFrameAnimation();
            _stateChangeAnimation.InsertKeyFrame(0, OverlayColor);
            _stateChangeAnimation.InsertKeyFrame(1, FallbackColor);
            _stateChangeAnimation.Duration = TimeSpan.FromSeconds(1);
        }
        private async void UpdateBrush()
        {
            if (_layerInvalidated)
            {
                // Clear the old brush
                _effectBrush = null;

                IGraphicsEffect effecGraph = _groupLayer.GenerateEffectGraph(false);
                if (effecGraph != null)
                {
                    try
                    {
                        CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(effecGraph, null);
                        _effectBrush = effectFactory.CreateBrush();

                        foreach (Layer layer in _groupLayer.Layers)
                        {
                            if (layer.Enabled)
                            {
                                layer.UpdateResourceBindings(_effectBrush);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ContentDialog dialog = new ContentDialog()
                        {
                            Title                    = "Failed to create effect",
                            Content                  = String.Format("The effect creation failed with the following error.  Please simplify your material.\r\n\r\n\"{0}\"", e.Message.ToString().Replace("\r\n", " ")),
                            PrimaryButtonText        = "OK",
                            IsSecondaryButtonEnabled = false,
                        };

                        await dialog.ShowAsync();

                        // Clear out the old effect
                        _effectBrush = null;
                    }

                    // Clear the flag
                    _layerInvalidated = false;
                }

                _brushChangedHandler(this);
            }
        }
        private static CompositionBrush CreateGrayscaleBrush()
        {
            Matrix5x4 grayscaleMatrix = CreateGrayscaleMatrix();

            ColorMatrixEffect grayscaleMatrixEffect = new ColorMatrixEffect
            {
                ColorMatrix = grayscaleMatrix,
                Source      = new CompositionEffectSourceParameter("source")
            };

            CompositionEffectFactory grayscaleEffectFactory = _compositor.CreateEffectFactory(grayscaleMatrixEffect);
            var backdropBrush = grayscaleEffectFactory.CreateBrush();

            backdropBrush.SetSourceParameter("source", _compositor.CreateBackdropBrush());

            return(backdropBrush);
        }
Example #31
0
        private void InitializeFrostedGlass(float width, float height, Color color, float blurAmout, byte alpha, float multiply, float backAmout, float frontAmout)
        {
            Visual             hostedVisual = ElementCompositionPreview.GetElementVisual(glassGrid);
            Compositor         compositor   = hostedVisual.Compositor;
            GaussianBlurEffect blurEffect   = new GaussianBlurEffect()
            {
                BlurAmount = blurAmout,
                BorderMode = EffectBorderMode.Hard,
                Source     = new ArithmeticCompositeEffect()
                {
                    MultiplyAmount = multiply,
                    Source1Amount  = backAmout,
                    Source2Amount  = frontAmout,
                    Source1        = new CompositionEffectSourceParameter("BackBrush"),
                    Source2        = new ColorSourceEffect()
                    {
                        Color = Color.FromArgb(alpha, color.R, color.G, color.B)
                    }
                }
            };

            CompositionEffectFactory factory = compositor.CreateEffectFactory(blurEffect);
            CompositionBackdropBrush backdropBrush;

            if (Hosted)
            {
                backdropBrush = compositor.CreateHostBackdropBrush();
            }
            else
            {
                backdropBrush = compositor.CreateBackdropBrush();
            }
            CompositionEffectBrush brush = factory.CreateBrush();

            brush.SetSourceParameter("BackBrush", backdropBrush);

            SpriteVisual glassVisual = compositor.CreateSpriteVisual();

            glassVisual.Size = new Vector2()
            {
                X = width,
                Y = height
            };
            glassVisual.Brush = brush;
            ElementCompositionPreview.SetElementChildVisual(glassGrid, glassVisual);
        }
Example #32
0
        private void CreateEffect()
        {
            effect = new SaturationEffect()
            {
                Name = SaturationEffect,
                Saturation = 0.0f,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateLevel();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { SaturationEffectPath });
        }
Example #33
0
        public static void Initialize(Compositor compositor)
        {
            s_random = new Random();
            s_compositor = compositor;

            // Create a animatable desaturation effect description

            var effectDesc = new SaturationEffect();
            effectDesc.Name = "myEffect";
            effectDesc.Source = new CompositionEffectSourceParameter("Image");

            s_saturationEffectFactory = compositor.CreateEffectFactory(
                effectDesc,
                new string[] { "myEffect.Saturation" });
        }
Example #34
0
        public static void Uninitialize()
        {
            s_saturationEffectFactory = null;

            s_compositor = null;
        }
Example #35
0
 public void Uninitialize()
 {
     effectFactory = null;
     compositor = null;
 }
Example #36
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.ExposureEffect()
            {
                Name = EffectName,
                Exposure = 0.0f,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateLevel();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { ExposureEffectPath });
        }
Example #37
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.TemperatureAndTintEffect()
            {
                Name = EffectName,
                Temperature = 0f,
                Tint = 0f,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateTemperature();
            UpdateTint();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { TemperatureEffectPath, TintEffectPath });
        }
Example #38
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.SepiaEffect()
            {
                Name = EffectName,
                Intensity = 0.5f,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateLevel();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { IntensityEffectPath });
        }
        private void UpdateLightingEffect()
        {
            _ambientLight.Targets.RemoveAll();
            _pointLight.Targets.RemoveAll();
            _distantLight.Targets.RemoveAll();
            _spotLight.Targets.RemoveAll();

            ComboBoxItem item = LightingSelection.SelectedValue as ComboBoxItem;
            switch ((LightingTypes)item.Tag)
            {
                case LightingTypes.PointDiffuse:
                    {
                        //
                        // Result = Ambient +       Diffuse
                        // Result = (Image) + (.75 * Diffuse color)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.Add,
                            Sources =
                            {
                                new CompositionEffectSourceParameter("ImageSource"),
                                new SceneLightingEffect()
                                {
                                    AmbientAmount = 0,
                                    DiffuseAmount = .75f,
                                    SpecularAmount = 0,
                                    NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                }
                            }
                        };

                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        // Set the light coordinate space and add the target
                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _pointLight.CoordinateSpace = lightRoot;
                        _pointLight.Targets.Add(lightRoot);
                    }
                    break;

                case LightingTypes.PointSpecular:
                    {
                        //
                        // Result =    Ambient   +       Diffuse           +     Specular
                        // Result = (Image * .6) + (Image * Diffuse color) + (Specular color)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.DestinationIn,
                            Sources =
                            {
                                new ArithmeticCompositeEffect()
                                {
                                    Source1Amount = 1,
                                    Source2Amount = 1,
                                    MultiplyAmount = 0,

                                    Source1 = new ArithmeticCompositeEffect()
                                    {
                                        MultiplyAmount = 1,
                                        Source1Amount = 0,
                                        Source2Amount = 0,
                                        Source1 = new CompositionEffectSourceParameter("ImageSource"),
                                        Source2 = new SceneLightingEffect()
                                        {
                                            AmbientAmount = .6f,
                                            DiffuseAmount = 1f,
                                            SpecularAmount = 0f,
                                            NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                        }
                                    },
                                    Source2 = new SceneLightingEffect()
                                    {
                                        AmbientAmount = 0,
                                        DiffuseAmount = 0f,
                                        SpecularAmount = 1f,
                                        SpecularShine = 100,
                                        NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                    }
                                },
                                new CompositionEffectSourceParameter("NormalMap"),
                            }
                        };

                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        // Set the light coordinate space and add the target
                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _ambientLight.Targets.Add(lightRoot);
                        _pointLight.CoordinateSpace = lightRoot;
                        _pointLight.Targets.Add(lightRoot);
                    }
                    break;

                case LightingTypes.SpotLightDiffuse:
                    {
                        //
                        // Result = Ambient +      Diffuse
                        // Result =  Image  + (Diffuse color * .75)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.Add,
                            Sources =
                            {
                                new CompositionEffectSourceParameter("ImageSource"),
                                new SceneLightingEffect()
                                {
                                    AmbientAmount = 0,
                                    DiffuseAmount = .75f,
                                    SpecularAmount = 0,
                                    NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                }
                            }
                        };

                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        // Set the light coordinate space and add the target
                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _spotLight.CoordinateSpace = lightRoot;
                        _spotLight.Targets.Add(lightRoot);
                        _spotLight.InnerConeAngle = (float)(Math.PI / 15);
                        _spotLight.OuterConeAngle = (float)(Math.PI / 10);
                        _spotLight.Direction = new Vector3(0, 0, -1);
                    };
                    break;

                case LightingTypes.SpotLightSpecular:
                    {
                        //
                        // Result =    Ambient   +       Diffuse           +     Specular
                        // Result = (Image * .6) + (Image * Diffuse color) + (Specular color)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.DestinationIn,
                            Sources =
                            {
                                new ArithmeticCompositeEffect()
                                {
                                    Source1Amount = 1,
                                    Source2Amount = 1,
                                    MultiplyAmount = 0,

                                    Source1 = new ArithmeticCompositeEffect()
                                    {
                                        MultiplyAmount = 1,
                                        Source1Amount = 0,
                                        Source2Amount = 0,
                                        Source1 = new CompositionEffectSourceParameter("ImageSource"),
                                        Source2 = new SceneLightingEffect()
                                        {
                                            AmbientAmount = .6f,
                                            DiffuseAmount = 1f,
                                            SpecularAmount = 0f,
                                            NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                        }
                                    },
                                    Source2 = new SceneLightingEffect()
                                    {
                                        AmbientAmount = 0,
                                        DiffuseAmount = 0f,
                                        SpecularAmount = 1f,
                                        SpecularShine = 100,
                                        NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                    }
                                },
                                new CompositionEffectSourceParameter("NormalMap"),
                            }
                        };

                        // Create the effect factory
                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        // Set the light coordinate space and add the target
                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _ambientLight.Targets.Add(lightRoot);
                        _spotLight.CoordinateSpace = lightRoot;
                        _spotLight.Targets.Add(lightRoot);
                        _spotLight.InnerConeAngle = (float)(Math.PI / 15);
                        _spotLight.OuterConeAngle = (float)(Math.PI / 10);
                        _spotLight.Direction = new Vector3(0, 0, -1);
                    };
                    break;

                case LightingTypes.DistantDiffuse:
                    {
                        //
                        // Result = Ambient +       Diffuse
                        // Result = (Image) + (.5 * Diffuse color)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.DestinationIn,
                            Sources =
                            {
                                new CompositeEffect()
                                {
                                    Mode = CanvasComposite.Add,
                                    Sources =
                                    {
                                        new CompositionEffectSourceParameter("ImageSource"),
                                        new SceneLightingEffect()
                                        {
                                            AmbientAmount = 0,
                                            DiffuseAmount = .5f,
                                            SpecularAmount = 0,
                                            NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                        }
                                    }
                                },
                                new CompositionEffectSourceParameter("NormalMap"),
                            }
                        };

                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _distantLight.CoordinateSpace = lightRoot;
                        _distantLight.Targets.Add(lightRoot);
                    };
                    break;

                case LightingTypes.DistantSpecular:
                    {
                        //
                        // Result =          Diffuse        +    Specular
                        // Result = (Image * Diffuse color) + (Specular color)
                        //

                        IGraphicsEffect graphicsEffect = new CompositeEffect()
                        {
                            Mode = CanvasComposite.DestinationIn,
                            Sources =
                            {
                                new ArithmeticCompositeEffect()
                                {
                                    Source1Amount = 1,
                                    Source2Amount = 1,
                                    MultiplyAmount = 0,

                                    Source1 = new ArithmeticCompositeEffect()
                                    {
                                        MultiplyAmount = 1,
                                        Source1Amount = 0,
                                        Source2Amount = 0,
                                        Source1 = new CompositionEffectSourceParameter("ImageSource"),
                                        Source2 = new SceneLightingEffect()
                                        {
                                            AmbientAmount = .6f,
                                            DiffuseAmount = 1f,
                                            SpecularAmount = 0f,
                                            NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                        }
                                    },
                                    Source2 = new SceneLightingEffect()
                                    {
                                        AmbientAmount = 0,
                                        DiffuseAmount = 0f,
                                        SpecularAmount = 1f,
                                        SpecularShine = 100,
                                        NormalMapSource = new CompositionEffectSourceParameter("NormalMap"),
                                    }
                                },
                                new CompositionEffectSourceParameter("NormalMap"),
                            }
                        };

                        _effectFactory = _compositor.CreateEffectFactory(graphicsEffect);

                        Visual lightRoot = ElementCompositionPreview.GetElementVisual(ThumbnailList);
                        _distantLight.CoordinateSpace = lightRoot;
                        _distantLight.Targets.Add(lightRoot);
                    };
                    break;

                default:
                    break;
            }

            // Update the animations
            UpdateAnimations();

            // Update all the image to have the new effect
            UpdateEffectBrush();
        }
Example #40
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.GrayscaleEffect()
            {
                Name = EffectName,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            effectFactory = compositor.CreateEffectFactory(effect);
        }
Example #41
0
        private void CreateEffect()
        {
            effect = new Microsoft.Graphics.Canvas.Effects.GammaTransferEffect()
            {
                Name = EffectName,
                BlueExponent = 1.0f,
                GreenExponent = 1.0f,
                RedExponent = 1.0f,
                Source = new CompositionEffectSourceParameter(EffectSource)
            };

            UpdateRedExponent();
            effectFactory = compositor.CreateEffectFactory(effect, new[] { BlueExponentEffectPath, GreenExponentEffectPath, RedExponentEffectPath });
        }
Example #42
0
 private void CreateEffect()
 {
     effect = new Microsoft.Graphics.Canvas.Effects.ShadowEffect()
     {
         Name = EffectName,
         BlurAmount = 1.5f,
         ShadowColor = Colors.Black,
         Source = new CompositionEffectSourceParameter(EffectSource)
     };
     //Level = 1.5d;
     //UpdateLevel();
     effectFactory = compositor.CreateEffectFactory(effect, new[] { BlurEffectPath });
     
 }