Inheritance: GraphicsResource
Beispiel #1
0
        public Level(int _index)
        {
            random = new Random();
            removeQueue = new Queue<GameObject>();
            font = Main.font;
            prop = 0.08f;
            lightable = new List<Point>();
            nullColor = new Color(0, 0, 0, 0);
            multiply = new BlendState()
            {
                AlphaSourceBlend = Blend.DestinationAlpha,
                AlphaDestinationBlend = Blend.Zero,
                AlphaBlendFunction = BlendFunction.Add,
                ColorSourceBlend = Blend.DestinationColor,
                ColorDestinationBlend = Blend.Zero,
                ColorBlendFunction = BlendFunction.Add
            };
            index = _index;
            lightSources = new List<LightSource>();
            objects = new List<GameObject>();
            charMap = Managers.Executive.levels[index][0];
            backCharMap = Managers.Executive.levels[index][1];
            tileMap = new Tile[charMap.GetLength(0), charMap.GetLength(1)];
            backTileMap = new Tile[charMap.GetLength(0), charMap.GetLength(1)];
            lightMap = new Light[charMap.GetLength(0), charMap.GetLength(1)];

        }
        public DeferredRenderer(GraphicsDevice GraphicsDevice, int Width, int Height)
            : base(GraphicsDevice)
        {
            //Create LightMap BlendState
            LightMapBS = new BlendState();
            LightMapBS.ColorSourceBlend = Blend.One;
            LightMapBS.ColorDestinationBlend = Blend.One;
            LightMapBS.ColorBlendFunction = BlendFunction.Add;
            LightMapBS.AlphaSourceBlend = Blend.One;
            LightMapBS.AlphaDestinationBlend = Blend.One;
            LightMapBS.AlphaBlendFunction = BlendFunction.Add;

            //Set GBuffer Texture Size
            GBufferTextureSize = new Vector2(Width, Height);

            //Intialize Each Target of the GBuffer
            GBufferTargets = new RenderTargetBinding[3];
            GBufferTargets[0] = new RenderTargetBinding(new RenderTarget2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8));
            GBufferTargets[1] = new RenderTargetBinding(new RenderTarget2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Rgba64, DepthFormat.Depth24Stencil8));
            GBufferTargets[2] = new RenderTargetBinding(new RenderTarget2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Vector2, DepthFormat.Depth24Stencil8));

            //Initialize LightMap
            LightMap = new RenderTarget2D(GraphicsDevice, Width, Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

            //Create Fullscreen Quad
            fsq = new FullscreenQuad(GraphicsDevice);
        }
Beispiel #3
0
 static HighlightModule()
 {
     var color = Color.Black;
     CubeVerticies = new[]
     {
         new VertexPositionColor(new XVector3(0, 0, 1), color),
         new VertexPositionColor(new XVector3(1, 0, 1), color),
         new VertexPositionColor(new XVector3(1, 1, 1), color),
         new VertexPositionColor(new XVector3(0, 1, 1), color),
         new VertexPositionColor(new XVector3(0, 0, 0), color),
         new VertexPositionColor(new XVector3(1, 0, 0), color),
         new VertexPositionColor(new XVector3(1, 1, 0), color),
         new VertexPositionColor(new XVector3(0, 1, 0), color)
     };
     CubeIndicies = new short[]
     {
         0, 1,   1, 2,   2, 3,   3, 0,
         0, 4,   4, 7,   7, 6,   6, 2,
         1, 5,   5, 4,   3, 7,   6, 5
     };
     DestructionBlendState = new BlendState
     {
         ColorSourceBlend = Blend.DestinationColor,
         ColorDestinationBlend = Blend.SourceColor,
         AlphaSourceBlend = Blend.DestinationAlpha,
         AlphaDestinationBlend = Blend.SourceAlpha
     };
     RasterizerState = new RasterizerState
     {
         DepthBias = -3,
         SlopeScaleDepthBias = -3
     };
 }
