Last active
October 12, 2017 16:03
-
-
Save terriblememory/cf5aa651c9e5238a7ae41df8a6b3734b to your computer and use it in GitHub Desktop.
UWP CompositionBrush containing a tiling noise texture, host backdrop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var compositor = Window.Current.Compositor; | |
var noiseUri = new System.Uri("ms-appx:///Assets/noisy-texture-256x256.png"); | |
var noiseSurface = LoadedImageSurface.StartLoadFromUri(noiseUri); | |
var noiseBrush = compositor.CreateSurfaceBrush(); | |
noiseBrush.Surface = noiseSurface; | |
noiseBrush.Stretch = CompositionStretch.None; | |
var composeNoiseAndBackgroundEffectDesc = new ArithmeticCompositeEffect() | |
{ | |
Source1 = new CompositionEffectSourceParameter("HostBackdropBrush"), | |
Source2 = new GaussianBlurEffect() | |
{ | |
Name = "Glass", | |
BlurAmount = 12, | |
BorderMode = EffectBorderMode.Soft, | |
Source = new BorderEffect() | |
{ | |
Name = "TiledNoise", | |
ExtendX = CanvasEdgeBehavior.Wrap, | |
ExtendY = CanvasEdgeBehavior.Wrap, | |
Source = new CompositionEffectSourceParameter("NoiseBrush") | |
} | |
}, | |
Source1Amount = 0.8f, | |
Source2Amount = 0.2f, | |
MultiplyAmount = 0.0f, | |
Offset = 0.0f | |
}; | |
var composeNoiseAndBackgroundEffectFactory = compositor.CreateEffectFactory(composeNoiseAndBackgroundEffectDesc); | |
var composeNoiseAndBackgroundBrush = composeNoiseAndBackgroundEffectFactory.CreateBrush(); | |
composeNoiseAndBackgroundBrush.SetSourceParameter("HostBackdropBrush", compositor.CreateHostBackdropBrush()); | |
composeNoiseAndBackgroundBrush.SetSourceParameter("NoiseBrush", noiseBrush); | |
CompositionBrush = composeNoiseAndBackgroundBrush; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment