Пример #1
0
        public PongMaterials (ContentManager content)
            : base(content) {

            var addBs = new BlendState {
                AlphaBlendFunction = BlendFunction.Add,
                ColorBlendFunction = BlendFunction.Add,
                AlphaSourceBlend = Blend.One,
                ColorSourceBlend = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One
            };

            var ds = new DepthStencilState {
                DepthBufferEnable = false
            };

            // Set up various blending modes by changing render states
            var additiveBlend = new Action<DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState = addBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            var subBs = new BlendState {
                AlphaBlendFunction = BlendFunction.ReverseSubtract,
                ColorBlendFunction = BlendFunction.ReverseSubtract,
                AlphaSourceBlend = Blend.One,
                ColorSourceBlend = Blend.One,
                AlphaDestinationBlend = Blend.One, 
                ColorDestinationBlend = Blend.One
            };

            var subtractiveBlend = new Action<DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState = subBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            var alphaBs = new BlendState {
                AlphaBlendFunction = BlendFunction.Add,
                ColorBlendFunction = BlendFunction.Add,
                AlphaSourceBlend = Blend.SourceAlpha,
                ColorSourceBlend = Blend.SourceAlpha,
                AlphaDestinationBlend = Blend.InverseSourceAlpha,
                ColorDestinationBlend = Blend.InverseSourceAlpha
            };

            var alphaBlend = new Action<DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState = alphaBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            // Replace the default materials with ones that set up our custom render states
            ScreenSpaceBitmap = new DelegateMaterial(
                base.ScreenSpaceBitmap,
                alphaBlend,
                null
            );

            ScreenSpaceGeometry = new DelegateMaterial(
                base.ScreenSpaceGeometry,
                alphaBlend,
                null
            );

            // Create a couple custom materials
            Trail = new DelegateMaterial(
                base.ScreenSpaceBitmap,
                additiveBlend,
                null
            );

            SubtractiveGeometry = new DelegateMaterial(
                base.ScreenSpaceGeometry,
                subtractiveBlend,
                null
            );
        }
Пример #2
0
        public override void LoadContent()
        {
            LightmapMaterials = new DefaultMaterialSet(Game.Services);

            LightingEnvironment.DefaultSubdivision = 512f;

            BackgroundEnvironment = new LightingEnvironment();
            ForegroundEnvironment = new LightingEnvironment();

            BackgroundRenderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, BackgroundEnvironment);
            ForegroundRenderer = new LightingRenderer(Game.Content, Game.RenderCoordinator, LightmapMaterials, ForegroundEnvironment);

            // Add a global sun
            AddAmbientLight(746, -300);

            // Add clipped suns for areas with weird shadowing behavior
            AddAmbientLight(746, 200, new Bounds(
                                new Vector2(38, 33),
                                new Vector2(678, 678)
                                ));

            AddAmbientLight(740, 240, new Bounds(
                                new Vector2(805, 34),
                                new Vector2(1257, 546)
                                ));

            AddAmbientLight(741, 750, new Bounds(
                                new Vector2(0, 674),
                                new Vector2(1257, 941)
                                ));

            AddAmbientLight(741, 1025, new Bounds(
                                new Vector2(0, 941),
                                new Vector2(1257, 1250)
                                ));

            GenerateObstructionsFromTiles();

            Layers[0] = Game.Content.Load <Texture2D>("layers_bg");
            Layers[1] = Game.Content.Load <Texture2D>("layers_fg");
            Layers[2] = Game.Content.Load <Texture2D>("layers_chars");
            Layers[3] = Game.Content.Load <Texture2D>("layers_torches");

            MaskedForegroundMaterial = LightmapMaterials.ScreenSpaceLightmappedBitmap.SetStates(blendState: BlendState.Additive);

            ParticleRenderer = new ParticleRenderer(LightmapMaterials)
            {
                Viewport = new Bounds(Vector2.Zero, new Vector2(Width, Height))
            };

            Spark.Texture = Game.Content.Load <Texture2D>("spark");

            ParticleRenderer.Systems = new[] {
                Sparks = new ParticleSystem <Spark>(
                    new DotNetTimeProvider(),
                    BackgroundEnvironment
                    )
            };

            SparkLights = new ParticleLightManager <Spark>(
                Sparks,
                new[] { BackgroundEnvironment, ForegroundEnvironment },
                UpdateSectorLight
                );
        }
