private void Logo_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var session = args.DrawingSession;

            if (logoImage is CanvasBitmap && session is CanvasDrawingSession)
            {
                try
                {
                    if (RequestedTheme == ElementTheme.Dark)
                    {
                        session.DrawImage(logoImage);
                    }
                    else
                    {
                        var invert = new InvertEffect()
                        {
                            Source = logoImage
                        };
                        if (invert is InvertEffect)
                        {
                            session.DrawImage(invert);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.Message.T().ShowMessage("ERROR".T());
                }
            }
        }
Beispiel #2
0
        /// <inheritdoc cref="XamlCompositionBrushBase"/>
        protected override void OnConnected()
        {
            if (CompositionBrush == null)
            {
                // Effects setup
                SceneLightingEffect sceneLightingEffect = new SceneLightingEffect // Base lighting effect
                {
                    Name           = "Light",
                    SpecularShine  = (float)SpecularShine,
                    SpecularAmount = (float)SpecularAmount,
                    DiffuseAmount  = (float)DiffuseAmount,
                    AmbientAmount  = 0
                };
                _LuminanceEffect = new LuminanceToAlphaEffect {
                    Source = sceneLightingEffect
                };                                                                              // Map the bright areas of the light to an opacity mask
                _InverseEffect = new InvertEffect {
                    Source = _LuminanceEffect
                };                                                               // Invert the colors to make the brighter areas white
                _Factory = Window.Current.Compositor.CreateEffectFactory(_InverseEffect, new[] { "Light.DiffuseAmount", "Light.SpecularShine", "Light.SpecularAmount" });

                // Create and store the brush
                _Brush           = _Factory.CreateBrush();
                CompositionBrush = _Brush;
            }
            base.OnConnected();
        }
        /// <summary>
        /// Creates a CompositionEffectFactory that creates InvertEffects.
        /// </summary>
        /// <returns>CompositionEffectFactory</returns>
        private CompositionEffectFactory CreateInvertEffectFactory()
        {
            var effectDefinition = new InvertEffect()
            {
                Source = new CompositionEffectSourceParameter("Video")
            };

            return(_compositor.CreateEffectFactory(effectDefinition));
        }
        private static ICanvasImage CreateInvertEffect(ICanvasImage canvasImage)
        {
            var ef = new InvertEffect
            {
                Source = canvasImage
            };

            return(ef);
        }
Beispiel #5
0
        public void ISerializable_SerializeAndDeserializeCorrectly()
        {
            // Arrange
            var expected = new InvertEffect();
            var info     = MockSerializationInfo <InvertEffect>();

            // Act
            expected.GetObjectData(info, new StreamingContext());
            var actual = new InvertEffect(info, new StreamingContext());

            // Assert
            Assert.NotNull(actual);
        }
Beispiel #6
0
 private void Destroy()
 {
     if (this.Glitches != null)
     {
         ServiceHelper.RemoveComponent <NesGlitches>(this.Glitches);
     }
     this.Glitches = (NesGlitches)null;
     if (this.RtHandle != null)
     {
         this.TargetRenderer.UnscheduleHook(this.RtHandle.Target);
         this.TargetRenderer.ReturnTarget(this.RtHandle);
     }
     this.RtHandle = (RenderTargetHandle)null;
     if (this.SolidCubes != null)
     {
         this.SolidCubes.Dispose();
     }
     this.SolidCubes = (Mesh)null;
     if (this.WhiteCube != null)
     {
         this.WhiteCube.Dispose();
     }
     this.WhiteCube = (Mesh)null;
     if (this.RaysMesh != null)
     {
         this.RaysMesh.Dispose();
     }
     if (this.FlareMesh != null)
     {
         this.FlareMesh.Dispose();
     }
     this.RaysMesh = this.FlareMesh = (Mesh)null;
     if (this.InvertEffect != null)
     {
         this.InvertEffect.Dispose();
     }
     this.InvertEffect            = (InvertEffect)null;
     this.HexahedronAo            = (ArtObjectInstance)null;
     this.FirstUpdate             = true;
     this.sAmbientDrone           = this.sAku = this.sZoomIn = this.sHexAppear = this.sCubeAppear = this.sMotorSpin1 = this.sMotorSpin2 = this.sMotorSpinAOK = this.sMotorSpinCrash = this.sRayWhiteout = (SoundEffect)null;
     this.eAku                    = this.eAmbient = this.eMotor = (SoundEmitter)null;
     this.ActivePhase             = FinalRebuildHost.Phases.ZoomInNega;
     this.PhaseTime               = 0.0f;
     this.GameState.SkipRendering = false;
     this.GameState.HideHUD       = false;
 }
Beispiel #7
0
        public void Calculate_AppliesEffectOnHeightMap()
        {
            // Arrange
            var data = new double[, ] {
                { 0d, 0.25d, 0.5d, 0.75d, 1d }
            };
            var heightMap = new HeightMap(data);
            var expected  = MockImageEffect(heightMap);
            var effect    = new InvertEffect();

            // Act
            var actual = effect.Calculate(heightMap).Data;

            // Assert
            Assert.Equal(expected[0, 0], actual[0, 0]);
            Assert.Equal(expected[0, 1], actual[0, 1]);
            Assert.Equal(expected[0, 2], actual[0, 2]);
            Assert.Equal(expected[0, 3], actual[0, 3]);
            Assert.Equal(expected[0, 4], actual[0, 4]);
        }
        private void MainGridLoaded(object sender, RoutedEventArgs e)
        {
            m_compositor = ElementCompositionPreview.GetElementVisual(MainGrid).Compositor;
            m_root       = m_compositor.CreateContainerVisual();
            ElementCompositionPreview.SetElementChildVisual(MainGrid, m_root);

            Size imageSize;

            m_noEffectBrush = CreateBrushFromAsset(
                "Bruno'sFamily2015 (13)-X2.jpg",
                out imageSize);
            m_imageAspectRatio = (imageSize.Width == 0 && imageSize.Height == 0) ? 1 : imageSize.Width / imageSize.Height;

            m_sprite = m_compositor.CreateSpriteVisual();
            ResizeImage(new Size(MainGrid.ActualWidth, MainGrid.ActualHeight));
            m_root.Children.InsertAtTop(m_sprite);

            // Image with alpha channel as an mask.
            var alphaMaskEffectDesc = new CompositeEffect
            {
                Mode    = CanvasComposite.DestinationIn,
                Sources =
                {
                    new CompositionEffectSourceParameter("Image"),
                    new Transform2DEffect
                    {
                        Name   = "MaskTransform",
                        Source = new CompositionEffectSourceParameter("Mask")
                    }
                }
            };

            m_alphaMaskEffectBrush = m_compositor.CreateEffectFactory(
                alphaMaskEffectDesc,
                new[] { "MaskTransform.TransformMatrix" }
                ).CreateBrush();
            m_alphaMaskEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);
            m_alphaMaskEffectBrush.SetSourceParameter(
                "Mask",
                CreateBrushFromAsset("CircleMask.png"));

            // Arithmetic operations between two images.
            var arithmeticEffectDesc = new ArithmeticCompositeEffect
            {
                Name        = "effect",
                ClampOutput = false,
                Source1     = new CompositionEffectSourceParameter("Source1"),
                Source2     = new CompositionEffectSourceParameter("Source2")
            };

            m_arithmeticEffectBrush = m_compositor.CreateEffectFactory(
                arithmeticEffectDesc,
                new[]
            {
                "effect.MultiplyAmount",
                "effect.Source1Amount",
                "effect.Source2Amount",
                "effect.Offset"
            }
                ).CreateBrush();
            m_arithmeticEffectBrush.SetSourceParameter(
                "Source1",
                m_noEffectBrush);
            m_arithmeticEffectBrush.SetSourceParameter(
                "Source2",
                CreateBrushFromAsset("_P2A8041.jpg"));

            // Creates a blend effect that combines two images.
            var foregroundBrush = CreateBrushFromAsset("Checkerboard_100x100.png");

            m_blendEffectBrushes = new CompositionEffectBrush[m_supportedBlendModes.Length];
            for (int i = 0; i < m_supportedBlendModes.Length; i++)
            {
                var blendEffectDesc = new BlendEffect
                {
                    Mode       = m_supportedBlendModes[i],
                    Background = new CompositionEffectSourceParameter("Background"),
                    Foreground = new CompositionEffectSourceParameter("Foreground")
                };
                m_blendEffectBrushes[i] = m_compositor.CreateEffectFactory(
                    blendEffectDesc
                    ).CreateBrush();
                m_blendEffectBrushes[i].SetSourceParameter(
                    "Background",
                    m_noEffectBrush);
                m_blendEffectBrushes[i].SetSourceParameter(
                    "Foreground",
                    foregroundBrush);
            }

            // Generates an image containing a solid color.
            var colorSourceEffectDesc = new ColorSourceEffect // FloodEffect
            {
                Name = "effect"
            };

            m_colorSourceEffectBrush = m_compositor.CreateEffectFactory(
                colorSourceEffectDesc,
                new[] { "effect.Color" }
                ).CreateBrush();

            // Changes the contrast of an image.
            var contrastEffectDesc = new ContrastEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_contrastEffectBrush = m_compositor.CreateEffectFactory(
                contrastEffectDesc,
                new[] { "effect.Contrast" }
                ).CreateBrush();
            m_contrastEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Changes the exposure of an image.
            var exposureEffectDesc = new ExposureEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_exposureEffectBrush = m_compositor.CreateEffectFactory(
                exposureEffectDesc,
                new[] { "effect.Exposure" }
                ).CreateBrush();
            m_exposureEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the colors of an image by applying a per-channel gamma transfer function.
            var gammaTransferEffectDesc = new GammaTransferEffect
            {
                Name         = "effect",
                RedDisable   = false,
                GreenDisable = false,
                BlueDisable  = false,
                AlphaDisable = false,
                Source       = new CompositionEffectSourceParameter("Image")
            };

            m_gammaTransferEffectBrush = m_compositor.CreateEffectFactory(
                gammaTransferEffectDesc,
                new[]
            {
                "effect.RedAmplitude",
                "effect.RedExponent",
                "effect.RedOffset",
                "effect.GreenAmplitude",
                "effect.GreenExponent",
                "effect.GreenOffset",
                "effect.BlueAmplitude",
                "effect.BlueExponent",
                "effect.BlueOffset"
            }
                ).CreateBrush();
            m_gammaTransferEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Converts an image to monochromatic gray.
            var grayscaleEffectDesc = new GrayscaleEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_grayscaleEffectBrush = m_compositor.CreateEffectFactory(
                grayscaleEffectDesc
                ).CreateBrush();
            m_grayscaleEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the color of an image by rotating its hue values.
            var hueRotationEffectDesc = new HueRotationEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_hueRotationEffectBrush = m_compositor.CreateEffectFactory(
                hueRotationEffectDesc,
                new[] { "effect.Angle" }
                ).CreateBrush();
            m_hueRotationEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Inverts the colors of an image.
            var invertEffectDesc = new InvertEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_invertEffectBrush = m_compositor.CreateEffectFactory(
                invertEffectDesc
                ).CreateBrush();
            m_invertEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Alters the saturation of an image.
            var saturationEffectDesc = new SaturationEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_saturateEffectBrush = m_compositor.CreateEffectFactory(
                saturationEffectDesc,
                new[] { "effect.Saturation" }
                ).CreateBrush();
            m_saturateEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Converts an image to sepia tones.
            var supportedAlphaModes = new[]
            {
                CanvasAlphaMode.Premultiplied,
                CanvasAlphaMode.Straight
            };

            m_sepiaEffectBrushes = new CompositionEffectBrush[supportedAlphaModes.Length];
            for (int i = 0; i < supportedAlphaModes.Length; i++)
            {
                var sepiaEffectDesc = new SepiaEffect
                {
                    Name      = "effect",
                    AlphaMode = supportedAlphaModes[i],
                    Source    = new CompositionEffectSourceParameter("Image")
                };
                m_sepiaEffectBrushes[i] = m_compositor.CreateEffectFactory(
                    sepiaEffectDesc,
                    new[] { "effect.Intensity" }
                    ).CreateBrush();
                m_sepiaEffectBrushes[i].SetSourceParameter(
                    "Image",
                    m_noEffectBrush);
            }

            // Adjusts the temperature and/or tint of an image.
            var temperatureAndTintEffectDesc = new TemperatureAndTintEffect
            {
                Name   = "effect",
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_temperatureAndTintEffectBrush = m_compositor.CreateEffectFactory(
                temperatureAndTintEffectDesc,
                new[]
            {
                "effect.Temperature",
                "effect.Tint"
            }
                ).CreateBrush();
            m_temperatureAndTintEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // Applies a 2D affine transform matrix to an image.
            var transform2DEffectDesc = new Transform2DEffect
            {
                TransformMatrix = new Matrix3x2(
                    -1, 0,
                    0, 1,
                    m_sprite.Size.X, 0),
                Source = new CompositionEffectSourceParameter("Image")
            };

            m_transform2DEffectBrush = m_compositor.CreateEffectFactory(
                transform2DEffectDesc
                ).CreateBrush();
            m_transform2DEffectBrush.SetSourceParameter(
                "Image",
                m_noEffectBrush);

            // For simplying UI states switch, put effect parameter grids in an array
            m_effectParamsGrids = new Grid[(int)EffectType.NumEffectTypes];
            m_effectParamsGrids[(int)EffectType.NoEffect]           = null;
            m_effectParamsGrids[(int)EffectType.AlphaMask]          = AlphaMaskParams;
            m_effectParamsGrids[(int)EffectType.Arithmetic]         = ArithmeticParams;
            m_effectParamsGrids[(int)EffectType.Blend]              = BlendParams;
            m_effectParamsGrids[(int)EffectType.ColorSource]        = ColorSourceParams;
            m_effectParamsGrids[(int)EffectType.Contrast]           = ContrastParams;
            m_effectParamsGrids[(int)EffectType.Exposure]           = ExposureParams;
            m_effectParamsGrids[(int)EffectType.GammaTransfer]      = GammaTransferParams;
            m_effectParamsGrids[(int)EffectType.Grayscale]          = null;
            m_effectParamsGrids[(int)EffectType.HueRotation]        = HueRotationParams;
            m_effectParamsGrids[(int)EffectType.Invert]             = null;
            m_effectParamsGrids[(int)EffectType.Saturation]         = SaturationParams;
            m_effectParamsGrids[(int)EffectType.Sepia]              = SepiaParams;
            m_effectParamsGrids[(int)EffectType.TemperatureAndTint] = TemperatureAndTintParams;
            m_effectParamsGrids[(int)EffectType.Transform2D]        = null;

            // Same as grids
            m_effectBrushes = new CompositionBrush[(int)EffectType.NumEffectTypes];
            m_effectBrushes[(int)EffectType.NoEffect]           = m_noEffectBrush;
            m_effectBrushes[(int)EffectType.AlphaMask]          = m_alphaMaskEffectBrush;
            m_effectBrushes[(int)EffectType.Arithmetic]         = m_arithmeticEffectBrush;
            m_effectBrushes[(int)EffectType.Blend]              = m_blendEffectBrushes[m_activeBlendMode];
            m_effectBrushes[(int)EffectType.ColorSource]        = m_colorSourceEffectBrush;
            m_effectBrushes[(int)EffectType.Contrast]           = m_contrastEffectBrush;
            m_effectBrushes[(int)EffectType.Exposure]           = m_exposureEffectBrush;
            m_effectBrushes[(int)EffectType.GammaTransfer]      = m_gammaTransferEffectBrush;
            m_effectBrushes[(int)EffectType.Grayscale]          = m_grayscaleEffectBrush;
            m_effectBrushes[(int)EffectType.HueRotation]        = m_hueRotationEffectBrush;
            m_effectBrushes[(int)EffectType.Invert]             = m_invertEffectBrush;
            m_effectBrushes[(int)EffectType.Saturation]         = m_saturateEffectBrush;
            m_effectBrushes[(int)EffectType.Sepia]              = m_sepiaEffectBrushes[m_activeSepiaAlphaMode];
            m_effectBrushes[(int)EffectType.TemperatureAndTint] = m_temperatureAndTintEffectBrush;
            m_effectBrushes[(int)EffectType.Transform2D]        = m_transform2DEffectBrush;

            this.InitializeValues();
        }
        private async void OnLoaded(object sender, RoutedEventArgs e)
        {
            _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
            _generator  = CompositionGeneratorFactory.GetCompositionGenerator(_compositor);

            var distance   = 4f;
            var visualSize = new Vector2(225, 150);
            var vRefHeight = visualSize.Y + (visualSize.Y * 0.7f) + distance;
            var hRefWidth  = visualSize.X + (visualSize.X * 0.7f) + distance;

            var vRefLeft = (float)(CompositionGrid1.ActualWidth - visualSize.X) / 2f;
            var vRefTop  = (float)(CompositionGrid1.ActualHeight - vRefHeight) / 2f;
            var hRefLeft = (float)(CompositionGrid1.ActualWidth - hRefWidth) / 2f;
            var hRefTop  = (float)(CompositionGrid1.ActualHeight - visualSize.Y) / 2f;

            var surfaceImage = await _generator.CreateImageSurfaceAsync(new Uri("ms-appx:///Assets/Images/Car.jpg"),
                                                                        visualSize.ToSize(), ImageSurfaceOptions.Default);

            var surfaceBrush = _compositor.CreateSurfaceBrush(surfaceImage.Surface);

            var visual1 = _compositor.CreateSpriteVisual();

            visual1.Size   = visualSize;
            visual1.Offset = new Vector3(vRefLeft, vRefTop, 0);
            visual1.Brush  = surfaceBrush;

            _generator.CreateReflection(visual1, distance);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid1, visual1);

            var invertEffect = new InvertEffect()
            {
                Source = new CompositionEffectSourceParameter("source")
            };

            var invertEffectFactory = _compositor.CreateEffectFactory(invertEffect);
            var invertBrush         = invertEffectFactory.CreateBrush();

            invertBrush.SetSourceParameter("source", surfaceBrush);

            var visual2 = _compositor.CreateSpriteVisual();

            visual2.Size   = visualSize;
            visual2.Offset = new Vector3(hRefLeft, hRefTop, 0);
            visual2.Brush  = invertBrush;

            _generator.CreateReflection(visual2, distance, 0.7f, ReflectionLocation.Right);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid2, visual2);

            var visual3 = _compositor.CreateSpriteVisual();

            visual3.Size   = visualSize;
            visual3.Offset = new Vector3(vRefLeft, vRefTop, 0);
            visual3.Brush  = surfaceBrush;

            var inVisual = _compositor.CreateSpriteVisual();

            inVisual.Size   = new Vector2(80, 80);
            inVisual.Offset = new Vector3(20, 10, 0);
            inVisual.Brush  = _compositor.CreateColorBrush(Colors.Yellow);

            var inVisual2 = _compositor.CreateSpriteVisual();

            inVisual2.Size   = new Vector2(80, 80);
            inVisual2.Offset = new Vector3(60, 60, 0);
            inVisual2.Brush  = _compositor.CreateColorBrush(Colors.Blue);
            visual3.Children.InsertAtTop(inVisual2);
            visual3.Children.InsertAtTop(inVisual);

            _generator.CreateReflection(visual3, distance, 0.7f, ReflectionLocation.Bottom);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid3, visual3);

            var visual4 = _compositor.CreateSpriteVisual();

            visual4.Size   = visualSize;
            visual4.Offset = new Vector3(hRefLeft, hRefTop, 0);
            visual4.Brush  = surfaceBrush;

            var inVisual3 = _compositor.CreateSpriteVisual();

            inVisual3.Size   = new Vector2(80, 80);
            inVisual3.Offset = new Vector3(20, 10, 0);
            inVisual3.Brush  = _compositor.CreateColorBrush(Colors.Yellow);

            var inVisual4 = _compositor.CreateSpriteVisual();

            inVisual4.Size   = new Vector2(80, 80);
            inVisual4.Offset = new Vector3(60, 40, 0);
            inVisual4.Brush  = _compositor.CreateColorBrush(Colors.Blue);
            visual4.Children.InsertAtTop(inVisual3);
            visual4.Children.InsertAtTop(inVisual4);


            _generator.CreateReflection(visual4, distance, 0.7f, ReflectionLocation.Right);

            ElementCompositionPreview.SetElementChildVisual(CompositionGrid4, visual4);
        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Initialize Composition UI infrastructure.
            _leftRoot   = LeftContainer.GetVisual();
            _middleRoot = MiddleContainer.GetVisual();
            _rightRoot  = RightContainer.GetVisual();
            _compositor = _leftRoot.Compositor;

            _imageFactory = CompositionImageFactory.CreateCompositionImageFactory(_compositor);

            // Hook the sprite visuals into the XAML visual tree.
            _leftSpriteVisual = _compositor.CreateSpriteVisual();
            var side = (float)Math.Min(LeftPresenter.ActualWidth, LeftPresenter.ActualHeight);

            _leftSpriteVisual.Size = new Vector2(side, side);
            _leftRoot.Children.InsertAtTop(_leftSpriteVisual);
            _middleSpriteVisual = _compositor.CreateSpriteVisual();
            side = (float)Math.Min(MiddlePresenter.ActualWidth, MiddlePresenter.ActualHeight);
            _middleSpriteVisual.Size = new Vector2(side, side);
            _middleRoot.Children.InsertAtTop(_middleSpriteVisual);
            _rightSpriteVisual = _compositor.CreateSpriteVisual();
            side = (float)Math.Min(RightPresenter.ActualWidth, RightPresenter.ActualHeight);
            _rightSpriteVisual.Size = new Vector2(side, side);
            _rightRoot.Children.InsertAtTop(_rightSpriteVisual);

            // Create CompositionSurfaceBrush
            _imageBrush = _compositor.CreateSurfaceBrush();

            // Create an image source to load
            var imageSource = _imageFactory.CreateImageFromUri(new Uri("ms-appx:///Assets/flowers.jpg"));

            _imageBrush.Surface = imageSource.Surface;

            // Create and apply the first effect.
            _firstEffect = new SaturationEffect
            {
                Name   = "firstEffect",
                Source = new CompositionEffectSourceParameter("source")
            };
            var firstEffectFactory = _compositor.CreateEffectFactory(_firstEffect, new[] { "firstEffect.Saturation" });

            _effectBrush1           = firstEffectFactory.CreateBrush();
            _leftSpriteVisual.Brush = _effectBrush1;

            // Create and apply the second effect.
            var secondEffect = new InvertEffect
            {
                Name   = "secondEffect",
                Source = new CompositionEffectSourceParameter("source")
            };
            var secondEffectFactory = _compositor.CreateEffectFactory(secondEffect);

            _effectBrush2             = secondEffectFactory.CreateBrush();
            _middleSpriteVisual.Brush = _effectBrush2;

            // Create and apply the combined effect.
            _combinedEffect = new InvertEffect
            {
                Name   = "chained",
                Source = _firstEffect
            };
            var combinedEffectFactory = _compositor.CreateEffectFactory(_combinedEffect, new[] { "firstEffect.Saturation" });

            _combinedBrush           = combinedEffectFactory.CreateBrush();
            _rightSpriteVisual.Brush = _combinedBrush;

            // Chain the brushes
            _effectBrush1.SetSourceParameter("source", _imageBrush);
            _effectBrush2.SetSourceParameter("source", _imageBrush);
            _combinedBrush.SetSourceParameter("source", _imageBrush);
        }