Beispiel #4
0
        public override void Draw(GameTime gameTime)
        {
            //first light area
            light1.LightPosition = new Vector2(200, 200);
            light1.BeginDrawingShadowCasters();
            //DrawCasters(lightArea1);
            light1.EndDrawingShadowCasters();
            shadowMapResolver.ResolveShadows(light1.RenderTarget, light1.RenderTarget, new Vector2(200, 200));

            GraphicsDevice.SetRenderTarget(screenShadows);
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
            spriteBatch.Draw(light1.RenderTarget, light1.LightPosition - light1.LightAreaSize * 0.5f, Color.White);
            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            GraphicsDevice.Clear(Color.Black);

            DrawBackground();

            BlendState blendState = new BlendState();
            blendState.ColorSourceBlend = Blend.DestinationColor;
            blendState.ColorDestinationBlend = Blend.SourceColor;

            spriteBatch.Begin(SpriteSortMode.Immediate, blendState);
            spriteBatch.Draw(screenShadows, Vector2.Zero, Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
Beispiel #5
0
        /// <summary>
        /// Starts the specified batch.
        /// </summary>
        /// <param name="batch">The batch.</param>
        /// <param name="useCamera">if set to <c>true</c> camera matrix will be applied.</param>
        /// <param name="sortMode">The sort mode.</param>
        /// <param name="blendState">State of the blend.</param>
        /// <param name="samplerState">State of the sampler.</param>
        /// <param name="depthStencilState">State of the depth stencil.</param>
        /// <param name="rasterizerState">State of the rasterizer.</param>
        /// <param name="effect">The effect.</param>
        /// <param name="transform">The transformation matrix.</param>
        public static void Start(this SpriteBatch batch,
            bool useCamera = false,
            SpriteSortMode sortMode = SpriteSortMode.Deferred,
            BlendState blendState = null,
            SamplerState samplerState = null,
            DepthStencilState depthStencilState = null,
            RasterizerState rasterizerState = null,
            Effect effect = null,
            Matrix? transform = null)
        {
            Matrix matrix = AlmiranteEngine.IsWinForms ? Matrix.Identity : AlmiranteEngine.Settings.Resolution.Matrix;

            if (useCamera)
            {
                matrix = AlmiranteEngine.Camera.Matrix * matrix;
            }

            if (transform.HasValue)
            {
                matrix = transform.Value * matrix;
            }

            BatchExtensions._sortMode = sortMode;
            BatchExtensions._blendState = blendState;
            BatchExtensions._samplerState = samplerState;
            BatchExtensions._depthStencilState = depthStencilState;
            BatchExtensions._rasterizerState = rasterizerState;
            BatchExtensions._effect = effect;
            BatchExtensions._matrix = matrix;

            batch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, matrix);
        }
Beispiel #6
0
 public RenderLayer(Vector2 parallax_vector, String layer_name, BlendState blend_state)
 {
     name = layer_name;
     visible = true;
     parallax = parallax_vector;
     blending = blend_state;
 }
 public DefaultLightContext(
     Texture2D deferredColorMap, 
     Texture2D deferredNormalMap,
     Texture2D deferredDepthMap, 
     Texture2D deferredSpecularMap,
     RenderTarget2D diffuseLightRenderTarget,
     RenderTarget2D specularLightRenderTarget,
     BlendState lightBlendState,
     RasterizerState rasterizerStateCullNone,
     RasterizerState rasterizerStateCullClockwiseFace, 
     RasterizerState rasterizerStateCullCounterClockwiseFace, 
     Vector2 halfPixel)
 {
     DeferredColorMap = deferredColorMap;
     DeferredNormalMap = deferredNormalMap;
     DeferredDepthMap = deferredDepthMap;
     DeferredSpecularMap = deferredSpecularMap;
     DiffuseLightRenderTarget = diffuseLightRenderTarget;
     SpecularLightRenderTarget = specularLightRenderTarget;
     LightBlendState = lightBlendState;
     RasterizerStateCullNone = rasterizerStateCullNone;
     RasterizerStateCullClockwiseFace = rasterizerStateCullClockwiseFace;
     RasterizerStateCullCounterClockwiseFace = rasterizerStateCullCounterClockwiseFace;
     HalfPixel = halfPixel;
 }
Beispiel #8
0
        protected override void OnInit()
        {
            base.OnInit();
            Texture2D texture = Texture;

            dtAfterGolUpdate = 0f;
            golUpdatePeriod = 60f / 140f;
            needFirstUpdate = true;

            spriteBatch = new SpriteBatch(Screen.graphicsDevice);
            eff = TTengineMaster.ActiveGame.Content.Load<Effect>("Effects/GoL");
            effTime = eff.Parameters["Time"];
            effDeltaPixelX = eff.Parameters["DeltaPixelX"];
            effDeltaPixelY = eff.Parameters["DeltaPixelY"];
            effDoGolUpdate = eff.Parameters["DoGolUpdate"];
            effDeltaPixelX.SetValue(1f/((float)texture.Width));
            effDeltaPixelY.SetValue(1f / ((float)texture.Height));
            VertexShaderInit(eff);

            renderBufInput = new RenderTarget2D(spriteBatch.GraphicsDevice, texture.Width, texture.Height);
            renderBufOutput = new RenderTarget2D(spriteBatch.GraphicsDevice, texture.Width, texture.Height);
            blendState = new BlendState();
            blendState.AlphaDestinationBlend = Blend.Zero;
            // first time rendering into buffer using BufferInit technique
            eff.CurrentTechnique = eff.Techniques[0];
            spriteBatch.Begin(SpriteSortMode.Deferred,blendState,null,null,null,eff);
            spriteBatch.GraphicsDevice.SetRenderTarget(renderBufInput);
            spriteBatch.Draw(texture, renderBufInput.Bounds, Color.White);
            spriteBatch.End();
        }
Beispiel #9
0
 protected override void InitialiserParamètresEffetDeBase()
 {
    EffetDeBase.TextureEnabled = true;
    EffetDeBase.Texture = Texture;
    GestionAlpha = BlendState.AlphaBlend;
    
 }
Beispiel #10
0
        private static void DoAsserts(BlendState blendState, Action<TestDelegate> assertMethod)
        {
            assertMethod(() => blendState.AlphaBlendFunction = BlendFunction.Add);
            assertMethod(() => blendState.AlphaDestinationBlend = Blend.BlendFactor);
            assertMethod(() => blendState.AlphaSourceBlend = Blend.BlendFactor);
            assertMethod(() => blendState.BlendFactor = Color.White);
            assertMethod(() => blendState.ColorBlendFunction = BlendFunction.Add);
            assertMethod(() => blendState.ColorDestinationBlend = Blend.BlendFactor);
            assertMethod(() => blendState.ColorSourceBlend = Blend.BlendFactor);
            assertMethod(() => blendState.ColorWriteChannels = ColorWriteChannels.All);
            assertMethod(() => blendState.ColorWriteChannels1 = ColorWriteChannels.All);
            assertMethod(() => blendState.ColorWriteChannels2 = ColorWriteChannels.All);
            assertMethod(() => blendState.ColorWriteChannels3 = ColorWriteChannels.All);
#if !XNA
            assertMethod(() => blendState.IndependentBlendEnable = true);
#endif
            assertMethod(() => blendState.MultiSampleMask = 0);

#if !XNA
            for (var i = 0; i < 4; i++)
            {
                assertMethod(() => blendState[0].AlphaBlendFunction = BlendFunction.Add);
                assertMethod(() => blendState[0].AlphaDestinationBlend = Blend.BlendFactor);
                assertMethod(() => blendState[0].AlphaSourceBlend = Blend.BlendFactor);
                assertMethod(() => blendState[0].ColorBlendFunction = BlendFunction.Add);
                assertMethod(() => blendState[0].ColorDestinationBlend = Blend.BlendFactor);
                assertMethod(() => blendState[0].ColorSourceBlend = Blend.BlendFactor);
                assertMethod(() => blendState[0].ColorWriteChannels = ColorWriteChannels.All);
            }
#endif
        }
Beispiel #11
0
 static BlendState()
 {
     AlphaBlend = new BlendState(FixedBlendState.AlphaBlend, TintEffectMode.Normal, "BlendState.AlphaBlend");
     NonPremultiplied = new BlendState(FixedBlendState.NonPremultiplied, TintEffectMode.Normal, "BlendState.NonPremultiplied");
     Additive = new BlendState(FixedBlendState.Additive, TintEffectMode.Additive, "BlendState.Additive");
     Opaque = new BlendState(FixedBlendState.Opaque, TintEffectMode.Opaque, "BlendState.Opaque");
 }
        public void DrawPolygons(Vector2 position, float angle, float scale,
            Texture2D texture, VertexPositionTexture[] vertices, BlendState blendMode)
        {
            effect.World = Matrix.CreateRotationZ(angle) *
                Matrix.CreateScale(scale) *
                Matrix.CreateTranslation(new Vector3(position, 0));
            effect.Texture = texture;

            GraphicsDevice device = GameEngine.Instance.GraphicsDevice;

            if (blendMode == BlendState.AlphaBlend)
            {
                device.BlendState = BlendState.AlphaBlend;
            }
            else if (blendMode == BlendState.Additive)
            {
                device.BlendState = BlendState.Additive;
            }
            SamplerState s = new SamplerState();
            s.AddressU = TextureAddressMode.Wrap;
            s.AddressV = TextureAddressMode.Wrap;
            device.SamplerStates[0] = s;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
                //pass.Apply();
            }
        }
