private void InitializeResources() { m_tempLayer = m_presenter.Factory.CreateDrawingLayer(SCENE_WIDTH, SCENE_HEIGHT); m_tempLayer2 = m_presenter.Factory.CreateDrawingLayer(SCENE_WIDTH, SCENE_HEIGHT); m_drawingLayerBrush = m_presenter.Factory.CreateDrawingLayerBrush(m_tempLayer); m_drawingLayerBrush2 = m_presenter.Factory.CreateDrawingLayerBrush(m_tempLayer2); m_blurEffect = new BlurEffect(m_presenter.Factory); GradientStop[] stops = new GradientStop[3]; stops[0].Position = 0; stops[0].Color = new Color4(1f, 1, 0, 0); stops[1].Position = 0.5f; stops[1].Color = new Color4(1f, 0, 1, 0); stops[2].Position = 1f; stops[2].Color = new Color4(.1f, 0, 0, 1); m_gradientBrush = m_presenter.Factory.CreateLinearGradientBrush(stops, ExtendMode.Clamp, new PointF(0, 0), new PointF(SCENE_WIDTH, 0)); m_gradientBrush.Transform = new RotateTransform(); //m_paintingBrush = m_presenter.DirectCanvas.CreateRadialGradientBrush(stops, // ExtendMode.Clamp, // new PointF(500, 500), // new PointF(0, 0), // new SizeF(500, 500)); InitMediaPlayer(); }
public void Apply(RippleEffect effect, DrawingLayer sourceLayer, DrawingLayer targetLayer) { effect.Center = Center; effect.Amplitude = Amplitude; effect.Frequency = Frequency; effect.LightIntensity = LightIntensity; effect.Phase = Phase; sourceLayer.ApplyEffect(effect, targetLayer); }
private void InitializeResources() { m_tempLayer = m_presenter.Factory.CreateDrawingLayer(SCENE_WIDTH, SCENE_HEIGHT); m_bitmap = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\Radioactive.jpg"); m_cloudsBitmap = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\clouds.png"); m_mountainsBitmap = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\Nature Mountains photo.jpg"); m_transition = new RadialWiggleTransitionEffect(m_presenter.Factory); }
public GPGPUScene(Presenter presenter) { m_presenter = presenter; m_tempLayer = presenter.Factory.CreateDrawingLayer(width, height); m_workingLayer = presenter.Factory.CreateDrawingLayer(width, height); m_tempLayer.EnableImageCopy = true; m_workingLayer.EnableImageCopy = true; m_data1Image = presenter.Factory.CreateImage(@".\Assets\Nature Mountains photo.jpg"); //m_data1Image = presenter.Factory.CreateImage(width, height); m_gpgpuEffect = new GPGPUEffect(presenter.Factory); //LoadData(m_data1Image); }
private void InitializeResources() { var factory = m_mainLayer.Factory; /* Initialize the drawing layer using our hard coded dimensions */ m_tempLayer = factory.CreateDrawingLayer(SCENE_WIDTH, SCENE_HEIGHT); /* This will read an image from a file, create a DrawingLayer at the * same dimensions as the file, then copy the image to the DrawingLayer */ m_bitmap = factory.CreateDrawingLayerFromFile(@".\Assets\Radioactive.jpg"); /* Create a new ripple effect */ m_rippleEffect = new RippleEffect(factory); nullRipple = new RippleSettings() { Amplitude = 0f, LightIntensity = 0f }; }
/// <summary> /// Draws the video on to the main layer, using the opacity mask /// </summary> private void RenderVideoAndOpacityMask(DrawingLayer layer) { layer.BeginDraw(); /* Clear the old drawing layer*/ layer.Clear(); /* Scale the video brush to match the size of the layer */ m_videoBrush.Transform = new ScaleTransform { ScaleX = (float)layer.Width / m_player.NaturalSize.Width, ScaleY = (float)layer.Height / m_player.NaturalSize.Height }; /* Draws the contents of the video brush, using the given opacity mask, onto the layer. */ layer.FillOpacityMask(m_videoBrush, m_opacityMask, new RectangleF(0, 0, layer.Width, layer.Height), new RectangleF(0, 0, layer.Width, layer.Height)); layer.EndDraw(); }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeDrawingLayer(DrawingLayer layer, ref RectangleF sourceArea, ref RectangleF destinationArea, ref RotationParameters rotationTransform, ref Color4 tint) { m_drawStateManagement.DrawPreamble(); /* Get the current draw data to fill. We avoid creating new object instances * for the GC to have to delete */ var spriteRenderData = m_spriteRenderer.GetCurrentRenderData(); /* Copy all the primitive transform data to the spriteRenderData */ float xDestination = destinationArea.X; float yDestination = destinationArea.Y; spriteRenderData.drawData.Translation.X = xDestination; spriteRenderData.drawData.Translation.Y = yDestination; spriteRenderData.drawData.Rotate.X = rotationTransform.RotateX; spriteRenderData.drawData.Rotate.Y = rotationTransform.RotateY; spriteRenderData.drawData.Rotate.Z = rotationTransform.RotateZ; spriteRenderData.drawData.Scale.X = destinationArea.Width / sourceArea.Width; spriteRenderData.drawData.Scale.Y = destinationArea.Height / sourceArea.Height; spriteRenderData.drawData.DrawRect.X = sourceArea.X; spriteRenderData.drawData.DrawRect.Y = sourceArea.Y; spriteRenderData.drawData.DrawRect.Z = sourceArea.Width; spriteRenderData.drawData.DrawRect.W = sourceArea.Height; spriteRenderData.drawData.RotationCenter = rotationTransform.RotationCenter.InternalVector2; spriteRenderData.drawData.Color = tint.InternalColor4; spriteRenderData.texture = layer.RenderTargetTexture; /* Add (queue) the drawing data to the sprite renderer */ m_spriteRenderer.AddRenderData(spriteRenderData); }
private void InitD3DImage(int width, int height) { if (Application.Current == null || Application.Current.Dispatcher == null) return; var dispatcher = Application.Current.Dispatcher; if (!dispatcher.CheckAccess()) { dispatcher.Invoke((Action)delegate { InitD3DImage(width, height); }); return; } ReleaseResources(); m_width = width; m_height = height; rect = new RectangleF(0, 0, m_width, m_height); intRect = new Int32Rect(0, 0, m_width, m_height); if (m_d3dImage == null) { m_d3dImage = new D3DImageSlimDX(); m_d3dImage.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged; } m_layer1 = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); m_layer2 = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); SetBackBuffer(); }
private void Initialize() { SetupGeometry(); m_solidColorBrush = m_presenter.Factory.CreateSolidColorBrush(new Color4(1, 1, 1, 1)); m_bitmap = m_presenter.Factory.CreateDrawingLayerFromFile(@".\Assets\Nature Mountains photo.jpg"); m_bitmapBrush = m_presenter.Factory.CreateDrawingLayerBrush(m_bitmap); GradientStop[] stops = new GradientStop[3]; stops[0].Position = 0; stops[0].Color = new Color4(1f, 1, 0, 0); stops[1].Position = 0.5f; stops[1].Color = new Color4(1f, 0, 1, 0); stops[2].Position = 1f; stops[2].Color = new Color4(.1f, 0, 0, 1); m_gradientBrush = m_presenter.Factory.CreateLinearGradientBrush(stops, ExtendMode.Clamp, new PointF(0, 0), new PointF(SCENE_WIDTH, 0)); m_gradientBrush.Transform = new RotateTransform(); m_radialBrush = m_presenter.Factory.CreateRadialGradientBrush(stops, ExtendMode.Clamp, new PointF(500, 500), new PointF(0, 0), new SizeF(500, 500)); }
/// <summary> /// Creates the special drawing layer the presenter will use to render content /// </summary> /// <param name="width">Pixel width of the device</param> /// <param name="height">Pixel height of the device</param> private void CreateLayer(int width, int height) { /* Release any used resources. Other resources may * already exist if the presenter is being resized */ ReleaseResources(); /* This will be the main layer that content is written to */ m_layer = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); var sourceHandle = GetSharedHandle(m_layer.RenderTargetTexture.InternalTexture2D); m_sourceTexture = new Texture(m_device, width, height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default, ref sourceHandle); /* First blit layer. We need two layers to blit to * to avoid flickering in WPF. This is temporary until * we build proper syncronization of the rendering */ m_blitLayer = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.KeyedMutex); /* Second blit layer. We need two layers to blit to * to avoid flickering in WPF. This is temporary until * we build proper syncronization of the rendering */ m_blitLayer2 = new DrawingLayer(Factory, width, height, SlimDX.DXGI.Format.B8G8R8A8_UNorm, ResourceOptionFlags.Shared); /* Get the shared handle associated to our last blit texture */ var sharedHandle = GetSharedHandle(m_blitLayer2.RenderTargetTexture.InternalTexture2D); /* This initializes the shared surface on our Direct3D9Ex device so WPF can access it * It needs to be pulled in using the exact same size/format/etc as the original */ m_sharedTexture = new Texture(m_device, width, height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default, ref sharedHandle); Surface s = m_device.GetRenderTarget(0); /* We get the surface from our shared texture...*/ using (Surface surface = m_sharedTexture.GetSurfaceLevel(0)) { InvalidateD3DSurface(surface.ComPointer); } }
protected override bool VerifyInitOverride() { if (DepthFrame == null) { return false; } if (effectLayer == null) { effectLayer = Factory.CreateDrawingLayer(DepthFrame.Width, DepthFrame.Height); } if (effectLayer2 == null) { effectLayer2 = Factory.CreateDrawingLayer(DepthFrame.Width, DepthFrame.Height); } if (unpackEffect == null) { unpackEffect = new UnpackDepthEffect(Factory); } if (colorMapEffect == null) { colorMapEffect = new ColorMapDepthEffect(Factory); } if (rectBrushForeground == null) { rectBrushForeground = Factory.CreateSolidColorBrush(new Color4(1, 1, 1, 1)); } if (rectBrushBackground == null) { rectBrushBackground = Factory.CreateSolidColorBrush(new Color4(1, 0, 0, 0)); } return base.VerifyInitOverride(); }
protected override void DrawLayer(DrawingLayer outputLayer) { base.DrawLayer(outputLayer); DepthFrame.MinThreshold = (ushort)this.MinThreshold; DepthFrame.MaxThreshold = (ushort)this.MaxThreshold; ushort minValue; ushort maxValue; var img = DepthFrame.ToDirectCanvasImage(Factory, out minValue, out maxValue); effectLayer.CopyFromImage(img); Rect crop = DepthFrame.Crop; Rectangle rect = new Rectangle((int)crop.X, (int)crop.Y, (int)crop.Width, (int)crop.Height); RectangleF rectf = new RectangleF((float)crop.X, (float)crop.Y, (float)crop.Width, (float)crop.Height); colorMapEffect.MinThreshold = (float)MinThreshold; colorMapEffect.MaxThreshold = (float)MaxThreshold; colorMapEffect.MinValue = minValue; colorMapEffect.MaxValue = maxValue; unpackEffect.TexSize = new DirectCanvas.Misc.Size(effectLayer.Width, effectLayer.Height); effectLayer.ApplyEffect(unpackEffect, effectLayer2, true); effectLayer2.ApplyEffect(colorMapEffect, outputLayer, true); outputLayer.BeginDraw(); outputLayer.DrawRectangle(rectBrushBackground, rectf, 3f); outputLayer.DrawRectangle(rectBrushForeground, rectf, 1f); outputLayer.EndDraw(); }
/// <summary> /// Override to draw visuals to the drawing layer /// </summary> /// <param name="drawingLayer"></param> protected virtual void DrawLayer(DrawingLayer outputLayer) { }
/// <summary> /// Creates a new DrawingLayerBrush, using a drawing layer as an input /// </summary> /// <param name="drawingLayer">The drawing layer to use as input</param> /// <returns>An intialized DrawingLayerBrush</returns> public DrawingLayerBrush CreateDrawingLayerBrush(DrawingLayer drawingLayer) { return m_resources.CreateDrawingLayerBrush(drawingLayer); }
internal void ApplyEffect(ShaderEffect effect, DrawingLayer input, DrawingLayer output, Rectangle targetRect, bool clearOutput = true) { m_shaderRenderer.Apply(effect, input.RenderTargetTexture, output.RenderTargetTexture, targetRect, clearOutput); }
/// <summary> /// Fills an opacity mask on the DrawingLayer /// </summary> /// <param name="brush">The brush containing the content to fill</param> /// <param name="mask">The opacity mask</param> /// <param name="sourceRect">The source rectangle to use</param> /// <param name="destinationRect">The destination rectangle to use</param> public void FillOpacityMask(Brush brush, DrawingLayer mask, RectangleF destinationRect, RectangleF sourceRect) { FillOpacityMaskInternal(brush, mask.D2DRenderTarget.InternalBitmap, destinationRect, sourceRect); }
public void ApplyEffect(ShaderEffect effect, DrawingLayer output, Rectangle targetRect, bool clearOutput = true) { m_directCanvasFactory.ApplyEffect(effect, this, output, targetRect, clearOutput); }
private void ReleaseResources() { if (m_sharedTexture != null) { m_sharedTexture.Dispose(); m_sharedTexture = null; } if (m_blitLayer != null) { m_blitLayer.Dispose(); m_blitLayer = null; } if (m_blitLayer2 != null) { m_blitLayer2.Dispose(); m_blitLayer2 = null; } if (m_layer != null) { m_layer.Dispose(); m_layer = null; } }
public void InitLayers(Size ImageSize) { hoverBrush = Factory.CreateSolidColorBrush(new Color4(.4f, 0, 0, 0)); contactBrush = Factory.CreateSolidColorBrush(new Color4(.8f, 0, 0, 0)); DepthPresenter = new WPFPresenter(Factory, ImageSize.Width, ImageSize.Height); intermediateLayer = Factory.CreateDrawingLayer(ImageSize.Width, ImageSize.Height); rawDepthLayer = Factory.CreateDrawingLayer(ImageSize.Width, ImageSize.Height); DepthBrush = Factory.CreateDrawingLayerBrush(DepthPresenter); DepthBrush.Alignment = DirectCanvas.Brushes.BrushAlignment.DrawingLayerAbsolute; }
public DrawingLayerBrush CreateDrawingLayerBrush(DrawingLayer drawingLayer) { return new DrawingLayerBrush(drawingLayer); }
private void InitializeResources() { m_mainLayer = m_presenter.Factory.CreateDrawingLayer(SCENE_WIDTH, SCENE_HEIGHT); m_opacityMask = CreateOpacityMask(); InitMediaPlayer(); InitializeVisualElements(); }
public override void Dispose() { if(m_swapChain != null) { Layer.Dispose(); m_lastDrawingLayer = null; m_swapChain.Dispose(); } base.Dispose(); }
public PixelShaderScene(DrawingLayer presenter) { m_mainLayer = presenter; m_ripples = new Dictionary<int, RippleSettings>(); InitializeResources(); }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeLayer(DrawingLayer layer, RectangleF sourceArea, RectangleF destinationArea, RotationParameters rotationTransform, Color4 tint) { m_directCanvasFactory.Compose(layer, sourceArea, destinationArea, rotationTransform, tint); }
/// <summary> /// Composes a DrawingLayer with another DrawingLayer. /// This allows for things like scaling, blending, 2D and 3D transformations /// </summary> /// <param name="layer">The DrawingLayer that is used as the input</param> /// <param name="sourceArea">The area over the input DrawingLayer</param> /// <param name="destinationArea">The output area to draw the source area</param> /// <param name="rotationTransform">The rotation parameters</param> /// <param name="tint">The color to tint the source layer on to the output</param> public void ComposeDrawingLayer(DrawingLayer layer, RectangleF sourceArea, RectangleF destinationArea, RotationParameters rotationTransform, Color4 tint) { ComposeDrawingLayer(layer, ref sourceArea, ref destinationArea, ref rotationTransform, ref tint); }
/// <summary> /// Draws a DrawingLayer on to another DrawingLayer /// </summary> /// <param name="drawingLayer">The DrawingLayer to draw</param> /// <param name="destinationRectangle">The destination rectangle</param> /// <param name="sourceRectangle">The source rectangle</param> /// <param name="opacity">The transparency level, 0 - 1</param> public void DrawLayer(DrawingLayer drawingLayer, RectangleF destinationRectangle, RectangleF sourceRectangle, float opacity) { m_drawStateManagement.DrawPreamble(); D2DRenderTarget.InternalRenderTarget.DrawBitmap(drawingLayer.D2DRenderTarget.InternalBitmap, destinationRectangle.InternalRectangleF, opacity, InterpolationMode.Linear, sourceRectangle.InternalRectangleF); }
public DrawingLayer CalculateHistogram(DrawingLayer originalLayer) { DrawingLayer ping = originalLayer.Factory.CreateDrawingLayer(originalLayer.Width, originalLayer.Height); DrawingLayer pong = originalLayer.Factory.CreateDrawingLayer(originalLayer.Width, originalLayer.Height); float kernelHeight = 2; Rectangle rect = new Rectangle(0, 0, originalLayer.Width, (int)Math.Ceiling(originalLayer.Height / kernelHeight)); DrawingLayer source = ping; DrawingLayer target = pong; SourceHeight = rect.Height; originalLayer.ApplyEffect(this, source, rect, false); rect.Height = (int)Math.Ceiling(rect.Height / kernelHeight); while (rect.Height > 1) { SourceHeight = rect.Height; source.ApplyEffect(this, target, rect, false); //Swap layers for next round DrawingLayer temp = source; source = target; target = temp; rect.Height = (int)Math.Ceiling(rect.Height / kernelHeight); } //Target was switched with source, so source points to last result return source; }
/// <summary> /// Draws a DrawingLayer on to another DrawingLayer /// </summary> /// <param name="drawingLayer">The DrawingLayer to draw</param> /// <param name="destinationRectangle">The destination rectangle</param> public void DrawLayer(DrawingLayer drawingLayer, RectangleF destinationRectangle) { m_drawStateManagement.DrawPreamble(); D2DRenderTarget.InternalRenderTarget.DrawBitmap(drawingLayer.D2DRenderTarget.InternalBitmap, destinationRectangle.InternalRectangleF, 1.0f, InterpolationMode.Linear); }
private void ReleaseResources() { if (m_layer1 != null) { m_layer1.Dispose(); m_layer1 = null; } if (m_layer2 != null) { m_layer2.Dispose(); m_layer2 = null; } }
/// <summary> /// Draws a DrawingLayer on to another DrawingLayer /// </summary> /// <param name="drawingLayer">The DrawingLayer to draw</param> public void DrawLayer(DrawingLayer drawingLayer) { m_drawStateManagement.DrawPreamble(); D2DRenderTarget.InternalRenderTarget.DrawBitmap(drawingLayer.D2DRenderTarget.InternalBitmap); }