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 },
            };
        }
Example #2
0
        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    },
            };
        }
Example #3
0
	    private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
	    {
			// blobs
			_blobs = new List<Blob>();
			var rnd = new Random();
		    for (int i = 0; i < BlobCount; i++)
		    {
			    _blobs.Add(new Blob
			    {
				    Position = new Vector2((float) (rnd.NextDouble()*sender.Size.Width), (float) (rnd.NextDouble()*sender.Size.Height)),
				    Velocity = new Vector2(BlobVelocityScale *  (float) ((rnd.NextDouble()*3.0f) - 1.5f), BlobVelocityScale * (float) ((rnd.NextDouble()*3.0f) - 1.5f))
			    });
		    }
			// texture
		    var rgb = new CanvasRadialGradientBrush(sender, new[]
		    {
				new CanvasGradientStop
				{
					Color = Color.FromArgb(255, 128, 128, 255),
					Position = 0.0f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(128, 128, 128, 255),
					Position = 0.6f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(0, 128, 128, 255),
					Position = 1.0f
				}
		    });
		    rgb.RadiusX = rgb.RadiusY = BlobSize;
		    _blobBrush = rgb;
			// table transfer table
			ttt = new List<float>();
			for (int i = 0; i < 100; i++)
			{
				ttt.Add(i < Threshold ? 0.0f : 1.0f);
			}
			// setup
			_blobRenderTarget = new CanvasRenderTarget(sender, sender.Size);
			_pre = new PremultiplyEffect {Source = _blobRenderTarget};
			_tte = new TableTransferEffect {ClampOutput = true, Source = _pre};
			_tte.AlphaTable = _tte.RedTable = _tte.GreenTable = _tte.BlueTable = ttt.ToArray();
			_un = new UnPremultiplyEffect {Source = _tte};
			_gbe = new GaussianBlurEffect {BlurAmount = 8.0f, Source = _un};
		    _mask = new CanvasImageBrush(sender) {SourceRectangle = new Rect(new Point(), sender.Size)};
	    }