Beispiel #13
0
        internal EffectPass(    Effect effect, 
                                string name,
                                Shader vertexShader, 
                                Shader pixelShader, 
                                BlendState blendState, 
                                DepthStencilState depthStencilState, 
                                RasterizerState rasterizerState,
                                EffectAnnotationCollection annotations )
        {
            Debug.Assert(effect != null, "Got a null effect!");
            Debug.Assert(annotations != null, "Got a null annotation collection!");

            _effect = effect;

            Name = name;

            _vertexShader = vertexShader;
            _pixelShader = pixelShader;

            _blendState = blendState;
            _depthStencilState = depthStencilState;
            _rasterizerState = rasterizerState;

            Annotations = annotations;
        }
Beispiel #14
0
 static BlendState()
 {
     AlphaBlend = new BlendState(Blend.One, Blend.InverseSourceAlpha, "BlendState.AlphaBlend");
     NonPremultiplied = new BlendState(Blend.SourceAlpha, Blend.InverseSourceAlpha, "BlendState.NonPremultiplied");
     Additive = new BlendState(Blend.SourceAlpha, Blend.One, "BlendState.Additive");
     Opaque = new BlendState(Blend.One, Blend.Zero, "BlendState.Opaque");
 }
Beispiel #15
0
        public override void Draw(GameTime gameTime)
        {
            BlendState blend = new BlendState();
            blend.ColorBlendFunction = BlendFunction.Add;
            blend.ColorSourceBlend = Blend.One;
            blend.ColorDestinationBlend = Blend.One;

            sprites.Begin(SpriteSortMode.Immediate, blend);
            lock (notes)
            {
                foreach (Note note in notes)
                    sprites.Draw(note.Texture, new Rectangle((int)note.Position.X, (int)note.Position.Y, (int)(note.Scale * (float)note.Texture.Width/8), (int)(note.Scale * (float)note.Texture.Height/8)), new Color((float)note.Time, (float)note.Time, (float)note.Time));
            }

            sprites.Draw(square, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), new Color(White.Value, White.Value, White.Value));

            sprites.End();

            blend = new BlendState();
            blend.ColorBlendFunction = BlendFunction.Add;
            blend.ColorSourceBlend = Blend.Zero;
            blend.ColorDestinationBlend = Blend.InverseSourceColor;

            sprites.Begin(SpriteSortMode.Immediate, blend);
            sprites.Draw(square, new Rectangle(0, 0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), new Color(Black.Value, Black.Value, Black.Value));

            sprites.End();

            base.Draw(gameTime);
        }
 public IRenderRequest CreateInstancedRequest(IRenderContext renderContext, RasterizerState rasterizerState,
     BlendState blendState, DepthStencilState depthStencilState, IEffect effect, IEffectParameterSet effectParameterSet,
     VertexBuffer meshVertexBuffer, IndexBuffer meshIndexBuffer, PrimitiveType primitiveType,
     Matrix[] instanceWorldTransforms, Action<List<Matrix>, VertexBuffer, IndexBuffer> computeCombinedBuffers)
 {
     throw new NotImplementedException();
 }
 public TagRenderer(int tag)
 {
     Tag = tag;
     BlendState = BlendState.AlphaBlend;
     SamplerState = SamplerState.LinearClamp;
     Camera = new Camera();
 }
 public TagExcludeRenderer(int excludeTag)
 {
     ExcludeTag = excludeTag;
     BlendState = BlendState.AlphaBlend;
     SamplerState = SamplerState.LinearClamp;
     Camera = new Camera();
 }
