private async void ApplyEffect(CompositionImage image) { Task <CompositionDrawingSurface> task = null; // If we've requested a load time effect input, kick it off now if (_currentTechnique.LoadTimeEffectHandler != null) { task = SurfaceLoader.LoadFromUri(image.Source, Size.Empty, _currentTechnique.LoadTimeEffectHandler); } // Create the new brush, set the inputs and set it on the image CompositionEffectBrush brush = _currentTechnique.CreateBrush(); brush.SetSourceParameter("ImageSource", image.SurfaceBrush); image.Brush = brush; // If we've got an active task, wait for it to finish if (task != null) { CompositionDrawingSurface effectSurface = await task; // Set the effect surface as input brush.SetSourceParameter("EffectSource", _compositor.CreateSurfaceBrush(effectSurface)); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { _backgroundImageVisual = _compositor.CreateSpriteVisual(); _imageContainer = _compositor.CreateContainerVisual(); _imageSurfaceBrush = _compositor.CreateSurfaceBrush(); _capabilities.Changed += HandleCapabilitiesChanged; ElementCompositionPreview.SetElementChildVisual(ImageCanvas, _imageContainer); // Load in image var uri = new Uri("ms-appx:///Assets/Landscapes/Landscape-7.jpg"); var surface = await SurfaceLoader.LoadFromUri(uri); var imageSurface = _compositor.CreateSurfaceBrush(surface); _imageSurfaceBrush.Surface = imageSurface.Surface; _imageSurfaceBrush.Stretch = CompositionStretch.Fill; _imageContainer.Size = new Vector2((float)ImageCanvas.ActualWidth, (float)ImageCanvas.ActualHeight); _imageContainer.Children.InsertAtTop(_backgroundImageVisual); UpdateVisualSizeAndPosition(); UpdateAlbumArt(); }
#pragma warning disable 1998 private async void OnLoading(FrameworkElement sender, object args) { this.SizeChanged += OnSizeChanged; OnSizeChanged(this, null); m_noiseBrush.Surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/noise.jpg")); m_noiseBrush.Stretch = CompositionStretch.UniformToFill; }
async private Task LoadImages() { _imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor); string[] imageNames = { "Photos/Pic06", "Photos/Pic30", "Photos/Pic39", "Landscapes/Landscape-7", "Landscapes/Landscape-8", "Landscapes/Landscape-9", "Landscapes/Landscape-12", "Photos/pic22", "Photos/Pic11" }; for (int i = 0; i < imageNames.Length; ++i) { var uri = new Uri($"ms-appx:///Assets/{imageNames[i]}.jpg"); var surface = await SurfaceLoader.LoadFromUri(uri); _imageSurfaces[i] = _compositor.CreateSurfaceBrush(surface); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { // Populate the light type combobox IList <ComboBoxItem> lightList = new List <ComboBoxItem>(); foreach (LightingTypes type in Enum.GetValues(typeof(LightingTypes))) { ComboBoxItem item = new ComboBoxItem(); item.Tag = type; item.Content = type.ToString(); lightList.Add(item); } LightingSelection.ItemsSource = lightList; LightingSelection.SelectedIndex = 0; // Get the current compositor _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; ThumbnailList.ItemsSource = Model.Items; // // Create the sperical normal map. The normals will give the appearance of a sphere, and the alpha channel is used // for masking off the rectangular edges. // CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/ThumbnailLighting/SphericalWithMask.png")); _circleNormalsBrush = _compositor.CreateSurfaceBrush(normalMap); _circleNormalsBrush.Stretch = CompositionStretch.Fill; // // Create the flat normal map with beveled edges. This should give the appearance of slanting of the surface along // the edges, flat in the middle. // normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/ThumbnailLighting/BeveledEdges.jpg")); _flatNormalsBrush = _compositor.CreateSurfaceBrush(normalMap); _flatNormalsBrush.Stretch = CompositionStretch.Fill; // Update the effect brushes now that the normal maps are available. UpdateEffectBrush(); }
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); }
private async void ShowCustomSplashScreen(Rect imageBounds) { Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; Vector2 windowSize = new Vector2((float)Window.Current.Bounds.Width, (float)Window.Current.Bounds.Height); // // Create a container visual to hold the color fill background and image visuals. // Configure this visual to scale from the center. // ContainerVisual container = compositor.CreateContainerVisual(); container.Size = windowSize; container.CenterPoint = new Vector3(windowSize.X, windowSize.Y, 0) * .5f; ElementCompositionPreview.SetElementChildVisual(this, container); // // Create the colorfill sprite for the background, set the color to the same as app theme // SpriteVisual backgroundSprite = compositor.CreateSpriteVisual(); backgroundSprite.Size = windowSize; backgroundSprite.Brush = compositor.CreateColorBrush(Color.FromArgb(1, 0, 178, 240)); container.Children.InsertAtBottom(backgroundSprite); // // Create the image sprite containing the splash screen image. Size and position this to // exactly cover the Splash screen image so it will be a seamless transition between the two // CompositionDrawingSurface surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/SplashScreen.png")); SpriteVisual imageSprite = compositor.CreateSpriteVisual(); imageSprite.Brush = compositor.CreateSurfaceBrush(surface); imageSprite.Offset = new Vector3((float)imageBounds.X, (float)imageBounds.Y, 0f); imageSprite.Size = new Vector2((float)imageBounds.Width, (float)imageBounds.Height); container.Children.InsertAtTop(imageSprite); }
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 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 async void CreateImageAndLights(Vector2 sizeLightBounds) { // // Image and effect setup // // Create the effect graph. We will combine the desaturated image with two diffuse lights IGraphicsEffect graphicsEffect = new CompositeEffect() { Mode = Microsoft.Graphics.Canvas.CanvasComposite.Add, Sources = { new SaturationEffect() { Saturation = 0, Source = new CompositionEffectSourceParameter("ImageSource") }, new PointDiffuseEffect() { Name = "Light1", DiffuseAmount = 1f, Source = new CompositionEffectSourceParameter("NormalMap"), }, new PointDiffuseEffect() { Name = "Light2", DiffuseAmount = 1f, Source = new CompositionEffectSourceParameter("NormalMap"), }, } }; // Create the normal map. For this sample, we want a flat surface with no bumps CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK Insider/NowPlaying/NormalMap.jpg")); CompositionSurfaceBrush surfaceBrush = _compositor.CreateSurfaceBrush(normalMap); surfaceBrush.Stretch = CompositionStretch.Fill; // Create the effect factory, we're going to animate the light positions and colors CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new[] { "Light1.LightPosition", "Light1.LightColor", "Light2.LightPosition", "Light2.LightColor", }); // Create the effect brush and bind the normal map CompositionEffectBrush brush = effectFactory.CreateBrush(); brush.SetSourceParameter("NormalMap", surfaceBrush); // Update the CompositionImage to use the custom effect brush ArtistImage.Brush = brush; // // Animation setup // // Setup the first light's position, top and to the left in general LinearEasingFunction linear = _compositor.CreateLinearEasingFunction(); Vector3KeyFrameAnimation positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(0f, 0f, 300f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .5f, sizeLightBounds.Y * .5f, 100f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .25f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(0f, 0f, 300f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightPosition", positionAnimation); // Setup the first light's color animation, cycling through some brighter tones ColorKeyFrameAnimation colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.Orange); colorAnimation.InsertKeyFrame(.2f, Colors.Orange); colorAnimation.InsertKeyFrame(.3f, Colors.Red); colorAnimation.InsertKeyFrame(.5f, Colors.Red); colorAnimation.InsertKeyFrame(.6f, Colors.Yellow); colorAnimation.InsertKeyFrame(.8f, Colors.Yellow); colorAnimation.InsertKeyFrame(.9f, Colors.Orange); colorAnimation.InsertKeyFrame(1f, Colors.Orange); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light1.LightColor", colorAnimation); // Setup the second light's position, down and to the right in general positionAnimation = _compositor.CreateVector3KeyFrameAnimation(); positionAnimation.InsertKeyFrame(0f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.InsertKeyFrame(.33f, new Vector3(sizeLightBounds.X * .7f, sizeLightBounds.Y * .9f, 300f), linear); positionAnimation.InsertKeyFrame(.66f, new Vector3(sizeLightBounds.X * .95f, sizeLightBounds.Y * .95f, 100f), linear); positionAnimation.InsertKeyFrame(1f, new Vector3(sizeLightBounds.X, sizeLightBounds.Y, 200f), linear); positionAnimation.Duration = TimeSpan.FromMilliseconds(20000); positionAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightPosition", positionAnimation); // Setup the second light's color animation, cycling through some darker tones colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0f, Colors.Blue); colorAnimation.InsertKeyFrame(.2f, Colors.Blue); colorAnimation.InsertKeyFrame(.3f, Colors.DarkGreen); colorAnimation.InsertKeyFrame(.5f, Colors.DarkGreen); colorAnimation.InsertKeyFrame(.6f, Colors.DarkBlue); colorAnimation.InsertKeyFrame(.8f, Colors.DarkBlue); colorAnimation.InsertKeyFrame(.9f, Colors.Blue); colorAnimation.InsertKeyFrame(1f, Colors.Blue); colorAnimation.Duration = TimeSpan.FromMilliseconds(20000); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; brush.StartAnimation("Light2.LightColor", colorAnimation); }
private async void LoadImageAsync(Compositor compositor) { var surface = await SurfaceLoader.LoadFromUri(imageUri); visual.Brush = compositor.CreateSurfaceBrush(surface); }
private async void LoadSurface() { // If we're clearing out the content, return if (_uri == null) { ReleaseSurface(); return; } try { // Start a timer to enable the placeholder image if requested if (_surface == null && _placeholderDelay >= TimeSpan.Zero) { _timer = new DispatcherTimer(); _timer.Interval = _placeholderDelay; _timer.Tick += Timer_Tick; _timer.Start(); } // Load the image asynchronously CompositionDrawingSurface surface = await SurfaceLoader.LoadFromUri(_uri, Size.Empty, _loadEffectDelegate); if (_surface != null) { ReleaseSurface(); } _surface = surface; // The surface has changed, so we need to re-measure with the new surface dimensions InvalidateMeasure(); // Async operations may take a while. If we've unloaded, return now. if (_unloaded) { ReleaseSurface(); return; } // Update the brush UpdateBrush(); // Success, fire the Opened event if (ImageOpened != null) { ImageOpened(this, null); } // // If we created the loading placeholder, now that the image has loaded // cross-fade it out. // if (_sprite != null && _sprite.Children.Count > 0) { Debug.Assert(_timer == null); StartCrossFade(); } else if (_timer != null) { // We didn't end up loading the placeholder, so just stop the timer _timer.Stop(); _timer = null; } } catch (FileNotFoundException) { if (ImageFailed != null) { ImageFailed(this, 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 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 async void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { ConstructWalls(); CompositionDrawingSurface normalMap = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Samples/SDK 14393/LightSpheres/SphericalWithMask.png")); CompositionSurfaceBrush normalBrush = _compositor.CreateSurfaceBrush(normalMap); LightControl1.Offset = new Vector3(-77, 21, -768); LightControl1.LightColor.Color = Color.FromArgb(255, 255, 255, 255); LightControl1.LinearAttenuation.Value = 29; LightControl1.ConstantAttenuation.Value = 50; LightControl2.QuadraticAttenuation.Value = 0; LightControl2.Offset = new Vector3(2047, 500, -676); LightControl2.LightColor.Color = Color.FromArgb(255, 255, 0, 255); LightControl2.LinearAttenuation.Value = 0; LightControl2.ConstantAttenuation.Value = 9; LightControl2.QuadraticAttenuation.Value = 100; // Create the colors for the spheres Color[] colors = new Color[] { Color.FromArgb(255, 60, 60, 60), // Black Color.FromArgb(255, 200, 200, 200), // White Color.FromArgb(255, 139, 255, 211), // Green Color.FromArgb(255, 160, 244, 255), // Blue Color.FromArgb(255, 253, 99, 105), // Red Color.FromArgb(255, 206, 181, 251), // Purple Color.FromArgb(255, 67, 228, 124), // Bright Green Color.FromArgb(255, 248, 216, 148), // Yellow Color.FromArgb(255, 228, 190, 198), // Mauve }; // Create the lighting effect for the spheres IGraphicsEffect graphicsEffect = new CompositeEffect() { Mode = CanvasComposite.DestinationIn, Sources = { new ArithmeticCompositeEffect() { Source1Amount = .9f, Source2Amount = 1f, MultiplyAmount = 0, Source1 = new ArithmeticCompositeEffect() { MultiplyAmount = .5f, Source1Amount = .5f, Source2Amount = 0f, Source1 = new ArithmeticCompositeEffect() { MultiplyAmount = 1f, Source1Amount = 0f, Source2Amount = 0f, Source1 = new ColorSourceEffect() { Name = "Color", }, Source2 = new SceneLightingEffect() { Name = "Ambient", AmbientAmount = 1f, DiffuseAmount = 0f, SpecularAmount = 0f, NormalMapSource = new CompositionEffectSourceParameter("ImageSource"), } }, Source2 = new SceneLightingEffect() { Name = "Diffuse", AmbientAmount = 0f, DiffuseAmount = 1f, SpecularAmount = 0f, NormalMapSource = new CompositionEffectSourceParameter("ImageSource"), } }, Source2 = new SceneLightingEffect() { Name = "Specular", AmbientAmount = 0, DiffuseAmount = 0f, SpecularAmount = .1f, SpecularShine = 5, NormalMapSource = new CompositionEffectSourceParameter("ImageSource"), } }, new CompositionEffectSourceParameter("ImageSource"), } }; CompositionEffectFactory effectFactory = _compositor.CreateEffectFactory(graphicsEffect, new string[] { "Color.Color", "Diffuse.DiffuseAmount", "Specular.SpecularAmount", "Specular.SpecularShine" }); // Create the spheres int xOffset = 0; foreach (Color color in colors) { CompositionEffectBrush brush = effectFactory.CreateBrush(); brush.Properties.InsertColor("Color.Color", color); brush.SetSourceParameter("ImageSource", normalBrush); _brushList.Add(brush); SpriteVisual sprite = _compositor.CreateSpriteVisual(); sprite.Brush = brush; sprite.Size = new Vector2(200, 200); sprite.Offset = new Vector3(xOffset, 0, 0) + _defaultSphereOffset; _sceneContainer.Children.InsertAtTop(sprite); _sphereList.Add(sprite); xOffset += _defaultSphereSpace; LightControl1.AddTargetVisual(sprite); LightControl2.AddTargetVisual(sprite); } UpdateAnimationState(); }
private async Task <CompositionBrush> GenerateCompositionBrush() { var surface = await SurfaceLoader.LoadFromUri(new Uri("ms-appx:///Assets/KKBOX.png")); return(compositor.CreateSurfaceBrush(surface)); }