Inheritance: IDisposable
Ejemplo n.º 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
            );
        }