Beispiel #19
0
        public LineDrawer(Game game)
        {
            this.game = game;
            lineDrawer = new BasicEffect(game.GraphicsDevice);

            //Set up the default type mapping.
            displayTypes.Add(typeof(PointOnPlaneJoint), typeof(DisplayPointOnPlaneJoint));
            displayTypes.Add(typeof(SwivelHingeAngularJoint), typeof(DisplaySwivelHingeAngularJoint));
            displayTypes.Add(typeof(PointOnLineJoint), typeof(DisplayPointOnLineJoint));
            displayTypes.Add(typeof(BallSocketJoint), typeof(DisplayBallSocketJoint));
            displayTypes.Add(typeof(TwistJoint), typeof(DisplayTwistJoint));
            displayTypes.Add(typeof(TwistMotor), typeof(DisplayTwistMotor));
            displayTypes.Add(typeof(DistanceLimit), typeof(DisplayDistanceLimit));
            displayTypes.Add(typeof(DistanceJoint), typeof(DisplayDistanceJoint));
            displayTypes.Add(typeof(LinearAxisLimit), typeof(DisplayLinearAxisLimit));
            displayTypes.Add(typeof(EllipseSwingLimit), typeof(DisplayEllipseSwingLimit));
            displayTypes.Add(typeof(SingleEntityLinearMotor), typeof(DisplaySingleEntityLinearMotor));
            displayTypes.Add(typeof(RevoluteLimit), typeof(DisplayRevoluteLimit));

            blendState = new BlendState();
            blendState.ColorSourceBlend = Blend.SourceAlpha;
            blendState.AlphaSourceBlend = Blend.SourceAlpha;
            blendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            blendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
        }
