LOS color is based on ambient light, added a parallax effect to background particles

This commit is contained in:
Regalis
2016-10-27 18:41:00 +03:00
parent 29ad3d2555
commit 2f3d3ba9ea
2 changed files with 22 additions and 9 deletions

View File

@@ -126,21 +126,32 @@ namespace Barotrauma
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.Additive,
SamplerState.LinearWrap, DepthStencilState.Default, null, null,
cam.Transform);
for (int i = 1; i < 2; i++)
for (int i = 1; i < 4; i++)
{
Vector2 offset = new Vector2(cam.WorldView.X, cam.WorldView.Y);
float scale = 1.0f - i * 0.2f;
dustParticles.SourceRect = new Rectangle((int)(offset.X), (int)(-offset.Y), (int)(1024), (int)(1024));
//alpha goes from 1.0 to 0.0 when scale is in the range of 0.2-0.1
float alpha = (cam.Zoom * scale) < 0.2f ? (cam.Zoom * scale - 0.1f) * 10.0f : 1.0f;
if (alpha <= 0.0f) continue;
Vector2 offset = (new Vector2(cam.WorldViewCenter.X, cam.WorldViewCenter.Y) + dustOffset) * scale;
Vector3 origin = new Vector3(cam.WorldView.Width, cam.WorldView.Height, 0.0f) * 0.5f;
dustParticles.DrawTiled(spriteBatch, new Vector2(cam.WorldView.X, -cam.WorldView.Y),
new Vector2(cam.WorldView.Width, cam.WorldView.Height),
Vector2.Zero, Color.White);
dustParticles.SourceRect = new Rectangle(
(int)((offset.X - origin.X + (i * 256)) / scale),
(int)((-offset.Y - origin.Y + (i * 256)) / scale),
(int)((cam.WorldView.Width) / scale),
(int)((cam.WorldView.Height) / scale));
spriteBatch.Draw(dustParticles.Texture,
new Vector2(cam.WorldViewCenter.X, -cam.WorldViewCenter.Y),
dustParticles.SourceRect, Color.White * alpha, 0.0f,
new Vector2(cam.WorldView.Width, cam.WorldView.Height) * 0.5f / scale, scale, SpriteEffects.None, 0);
}
spriteBatch.End();

View File

@@ -12,6 +12,8 @@ namespace Barotrauma
{
Camera cam;
Color waterColor = new Color(0.75f, 0.8f, 0.9f, 1.0f);
readonly RenderTarget2D renderTargetBackground;
readonly RenderTarget2D renderTarget;
readonly RenderTarget2D renderTargetWater;
@@ -268,7 +270,7 @@ namespace Barotrauma
spriteBatch.Begin(SpriteSortMode.Deferred,
BlendState.Opaque);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), new Color(0.75f, 0.8f, 0.9f, 1.0f));
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), waterColor);
spriteBatch.End();
#if LINUX
@@ -404,7 +406,7 @@ namespace Barotrauma
float r = Math.Min(CharacterHUD.damageOverlayTimer * 0.5f, 0.5f);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
Color.Lerp(new Color(0.1f, 0.1f, 0.1f), Color.Red, r));
Color.Lerp(GameMain.LightManager.AmbientLight*0.5f, Color.Red, r));
spriteBatch.End();
}