Пример #3
0
        public override void LoadContent()
        {
            LightmapMaterials = new DefaultMaterialSet(Game.Services);

            LightingEnvironment.DefaultSubdivision = 512f;

            BackgroundEnvironment = new LightingEnvironment();
            ForegroundEnvironment = new LightingEnvironment();

            BackgroundRenderer = new LightingRenderer(Game.Content, LightmapMaterials, BackgroundEnvironment);
            ForegroundRenderer = new LightingRenderer(Game.Content, LightmapMaterials, ForegroundEnvironment);

            // Add a global sun
            AddAmbientLight(746, -300);

            // Add clipped suns for areas with weird shadowing behavior
            AddAmbientLight(746, 200, new Bounds(
                new Vector2(38, 33),
                new Vector2(678, 678)
            ));

            AddAmbientLight(740, 240, new Bounds(
                new Vector2(805, 34),
                new Vector2(1257, 546)
            ));

            AddAmbientLight(741, 750, new Bounds(
                new Vector2(0, 674),
                new Vector2(1257, 941)
            ));

            AddAmbientLight(741, 1025, new Bounds(
                new Vector2(0, 941),
                new Vector2(1257, 1250)
            ));

            AddTorch(102, 132);
            AddTorch(869, 132);
            AddTorch(102, 646);
            AddTorch(869, 645);

            GenerateObstructionsFromTiles();

            Layers[0] = Game.Content.Load<Texture2D>("layers_bg");
            Layers[1] = Game.Content.Load<Texture2D>("layers_fg");
            Layers[2] = Game.Content.Load<Texture2D>("layers_chars");
            Layers[3] = Game.Content.Load<Texture2D>("layers_torches");

            BricksLightMask = Game.Content.Load<Texture2D>("layers_bricks_lightmask");

            AdditiveBitmapMaterial = LightmapMaterials.ScreenSpaceBitmap.SetStates(blendState: BlendState.Additive);

            MaskedForegroundMaterial = LightmapMaterials.ScreenSpaceLightmappedBitmap.SetStates(blendState: BlendState.Additive);

            AOShadowMaterial = Game.ScreenMaterials.ScreenSpaceVerticalGaussianBlur5Tap.SetStates(blendState: RenderStates.SubtractiveBlend);

            ParticleRenderer = new ParticleRenderer(LightmapMaterials) {
                Viewport = new Bounds(Vector2.Zero, new Vector2(Width, Height))
            };

            Spark.Texture = Game.Content.Load<Texture2D>("spark");

            ParticleRenderer.Systems = new[] {
                Sparks = new ParticleSystem<Spark>(
                    new DotNetTimeProvider(),
                    BackgroundEnvironment
                )
            };
        }
Пример #4
0
        public PongMaterials(IServiceProvider serviceProvider)
            : base(serviceProvider)
        {
            var addBs = new BlendState {
                AlphaBlendFunction    = BlendFunction.Add,
                ColorBlendFunction    = BlendFunction.Add,
                AlphaSourceBlend      = Blend.One,
                ColorSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One
            };

            var ds = new DepthStencilState {
                DepthBufferEnable = false
            };

            // Set up various blending modes by changing render states
            var additiveBlend = new Action <DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState        = addBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            var subBs = new BlendState {
                AlphaBlendFunction    = BlendFunction.ReverseSubtract,
                ColorBlendFunction    = BlendFunction.ReverseSubtract,
                AlphaSourceBlend      = Blend.One,
                ColorSourceBlend      = Blend.One,
                AlphaDestinationBlend = Blend.One,
                ColorDestinationBlend = Blend.One
            };

            var subtractiveBlend = new Action <DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState        = subBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            var alphaBs = new BlendState {
                AlphaBlendFunction    = BlendFunction.Add,
                ColorBlendFunction    = BlendFunction.Add,
                AlphaSourceBlend      = Blend.SourceAlpha,
                ColorSourceBlend      = Blend.SourceAlpha,
                AlphaDestinationBlend = Blend.InverseSourceAlpha,
                ColorDestinationBlend = Blend.InverseSourceAlpha
            };

            var alphaBlend = new Action <DeviceManager>[] {
                (dm) => {
                    dm.Device.BlendState        = alphaBs;
                    dm.Device.DepthStencilState = ds;
                }
            };

            // Replace the default materials with ones that set up our custom render states
            ScreenSpaceBitmap = new DelegateMaterial(
                base.ScreenSpaceBitmap,
                alphaBlend,
                null
                );

            ScreenSpaceGeometry = new DelegateMaterial(
                base.ScreenSpaceGeometry,
                alphaBlend,
                null
                );

            // Create a couple custom materials
            Trail = new DelegateMaterial(
                base.ScreenSpaceBitmap,
                additiveBlend,
                null
                );

            SubtractiveGeometry = new DelegateMaterial(
                base.ScreenSpaceGeometry,
                subtractiveBlend,
                null
                );
        }