Beispiel #20
0
        static BlendState()
        {
            Additive = new BlendState () {
                ColorSourceBlend = Blend.SourceAlpha,
                AlphaSourceBlend = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.One,
                AlphaDestinationBlend = Blend.One
            };

            AlphaBlend = new BlendState () {
                ColorSourceBlend = Blend.One,
                AlphaSourceBlend = Blend.One,
                ColorDestinationBlend = Blend.InverseSourceAlpha,
                AlphaDestinationBlend = Blend.InverseSourceAlpha
            };

            NonPremultiplied = new BlendState () {
                ColorSourceBlend = Blend.SourceAlpha,
                AlphaSourceBlend = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.InverseSourceAlpha,
                AlphaDestinationBlend = Blend.InverseSourceAlpha
            };

            Opaque = new BlendState () {
                ColorSourceBlend = Blend.One,
                AlphaSourceBlend = Blend.One,
                ColorDestinationBlend = Blend.Zero,
                AlphaDestinationBlend = Blend.Zero
            };
        }
Beispiel #21
0
        /// <summary>
        /// Begins a new sprite and text batch with the specified render state.
        /// </summary>
        /// <param name="sortMode">The drawing order for sprite and text drawing. <see cref="SpriteSortMode.Deferred"/> by default.</param>
        /// <param name="blendState">State of the blending. Uses <see cref="BlendState.AlphaBlend"/> if null.</param>
        /// <param name="samplerState">State of the sampler. Uses <see cref="SamplerState.LinearClamp"/> if null.</param>
        /// <param name="depthStencilState">State of the depth-stencil buffer. Uses <see cref="DepthStencilState.None"/> if null.</param>
        /// <param name="rasterizerState">State of the rasterization. Uses <see cref="RasterizerState.CullCounterClockwise"/> if null.</param>
        /// <param name="effect">A custom <see cref="Effect"/> to override the default sprite effect. Uses default sprite effect if null.</param>
        /// <param name="transformMatrix">An optional matrix used to transform the sprite geometry. Uses <see cref="Matrix.Identity"/> if null.</param>
        /// <exception cref="InvalidOperationException">Thrown if <see cref="Begin"/> is called next time without previous <see cref="End"/>.</exception>
        /// <remarks>This method uses optional parameters.</remarks>
        /// <remarks>The <see cref="Begin"/> Begin should be called before drawing commands, and you cannot call it again before subsequent <see cref="End"/>.</remarks>
        public void Begin
        (
             SpriteSortMode sortMode = SpriteSortMode.Deferred,
             BlendState blendState = null,
             SamplerState samplerState = null,
             DepthStencilState depthStencilState = null,
             RasterizerState rasterizerState = null,
             Effect effect = null,
             Matrix? transformMatrix = null
        )
        {
            if (_beginCalled)
                throw new InvalidOperationException("Begin cannot be called again until End has been successfully called.");

            // defaults
            _sortMode = sortMode;
            _blendState = blendState ?? BlendState.AlphaBlend;
            _samplerState = samplerState ?? SamplerState.LinearClamp;
            _depthStencilState = depthStencilState ?? DepthStencilState.None;
            _rasterizerState = rasterizerState ?? RasterizerState.CullCounterClockwise;
            _effect = effect;
            _matrix = transformMatrix ?? Matrix.Identity;

            // Setup things now so a user can change them.
            if (sortMode == SpriteSortMode.Immediate)
            {
                Setup();
            }

            _beginCalled = true;
        }
