GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw(box1, Vector2.Zero, Color.White); spriteBatch.Draw(box2, new Vector2(40, 50), Color.White); spriteBatch.Draw(box4, new Vector2(150, 50), Color.White); spriteBatch.Draw(box3, new Vector2(260, 50), Color.White); spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront, blendState);
var blendState = BlendState.Additive;
var blendState = new BlendState(); blendState.AlphaBlendFunction = BlendFunction.Add; blendState.AlphaDestinationBlend = Blend.One; blendState.AlphaSourceBlend = Blend.SourceAlpha; blendState.BlendFactor = Color.White; blendState.ColorBlendFunction = BlendFunction.Add; blendState.ColorDestinationBlend = Blend.One; blendState.ColorSourceBlend = Blend.SourceAlpha; blendState.ColorWriteChannels = ColorWriteChannels.All; blendState.ColorWriteChannels1 = ColorWriteChannels.All; blendState.ColorWriteChannels2 = ColorWriteChannels.All; blendState.ColorWriteChannels3 = ColorWriteChannels.All; blendState.MultiSampleMask = -1;
// 1. . GraphicsDevice.SetRenderTarget(backgroundSprite); GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(); spriteBatch.Draw(background, Vector2.Zero, Color.White); spriteBatch.End(); // 2. . GraphicsDevice.SetRenderTarget(foregroundSprite); GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(); spriteBatch.Draw(foreground, Vector2.Zero, Color.White); spriteBatch.End(); // 3. . GraphicsDevice.SetRenderTarget(foregroundShadow); GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw(foregroundSprite, Vector2.Zero, Color.White); spriteBatch.Draw(light, new Vector2(620, 490), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.Draw(light, new Vector2(100, 500), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.Draw(light, new Vector2(620, 90), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.Draw(light, new Vector2(290, 270), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.Draw(light, new Vector2(400, 270), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.Draw(light, new Vector2(510, 270), null, Color.White, 0.0f, new Vector2(light.Width / 2, light.Height / 2), 1.0f, SpriteEffects.None, 0.0f); spriteBatch.End(); // . GraphicsDevice.SetRenderTarget(null); GraphicsDevice.Clear(Color.Black); // 1. . // 2. . spriteBatch.Begin(); spriteBatch.Draw(sky, Vector2.Zero, Color.White); spriteBatch.Draw(backgroundSprite, Vector2.Zero, Color.White); spriteBatch.End(); // BlendState. var blendState = new BlendState(); blendState.AlphaBlendFunction = BlendFunction.ReverseSubtract; blendState.AlphaDestinationBlend = Blend.One; blendState.AlphaSourceBlend = Blend.BlendFactor; // -0.9 (255 * 0.9 = 230, BlendFunction.ReverseSubtract = -1) { blendState.BlendFactor = new Color(230, 230, 230, 255); blendState.ColorBlendFunction = BlendFunction.ReverseSubtract; } blendState.ColorDestinationBlend = Blend.One; blendState.ColorSourceBlend = Blend.BlendFactor; blendState.ColorWriteChannels = ColorWriteChannels.All; blendState.ColorWriteChannels1 = ColorWriteChannels.All; blendState.ColorWriteChannels2 = ColorWriteChannels.All; blendState.ColorWriteChannels3 = ColorWriteChannels.All; blendState.MultiSampleMask = -1; // 3. , -0.9. spriteBatch.Begin(SpriteSortMode.BackToFront, blendState); spriteBatch.Draw(backgroundSprite, Vector2.Zero, Color.White); spriteBatch.End(); // 4. . spriteBatch.Begin(); spriteBatch.Draw(foregroundSprite, Vector2.Zero, Color.White); spriteBatch.End(); // 5. , -0.9. spriteBatch.Begin(SpriteSortMode.BackToFront, blendState); spriteBatch.Draw(foregroundShadow, Vector2.Zero, Color.White); spriteBatch.End(); // 6. . spriteBatch.Begin(); spriteBatch.Draw(menu, Vector2.Zero, Color.White); spriteBatch.End();
Source: https://habr.com/ru/post/241760/
All Articles