async Task Canvas_CreateResourcesAsync(CanvasAnimatedControl sender) { bitmapTiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg"); tigerSize = bitmapTiger.Size.ToVector2(); // The Sketch shader has two input textures: // // - First is the image that will be processed by the sketch effect. // The sketch shader applies a 3x3 edge detection filter kernel to this input, // so we specify Offset coordinate mapping mode with a max offset of 1 dip. // // - Second is an overlay containing a pencil sketch texture. The JitterX and JitterY // properties offset this by randomly varying amounts, so we specify Unknown mapping // mode to indicate that the entire image must be made available to the shader. sketchEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Sketch.bin")) { Source1 = bitmapTiger, Source1BorderMode = EffectBorderMode.Hard, Source1Mapping = SamplerCoordinateMapping.Offset, MaxSamplerOffset = (int)Math.Ceiling(sender.Dpi / 96), Source2 = await CanvasBitmap.LoadAsync(sender, "Shaders/SketchTexture.jpg"), Source2Mapping = SamplerCoordinateMapping.Unknown }; sketchEffect.Properties["EdgeOffset"] = sender.Dpi / 96; // The Dissolve shader has two input textures: // // - The first is an image that will be dissolved away to nothing. // // - The second is a dissolve mask whose red channel controls the order in which pixels // of the first image disappear as the dissolveAmount property is animated. // // This example selects different dissolve masks depending on the CurrentEffect. dissolveEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Dissolve.bin")); // The Ripples shader has no input textures. // It generates an animatable series of concentric circles. // This is used as a mask input to the dissolveEffect. rippleEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Ripples.bin")); rippleEffect.Properties["frequency"] = 0.15f; rippleEffect.Properties["dpi"] = sender.Dpi; rippleEffect.Properties["center"] = tigerSize / 3; // Create other dissolve mask images. CreateTurbulence(); CreateLinearGradient(sender); CreateRadialGradient(sender); }
async Task Canvas_CreateResourcesAsync(CanvasVirtualControl sender) { mandelbrotEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Mandelbrot.bin")); // The Mandelbrot pixel shader outputs grayscale values. To make the result more interesting, // we run it through a TableTransferEffect. This applies a color gradient that goes from black // through blue, cyan, green, yellow, red, magenta, blue again, and finally back toward cyan. colorizeEffect = new TableTransferEffect { Source = mandelbrotEffect, RedTable = new float[] { 0, 0, 0, 0, 1, 1, 0.67f, 0, 0 }, GreenTable = new float[] { 0, 0, 1, 1, 1, 0, 0, 0, 0.5f }, BlueTable = new float[] { 0, 1, 1, 0, 0, 0, 1, 1, 1 }, }; }
async Task Canvas_CreateResourcesAsync(CanvasAnimatedControl sender) { bitmapTiger = await CanvasBitmap.LoadAsync(sender, "imageTiger.jpg"); tigerSize = bitmapTiger.Size.ToVector2(); // The Sketch shader has two input textures: // // - First is the image that will be processed by the sketch effect. // The sketch shader applies a 3x3 edge detection filter kernel to this input, // so we specify Offset coordinate mapping mode with a max offset of 1 dip. // // - Second is an overlay containing a pencil sketch texture. The JitterX and JitterY // properties offset this by randomly varying amounts, so we specify Unknown mapping // mode to indicate that the entire image must be made available to the shader. sketchEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Sketch.bin")) { Source1 = bitmapTiger, Source1BorderMode = EffectBorderMode.Hard, Source1Mapping = SamplerCoordinateMapping.Offset, MaxSamplerOffset = (int)Math.Ceiling(sender.Dpi / 96), Source2 = await CanvasBitmap.LoadAsync(sender, "Shaders/SketchTexture.jpg"), Source2Mapping = SamplerCoordinateMapping.Unknown }; sketchEffect.Properties["EdgeOffset"] = sender.Dpi / 96; // The Dissolve shader has two input textures: // // - The first is an image that will be dissolved away to nothing. // // - The second is a dissolve mask whose red channel controls the order in which pixels // of the first image disappear as the dissolveAmount property is animated. // // This example selects different dissolve masks depending on the CurrentEffect. dissolveEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Dissolve.bin")); // The Ripples shader has no input textures. // It generates an animatable series of concentric circles. // This is used as a mask input to the dissolveEffect. rippleEffect = new PixelShaderEffect(await Utils.ReadAllBytes("Shaders/Ripples.bin")); rippleEffect.Properties["frequency"] = 0.15f; rippleEffect.Properties["dpi"] = sender.Dpi; #if WINDOWS_UWP rippleEffect.Properties["center"] = tigerSize / 3; #else rippleEffect.Properties["center"] = (Microsoft.Graphics.Canvas.Numerics.Vector2)(tigerSize / 3); // When compiling for Windows 8.1, we must explicitly convert vector and matrix values // from System.Numerics to their Microsoft.Graphics.Canvas.Numerics equivalents before // passing them to PixelShaderEffect.Properties. This is not neccessary when targetting // UWP, which handles the conversion automatically. For more info, see the article: // http://blogs.msdn.com/b/win2d/archive/2015/06/02/winrt-vector-and-matrix-types-in-windows-10.aspx #endif // Create other dissolve mask images. CreateTurbulence(); CreateLinearGradient(sender); CreateRadialGradient(sender); }