Beispiel #22
0
        public ImperativeRenderer(
            IBatchContainer container,
            DefaultMaterialSet materials,
            int layer = 0, 
            RasterizerState rasterizerState = null,
            DepthStencilState depthStencilState = null,
            BlendState blendState = null,
            SamplerState samplerState = null,
            bool worldSpace = true,
            bool useZBuffer = false,
            bool autoIncrementSortKey = false,
            bool autoIncrementLayer = false
        )
        {
            if (container == null)
                throw new ArgumentNullException("container");
            if (materials == null)
                throw new ArgumentNullException("materials");

            Container = container;
            Materials = materials;
            Layer = layer;
            RasterizerState = rasterizerState;
            DepthStencilState = depthStencilState;
            BlendState = blendState;
            SamplerState = samplerState;
            UseZBuffer = useZBuffer;
            WorldSpace = worldSpace;
            AutoIncrementSortKey = autoIncrementSortKey;
            AutoIncrementLayer = autoIncrementLayer;
            NextSortKey = 0;
            PreviousBatch = null;
        }
        static Texture2D LoadTextureStream(string path)
        {
            string fullPath = Path.Combine(Environment.CurrentDirectory, Constants.DataDirectory, baseArtDirectory, path);
            Console.WriteLine(fullPath);

            Texture2D file = null;
            RenderTarget2D result = null;

            using (FileStream stream = new FileStream(fullPath, FileMode.Open))
            {
                file = Texture2D.FromStream(device, stream);
            }

            //Setup a render target to hold our final texture which will have premulitplied alpha values
            result = new RenderTarget2D(device, file.Width, file.Height);

            device.SetRenderTarget(result);
            device.Clear(Color.Black);

            //Multiply each color by the source alpha, and write in just the color values into the final texture
            if (blendColor == null)
            {
                blendColor = new BlendState();
                blendColor.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue;

                blendColor.AlphaDestinationBlend = Blend.Zero;
                blendColor.ColorDestinationBlend = Blend.Zero;

                blendColor.AlphaSourceBlend = Blend.SourceAlpha;
                blendColor.ColorSourceBlend = Blend.SourceAlpha;
            }

            SpriteBatch spriteBatch = new SpriteBatch(device);
            spriteBatch.Begin(SpriteSortMode.Immediate, blendColor);
            spriteBatch.Draw(file, file.Bounds, Color.White);
            spriteBatch.End();

            //Now copy over the alpha values from the PNG source texture to the final one, without multiplying them
            if (blendAlpha == null)
            {
                blendAlpha = new BlendState();
                blendAlpha.ColorWriteChannels = ColorWriteChannels.Alpha;

                blendAlpha.AlphaDestinationBlend = Blend.Zero;
                blendAlpha.ColorDestinationBlend = Blend.Zero;

                blendAlpha.AlphaSourceBlend = Blend.One;
                blendAlpha.ColorSourceBlend = Blend.One;
            }

            spriteBatch.Begin(SpriteSortMode.Immediate, blendAlpha);
            spriteBatch.Draw(file, file.Bounds, Color.White);
            spriteBatch.End();

            //Release the GPU back to drawing to the screen
            device.SetRenderTarget(null);

            return result as Texture2D;
        }
Beispiel #24
0
 public virtual void Begin(BlendState blend)
 {
     if (_enabled)
     {
         Scene.RenderManager.End();
         Scene.RenderManager.Begin(_effect, blend);
     }
 }
Beispiel #25
0
 public Layer()
 {
     Color = (ConstantColor)Microsoft.Xna.Framework.Color.White;
     Transform = (ConstantMatrix)Matrix.Identity;
     AddressU = TextureAddressMode.Wrap;
     AddressV = TextureAddressMode.Wrap;
     BlendState = new BlendState();
 }
 public ParticleEffect(Texture2D texture, ParticleType pType, BlendState blend, Camera camera)
 {
     mCamera = camera;
     mParticles = new List<Particle>();
     particleTexture = texture;
     m_pType = pType;
     mBlendType = blend;
 }
		public void Begin () {
			defaultBlendState = premultipliedAlpha ? BlendState.AlphaBlend : BlendState.NonPremultiplied;

			device.RasterizerState = rasterizerState;
			device.BlendState = defaultBlendState;

			effect.Projection = Matrix.CreateOrthographicOffCenter(0, device.Viewport.Width, device.Viewport.Height, 0, 1, 0);
		}
Beispiel #28
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState)
 {
     _sortMode = sortMode;
     _blendState = (blendState == null) ? BlendState.AlphaBlend : blendState;
     _depthStencilState = DepthStencilState.None;
     _samplerState = SamplerState.LinearClamp;
     _rasterizerState = RasterizerState.CullCounterClockwise;
     _matrix = Matrix.Identity;
 }
Beispiel #29
0
		/// <summary>
		/// creates the Batcher and loads the texture if it is available
		/// </summary>
		void init()
		{
			// prep our custom BlendState and set the Material with it
			var blendState = new BlendState();
			blendState.ColorSourceBlend = blendState.AlphaSourceBlend = _emitterConfig.blendFuncSource;
			blendState.ColorDestinationBlend = blendState.AlphaDestinationBlend = _emitterConfig.blendFuncDestination;

			material = new Material( blendState );
		}