Beispiel #11
0
        private void TryInitialize()
        {
            this.Destroy();
            this.Visible = this.Enabled = this.LevelManager.Name == "HEX_REBUILD";
            if (!this.Enabled)
            {
                return;
            }
            this.GameState.HideHUD = true;
            this.CameraManager.ChangeViewpoint(Viewpoint.Right, 0.0f);
            this.PlayerManager.Background = false;
            ArtObject artObject = this.CMProvider.CurrentLevel.Load <ArtObject>("Art Objects/NEW_HEXAO");
            int       key       = IdentifierPool.FirstAvailable <ArtObjectInstance>(this.LevelManager.ArtObjects);

            this.HexahedronAo = new ArtObjectInstance(artObject)
            {
                Id = key
            };
            this.LevelManager.ArtObjects.Add(key, this.HexahedronAo);
            this.HexahedronAo.Initialize();
            this.HexahedronAo.Hidden = true;
            this.WhiteCube           = new Mesh()
            {
                Effect      = (BaseEffect) new DefaultEffect.VertexColored(),
                Blending    = new BlendingMode?(BlendingMode.Additive),
                DepthWrites = false
            };
            this.WhiteCube.Rotation = this.CameraManager.Rotation * Quaternion.CreateFromRotationMatrix(Matrix.CreateLookAt(Vector3.One, Vector3.Zero, Vector3.Up));
            this.WhiteCube.AddColoredBox(new Vector3(4f), Vector3.Zero, Color.White, true);
            FinalRebuildHost finalRebuildHost = this;
            Mesh             mesh1            = new Mesh();
            Mesh             mesh2            = mesh1;

            DefaultEffect.LitTextured litTextured1 = new DefaultEffect.LitTextured();
            litTextured1.Specular        = true;
            litTextured1.Emissive        = 0.5f;
            litTextured1.AlphaIsEmissive = true;
            DefaultEffect.LitTextured litTextured2 = litTextured1;
            mesh2.Effect   = (BaseEffect)litTextured2;
            mesh1.Blending = new BlendingMode?(BlendingMode.Opaque);
            Mesh mesh3 = mesh1;

            finalRebuildHost.SolidCubes = mesh3;
            this.OriginalCubeRotation   = this.SolidCubes.Rotation = this.WhiteCube.Rotation;
            ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> geometry1 = Enumerable.FirstOrDefault <Trile>(this.LevelManager.ActorTriles(ActorType.CubeShard)).Geometry;
            ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> geometry2 = Enumerable.FirstOrDefault <Trile>(this.LevelManager.ActorTriles(ActorType.SecretCube)).Geometry;

            this.sHexAppear      = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/HexAppear");
            this.sCubeAppear     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/CubeAppear");
            this.sMotorSpin1     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStart1");
            this.sMotorSpin2     = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStart2");
            this.sMotorSpinAOK   = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStartAOK");
            this.sMotorSpinCrash = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/MotorStartCrash");
            this.sRayWhiteout    = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/RayWhiteout");
            this.sAku            = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/Aku");
            this.sZoomIn         = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/ZoomIn");
            this.sAmbientDrone   = this.CMProvider.CurrentLevel.Load <SoundEffect>("Sounds/Ending/HexRebuild/AmbientDrone");
            for (int index = 0; index < Math.Min(this.GameState.SaveData.CubeShards + this.GameState.SaveData.SecretCubes, 64); ++index)
            {
                Vector3 vector3 = this.CubeOffsets[index];
                ShaderInstancedIndexedPrimitives <VertexPositionNormalTextureInstance, Vector4> indexedPrimitives = index < this.GameState.SaveData.CubeShards ? geometry1 : geometry2;
                Group group = this.SolidCubes.AddGroup();
                group.Geometry = (IIndexedPrimitiveCollection) new IndexedUserPrimitives <VertexPositionNormalTextureInstance>(Enumerable.ToArray <VertexPositionNormalTextureInstance>((IEnumerable <VertexPositionNormalTextureInstance>)indexedPrimitives.Vertices), indexedPrimitives.Indices, indexedPrimitives.PrimitiveType);
                group.Position = vector3;
                group.Rotation = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)RandomHelper.Random.Next(0, 4) * 1.570796f);
                group.Enabled  = false;
                group.Material = new Material();
            }
            this.SolidCubes.Texture = this.LevelMaterializer.TrilesMesh.Texture;
            this.InvertEffect       = new InvertEffect();
            this.RaysMesh           = new Mesh()
            {
                Effect      = (BaseEffect) new DefaultEffect.VertexColored(),
                Blending    = new BlendingMode?(BlendingMode.Additive),
                DepthWrites = false
            };
            this.FlareMesh = new Mesh()
            {
                Effect       = (BaseEffect) new DefaultEffect.Textured(),
                Texture      = (Dirtyable <Texture>)((Texture)this.CMProvider.Global.Load <Texture2D>("Other Textures/flare_alpha")),
                Blending     = new BlendingMode?(BlendingMode.Alphablending),
                SamplerState = SamplerState.AnisotropicClamp,
                DepthWrites  = false,
                AlwaysOnTop  = true
            };
            this.FlareMesh.AddFace(Vector3.One, Vector3.Zero, FaceOrientation.Front, true);
            this.RtHandle = this.TargetRenderer.TakeTarget();
            this.TargetRenderer.ScheduleHook(this.DrawOrder, this.RtHandle.Target);
            ServiceHelper.AddComponent((IGameComponent)(this.Glitches = new NesGlitches(this.Game)));
        }
        public CanvasRenderTarget applyEdgeDetectionEffects(CanvasBitmap workingBitmap)
        {
            //CanvasBitmap workingBitmap = SelectWorkingBitmap(useOriginalBitmap);


            if (workingBitmap != null)
            {
                int ww = (int)workingBitmap.SizeInPixels.Width;
                int hh = (int)workingBitmap.SizeInPixels.Height;

                //GrayscaleEffect grayscaleEffect = new GrayscaleEffect();
                //grayscaleEffect.Source=canvasBitmap;

                ContrastEffect contrastEffect = new ContrastEffect();
                contrastEffect.Contrast = (float)edgeDetectionContrast;
                contrastEffect.Source   = workingBitmap;

                ExposureEffect exposureEffect = new ExposureEffect();
                exposureEffect.Source   = contrastEffect;
                exposureEffect.Exposure = (float)edgeDetectionExposure;


                EdgeDetectionEffect edgeDetectionEffect = new EdgeDetectionEffect();
                edgeDetectionEffect.Source     = exposureEffect;
                edgeDetectionEffect.Amount     = (float)edgeDetectionAmount;
                edgeDetectionEffect.BlurAmount = (float)edgeDetectionBlurAmount;
                //edgeDetectionEffect.OverlayEdges = true;
                //edgeDetectionEffect.Mode = EdgeDetectionEffectMode.Prewitt;

                GrayscaleEffect grayscaleEffect = null;
                if (edgeDetectionGrayscale)
                {
                    grayscaleEffect            = new GrayscaleEffect();
                    grayscaleEffect.Source     = exposureEffect;
                    edgeDetectionEffect.Source = grayscaleEffect;
                }

                InvertEffect invertEdgeEffect = null;
                if (edgeDetectionMaskInvert)
                {
                    invertEdgeEffect        = new InvertEffect();
                    invertEdgeEffect.Source = edgeDetectionEffect;
                }



                BlendEffect blendEffect = null;
                if (edgeDetectionOverlayImage)
                {
                    OpacityEffect opacityEffect = new OpacityEffect();
                    opacityEffect.Opacity = (float)edgeDetectionOverlayOpacity;
                    opacityEffect.Source  = workingBitmap;

                    blendEffect            = new BlendEffect();
                    blendEffect.Foreground = edgeDetectionEffect;
                    blendEffect.Background = opacityEffect;
                    if (edgeDetectionMaskInvert)
                    {
                        //blendEffect.Background = invertEdgeEffect;
                        //blendEffect.Foreground = opacityEffect;

                        InvertEffect invertOrgEffect = new InvertEffect();
                        invertOrgEffect.Source = opacityEffect;
                        blendEffect.Background = invertOrgEffect;
                    }

                    blendEffect.Mode = edgeDetectionBlendEffectMode;
                }


                //if (canvasRenderTarget != null)
                //    canvasRenderTarget.Dispose();
                CanvasRenderTarget canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), ww, hh, canvasBitmap.Dpi);
                using (var session = canvasRenderTarget.CreateDrawingSession())
                {
                    if (edgeDetectionOverlayImage)
                    {
                        session.DrawImage(blendEffect);
                    }
                    else
                    {
                        if (edgeDetectionMaskInvert)
                        {
                            session.DrawImage(invertEdgeEffect);
                        }
                        else
                        {
                            session.DrawImage(edgeDetectionEffect);
                        }
                    }
                }

                return(canvasRenderTarget);
            }

            return(null);
        }
Beispiel #13
0
        public void ProcessFrame(ProcessVideoFrameContext context)
        {
            //using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface))
            //using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface))
            //using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
            //{
            //    var invert = new InvertEffect()
            //    {
            //        Source = inputBitmap
            //    };
            //    ds.DrawImage(invert);

            //}

            // When using SupportedMemoryTypes => MediaMemoryTypes.GpuAndCpu we need to check if we're using GPU or CPU for the frame

            // If we're on GPU, use InputFrame.Direct3DSurface
            if (context.InputFrame.SoftwareBitmap == null)
            {
                using (var inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(_canvasDevice, context.InputFrame.Direct3DSurface))
                    using (var renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(_canvasDevice, context.OutputFrame.Direct3DSurface))
                        using (var ds = renderTarget.CreateDrawingSession())
                        {
                            var invert = new InvertEffect()
                            {
                                Source = inputBitmap
                            };
                            ds.DrawImage(invert);
                        }

                return;
            }

            // If we're on CPU, use InputFrame.SoftwareBitmap
            if (context.InputFrame.Direct3DSurface == null)
            {
                // InputFrame's raw pixels
                byte[] inputFrameBytes = new byte[4 * context.InputFrame.SoftwareBitmap.PixelWidth * context.InputFrame.SoftwareBitmap.PixelHeight];
                context.InputFrame.SoftwareBitmap.CopyToBuffer(inputFrameBytes.AsBuffer());

                using (var inputBitmap = CanvasBitmap.CreateFromBytes(
                           _canvasDevice,
                           inputFrameBytes,
                           context.InputFrame.SoftwareBitmap.PixelWidth,
                           context.InputFrame.SoftwareBitmap.PixelHeight,
                           context.InputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat()))

                    using (var renderTarget = new CanvasRenderTarget(
                               _canvasDevice,
                               context.OutputFrame.SoftwareBitmap.PixelWidth,
                               context.OutputFrame.SoftwareBitmap.PixelHeight,
                               (float)context.OutputFrame.SoftwareBitmap.DpiX,
                               context.OutputFrame.SoftwareBitmap.BitmapPixelFormat.ToDirectXPixelFormat(),
                               CanvasAlphaMode.Premultiplied))
                    {
                        using (var ds = renderTarget.CreateDrawingSession())
                        {
                            var invert = new InvertEffect()
                            {
                                Source = inputBitmap
                            };
                            ds.DrawImage(invert);
                        }
                    }
            }
        }