Beispiel #30
0
 public void Begin()
 {
     _sortMode = SpriteSortMode.Deferred;
     _blendState = BlendState.AlphaBlend;
     _depthStencilState = DepthStencilState.None;
     _samplerState = SamplerState.LinearClamp;
     _rasterizerState = RasterizerState.CullCounterClockwise;
     _matrix = Matrix.Identity;
 }
        /// <summary>
        /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
        /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
        /// </summary>
        public override void BindBlendState()
        {
            if (!base.IsBound)
            {
                //If blending is enabled, create it
                if (this.GetBlendEnable(0))
                {
                    _blendState = new XFG.BlendState();
                    //Set alpha properties
                    _blendState.AlphaBlendFunction    = XNAHelper.ToXNABlendFunction(base.AlphaBlendFunction);
                    _blendState.AlphaSourceBlend      = XNAHelper.ToXNABlend(base.AlphaSourceBlend);
                    _blendState.AlphaDestinationBlend = XNAHelper.ToXNABlend(base.AlphaDestinationBlend);

                    //Set color properties
                    _blendState.ColorBlendFunction    = XNAHelper.ToXNABlendFunction(base.ColorBlendFunction);
                    _blendState.ColorSourceBlend      = XNAHelper.ToXNABlend(base.ColorSourceBlend);
                    _blendState.ColorDestinationBlend = XNAHelper.ToXNABlend(base.ColorDestinationBlend);

                    //Set blend factor
                    XNA.Color c;
                    Color     bf = base.BlendFactor;
                    XNAHelper.ConvertColor(ref bf, out c);
                    _blendState.BlendFactor = c;

                    //Set multisample bitmask
                    _blendState.MultiSampleMask = base.MultiSampleMask;

                    //Set color write bitmasks
                    _blendState.ColorWriteChannels  = (XFG.ColorWriteChannels) this.GetWriteChannels(0);
                    _blendState.ColorWriteChannels1 = (XFG.ColorWriteChannels) this.GetWriteChannels(1);
                    _blendState.ColorWriteChannels2 = (XFG.ColorWriteChannels) this.GetWriteChannels(2);
                    _blendState.ColorWriteChannels3 = (XFG.ColorWriteChannels) this.GetWriteChannels(3);
                }
                else
                {
                    //Otherwise if it is -not- enabled, just re-use the opaque state - guaranteed to never change
                    _blendState = XFG.BlendState.Opaque;
                }
                base.IsBound = true;
            }
        }
Beispiel #32
0
        public void Enable()
        {
            if (desc.blendEnable)
            {
                var blendState = new X.BlendState()
                {
                    ColorWriteChannels = desc.renderTargetWriteMask,

                    ColorBlendFunction    = desc.blendOp,
                    ColorSourceBlend      = desc.srcBlend,
                    ColorDestinationBlend = desc.dstBlend,

                    AlphaBlendFunction    = desc.blendOpAlpha,
                    AlphaSourceBlend      = desc.srcBlendAlpha,
                    AlphaDestinationBlend = desc.dstBlendAlpha
                };

                video.Device.BlendState = blendState;
            }
            else
            {
                video.Device.BlendState = X.BlendState.Opaque;
            }
        }
Beispiel #33
0
 public void Begin(SpriteBlendMode blendMode)
 {
     // GG EDIT
     Begin(SpriteSortMode.Deferred, BlendState.FromSpriteBlendMode(blendMode), SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
 }
Beispiel #34
0
 public void Begin(SpriteBlendMode blendMode, SpriteSortMode sortMode, SaveStateMode saveStateMode)
 {
     // GG EDIT
     // GG TODO implement saveStateMode
     Begin(sortMode, BlendState.FromSpriteBlendMode(blendMode), SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
 }
Beispiel #35
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState)
 {
     Begin(sortMode, blendState, null, null, null, null, Matrix.Identity);
 }
Beispiel #36
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState)
 {
     this.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, (Effect)null, Matrix.Identity);
 }
Beispiel #37
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState)
 {
     Begin(sortMode, blendState, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity);
 }
Beispiel #38
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect)
 {
     Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, Matrix.Identity);
 }
Beispiel #39
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, RasterizerState rasterizerState, Effect effect)
 {
 }
Beispiel #40
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, Shader[] shaders)
        {
            var count  = (int)reader.ReadByte();
            var passes = new EffectPass[count];

            for (var i = 0; i < count; i++)
            {
                var name        = reader.ReadString();
                var annotations = ReadAnnotations(reader);

                // Get the vertex shader.
                Shader vertexShader = null;
                var    shaderIndex  = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    vertexShader = shaders[shaderIndex];
                }

                // Get the pixel shader.
                Shader pixelShader = null;
                shaderIndex = (int)reader.ReadByte();
                if (shaderIndex != 255)
                {
                    pixelShader = shaders[shaderIndex];
                }

                BlendState        blend  = null;
                DepthStencilState depth  = null;
                RasterizerState   raster = null;
                if (reader.ReadBoolean())
                {
                    blend = new BlendState
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    depth = new DepthStencilState
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean(),
                    };
                }
                if (reader.ReadBoolean())
                {
                    raster = new RasterizerState
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle(),
                    };
                }

                passes[i] = new EffectPass(effect, name, vertexShader, pixelShader, blend, depth, raster, annotations);
            }

            return(new EffectPassCollection(passes));
        }
Beispiel #41
0
 public void Begin(SpriteSortMode sortMode, BlendState blendState)
 {
 }
Beispiel #42
0
        private static EffectPassCollection ReadPasses(BinaryReader reader, Effect effect, List <Shader> shaders)
        {
            Shader vertexShader = (Shader)null;
            Shader pixelShader  = (Shader)null;
            EffectPassCollection effectPassCollection = new EffectPassCollection();
            int num = (int)reader.ReadByte();

            for (int index1 = 0; index1 < num; ++index1)
            {
                string name = reader.ReadString();
                EffectAnnotationCollection annotations = Effect.ReadAnnotations(reader);
                int index2 = (int)reader.ReadByte();
                if (index2 != (int)byte.MaxValue)
                {
                    vertexShader = shaders[index2];
                }
                int index3 = (int)reader.ReadByte();
                if (index3 != (int)byte.MaxValue)
                {
                    pixelShader = shaders[index3];
                }
                BlendState        blendState        = (BlendState)null;
                DepthStencilState depthStencilState = (DepthStencilState)null;
                RasterizerState   rasterizerState   = (RasterizerState)null;
                if (reader.ReadBoolean())
                {
                    blendState = new BlendState()
                    {
                        AlphaBlendFunction    = (BlendFunction)reader.ReadByte(),
                        AlphaDestinationBlend = (Blend)reader.ReadByte(),
                        AlphaSourceBlend      = (Blend)reader.ReadByte(),
                        BlendFactor           = new Color((int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte(), (int)reader.ReadByte()),
                        ColorBlendFunction    = (BlendFunction)reader.ReadByte(),
                        ColorDestinationBlend = (Blend)reader.ReadByte(),
                        ColorSourceBlend      = (Blend)reader.ReadByte(),
                        ColorWriteChannels    = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels1   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels2   = (ColorWriteChannels)reader.ReadByte(),
                        ColorWriteChannels3   = (ColorWriteChannels)reader.ReadByte(),
                        MultiSampleMask       = reader.ReadInt32()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    depthStencilState = new DepthStencilState()
                    {
                        CounterClockwiseStencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFail            = (StencilOperation)reader.ReadByte(),
                        CounterClockwiseStencilFunction        = (CompareFunction)reader.ReadByte(),
                        CounterClockwiseStencilPass            = (StencilOperation)reader.ReadByte(),
                        DepthBufferEnable      = reader.ReadBoolean(),
                        DepthBufferFunction    = (CompareFunction)reader.ReadByte(),
                        DepthBufferWriteEnable = reader.ReadBoolean(),
                        ReferenceStencil       = reader.ReadInt32(),
                        StencilDepthBufferFail = (StencilOperation)reader.ReadByte(),
                        StencilEnable          = reader.ReadBoolean(),
                        StencilFail            = (StencilOperation)reader.ReadByte(),
                        StencilFunction        = (CompareFunction)reader.ReadByte(),
                        StencilMask            = reader.ReadInt32(),
                        StencilPass            = (StencilOperation)reader.ReadByte(),
                        StencilWriteMask       = reader.ReadInt32(),
                        TwoSidedStencilMode    = reader.ReadBoolean()
                    }
                }
                ;
                if (reader.ReadBoolean())
                {
                    rasterizerState = new RasterizerState()
                    {
                        CullMode             = (CullMode)reader.ReadByte(),
                        DepthBias            = reader.ReadSingle(),
                        FillMode             = (FillMode)reader.ReadByte(),
                        MultiSampleAntiAlias = reader.ReadBoolean(),
                        ScissorTestEnable    = reader.ReadBoolean(),
                        SlopeScaleDepthBias  = reader.ReadSingle()
                    }
                }
                ;
                EffectPass pass = new EffectPass(effect, name, vertexShader, pixelShader, blendState, depthStencilState, rasterizerState, annotations);
                effectPassCollection.Add(pass);
            }
            return(effectPassCollection);
        }