Optimized GameScreen.DrawMap
- Downscaled lightmap, since blurring will make this unnoticeable anyway (TODO: make this optional) - Render LOS in fewer passes by using a shader - Use light volume to calculate LOS - This also means we can use the override texture to render the diving suit obstruct effect - Don't render bunks and labels onto LOS background (TODO: add the option to render back into the LOS background, i.e. just use multiplicative blending as if it was the lightmap) - Prefer SpriteSortMode.Deferred over all others, prefer SamplerState.LinearClamp/PointClamp over all others - Remove shader blur in favor of geometry blur (TODO: improve on this further, right now it has a few artifacts) - Trim light volumes - Do some weird shit with the background particles (use DrawTiled instead of relying on SamplerState.LinearWrap, because that's faster somehow :/ ) - Pressing up/down in the console only returns a typed command now
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using Barotrauma.Particles;
|
using Barotrauma.Particles;
|
||||||
using FarseerPhysics;
|
using FarseerPhysics;
|
||||||
using FarseerPhysics.Dynamics;
|
using FarseerPhysics.Dynamics;
|
||||||
@@ -299,6 +299,14 @@ namespace Barotrauma
|
|||||||
if (info != null)
|
if (info != null)
|
||||||
{
|
{
|
||||||
Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
|
Vector2 namePos = new Vector2(pos.X, pos.Y - 110.0f - (5.0f / cam.Zoom)) - GUI.Font.MeasureString(Info.Name) * 0.5f / cam.Zoom;
|
||||||
|
Vector2 screenSize = new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||||
|
Vector2 viewportSize = new Vector2(cam.WorldView.Width, cam.WorldView.Height);
|
||||||
|
namePos.X -= cam.WorldView.X; namePos.Y += cam.WorldView.Y;
|
||||||
|
namePos *= screenSize / viewportSize;
|
||||||
|
namePos.X = (float)Math.Floor(namePos.X); namePos.Y = (float)Math.Floor(namePos.Y);
|
||||||
|
namePos *= viewportSize / screenSize;
|
||||||
|
namePos.X += cam.WorldView.X; namePos.Y -= cam.WorldView.Y;
|
||||||
|
|
||||||
Color nameColor = Color.White;
|
Color nameColor = Color.White;
|
||||||
|
|
||||||
if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
|
if (Character.Controlled != null && TeamID != Character.Controlled.TeamID)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using EventInput;
|
using EventInput;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered)
|
public GUIMessage(string text, Color color, Vector2 position, float lifeTime, Alignment textAlignment, bool centered)
|
||||||
{
|
{
|
||||||
coloredText = new ColoredText(text, color);
|
coloredText = new ColoredText(text, color, false);
|
||||||
pos = position;
|
pos = position;
|
||||||
this.lifeTime = lifeTime;
|
this.lifeTime = lifeTime;
|
||||||
this.Alignment = textAlignment;
|
this.Alignment = textAlignment;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Barotrauma.Lights;
|
using Barotrauma.Lights;
|
||||||
using Barotrauma.Particles;
|
using Barotrauma.Particles;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System;
|
using System;
|
||||||
@@ -76,9 +76,9 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lightSource.Range = Math.Max(size.X, size.Y) * 10.0f / 2.0f;
|
|
||||||
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
|
lightSource.Color = new Color(1.0f, 0.45f, 0.3f) * Rand.Range(0.8f, 1.0f);
|
||||||
lightSource.Position = position + Vector2.UnitY * 30.0f;
|
if (Math.Abs((lightSource.Range * 0.2f) - Math.Max(size.X, size.Y)) > 1.0f) lightSource.Range = Math.Max(size.X, size.Y) * 5.0f;
|
||||||
|
if (Vector2.DistanceSquared(lightSource.Position,position) > 5.0f) lightSource.Position = position + Vector2.UnitY * 30.0f;
|
||||||
|
|
||||||
if (size.X > 256.0f)
|
if (size.X > 256.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -63,6 +63,7 @@ namespace Barotrauma
|
|||||||
public void Update(float deltaTime)
|
public void Update(float deltaTime)
|
||||||
{
|
{
|
||||||
dustOffset -= Vector2.UnitY * 10.0f * deltaTime;
|
dustOffset -= Vector2.UnitY * 10.0f * deltaTime;
|
||||||
|
while (dustOffset.Y <= -1024.0f) dustOffset.Y += 1024.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VertexPositionColorTexture[] GetColoredVertices(VertexPositionTexture[] vertices, Color color)
|
public static VertexPositionColorTexture[] GetColoredVertices(VertexPositionTexture[] vertices, Color color)
|
||||||
@@ -108,7 +109,7 @@ namespace Barotrauma
|
|||||||
Vector2 backgroundPos = cam.WorldViewCenter;
|
Vector2 backgroundPos = cam.WorldViewCenter;
|
||||||
|
|
||||||
backgroundPos.Y = -backgroundPos.Y;
|
backgroundPos.Y = -backgroundPos.Y;
|
||||||
backgroundPos /= 20.0f;
|
backgroundPos *= 0.05f;
|
||||||
|
|
||||||
if (backgroundPos.Y < 1024)
|
if (backgroundPos.Y < 1024)
|
||||||
{
|
{
|
||||||
@@ -130,35 +131,38 @@ namespace Barotrauma
|
|||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
spriteBatch.Begin(SpriteSortMode.Deferred,
|
||||||
BlendState.AlphaBlend,
|
BlendState.AlphaBlend,
|
||||||
SamplerState.LinearWrap, DepthStencilState.Default, null, null,
|
SamplerState.LinearWrap, DepthStencilState.Default, null, null,
|
||||||
cam.Transform);
|
cam.Transform);
|
||||||
|
|
||||||
|
Vector2 origin = new Vector2(cam.WorldView.X, -cam.WorldView.Y);
|
||||||
|
Vector2 offset = -origin + dustOffset;
|
||||||
|
while (offset.X <= -1024.0f) offset.X += 1024.0f;
|
||||||
|
while (offset.X > 0.0f) offset.X -= 1024.0f;
|
||||||
|
while (offset.Y <= -1024.0f) offset.Y += 1024.0f;
|
||||||
|
while (offset.Y > 0.0f) offset.Y -= 1024.0f;
|
||||||
|
|
||||||
if (backgroundSpriteManager != null) backgroundSpriteManager.DrawSprites(spriteBatch, cam);
|
if (backgroundSpriteManager != null) backgroundSpriteManager.DrawSprites(spriteBatch, cam);
|
||||||
if (backgroundCreatureManager != null) backgroundCreatureManager.Draw(spriteBatch);
|
if (backgroundCreatureManager != null) backgroundCreatureManager.Draw(spriteBatch);
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
float scale = 1.0f - i * 0.2f;
|
float scale = 1.0f - i * 0.2f;
|
||||||
|
float recipScale = 1.0f / scale;
|
||||||
|
|
||||||
//alpha goes from 1.0 to 0.0 when scale is in the range of 0.2-0.1
|
//alpha goes from 1.0 to 0.0 when scale is in the range of 0.5-0.25
|
||||||
float alpha = (cam.Zoom * scale) < 0.2f ? (cam.Zoom * scale - 0.1f) * 10.0f : 1.0f;
|
float alpha = (cam.Zoom * scale) < 0.5f ? (cam.Zoom * scale - 0.25f) * 40.0f : 1.0f;
|
||||||
if (alpha <= 0.0f) continue;
|
if (alpha <= 0.0f) continue;
|
||||||
|
|
||||||
Vector2 offset = (new Vector2(cam.WorldViewCenter.X, cam.WorldViewCenter.Y) + dustOffset) * scale;
|
Vector2 offsetS = offset * scale + new Vector2(cam.WorldView.Width, cam.WorldView.Height) * (1.0f - scale) * 0.5f - new Vector2(256.0f * i);
|
||||||
Vector3 origin = new Vector3(cam.WorldView.Width, cam.WorldView.Height, 0.0f) * 0.5f;
|
while (offsetS.X <= -1024.0f*scale) offsetS.X += 1024.0f*scale;
|
||||||
|
while (offsetS.X > 0.0f) offsetS.X -= 1024.0f*scale;
|
||||||
|
while (offsetS.Y <= -1024.0f*scale) offsetS.Y += 1024.0f*scale;
|
||||||
|
while (offsetS.Y > 0.0f) offsetS.Y -= 1024.0f*scale;
|
||||||
|
|
||||||
dustParticles.SourceRect = new Rectangle(
|
Rectangle srcRect = new Rectangle(0, 0, 2048, 2048);
|
||||||
(int)((offset.X - origin.X + (i * 256)) / scale),
|
dustParticles.DrawTiled(spriteBatch, origin + offsetS, new Vector2(cam.WorldView.Width - offsetS.X, cam.WorldView.Height - offsetS.Y), Vector2.Zero, srcRect, Color.White * alpha, new Vector2(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, 1.0f - scale);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
@@ -13,7 +13,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public VertexPositionTexture[] vertices = new VertexPositionTexture[DefaultBufferSize];
|
public VertexPositionTexture[] vertices = new VertexPositionTexture[DefaultBufferSize];
|
||||||
|
|
||||||
private Effect waterEffect;
|
public Effect waterEffect
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
private BasicEffect basicEffect;
|
private BasicEffect basicEffect;
|
||||||
|
|
||||||
public int PositionInBuffer = 0;
|
public int PositionInBuffer = 0;
|
||||||
@@ -93,7 +97,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
|
|
||||||
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
|
graphicsDevice.SamplerStates[0] = SamplerState.PointWrap;
|
||||||
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
|
graphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, vertices.Length / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -23,7 +23,17 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
public Color AmbientLight;
|
public Color AmbientLight;
|
||||||
|
|
||||||
RenderTarget2D lightMap, losTexture;
|
private float lightmapScale = 0.5f;
|
||||||
|
public RenderTarget2D lightMap
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
public RenderTarget2D losTexture
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
BasicEffect lightEffect;
|
BasicEffect lightEffect;
|
||||||
|
|
||||||
@@ -36,8 +46,9 @@ namespace Barotrauma.Lights
|
|||||||
public bool LightingEnabled = true;
|
public bool LightingEnabled = true;
|
||||||
|
|
||||||
public bool ObstructVision;
|
public bool ObstructVision;
|
||||||
|
LightSource losSource;
|
||||||
|
|
||||||
private Texture2D visionCircle;
|
private Sprite visionCircle;
|
||||||
|
|
||||||
private Dictionary<Hull, Color> hullAmbientLights;
|
private Dictionary<Hull, Color> hullAmbientLights;
|
||||||
private Dictionary<Hull, Color> smoothedHullAmbientLights;
|
private Dictionary<Hull, Color> smoothedHullAmbientLights;
|
||||||
@@ -50,21 +61,26 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
AmbientLight = new Color(20, 20, 20, 255);
|
AmbientLight = new Color(20, 20, 20, 255);
|
||||||
|
|
||||||
visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png");
|
//visionCircle = Sprite.LoadTexture("Content/Lights/visioncircle.png");
|
||||||
|
visionCircle = new Sprite("Content/Lights/visioncircle.png", new Vector2(0.2f, 0.5f));
|
||||||
|
|
||||||
var pp = graphics.PresentationParameters;
|
var pp = graphics.PresentationParameters;
|
||||||
|
|
||||||
lightMap = new RenderTarget2D(graphics,
|
lightMap = new RenderTarget2D(graphics,
|
||||||
GameMain.GraphicsWidth, GameMain.GraphicsHeight, false,
|
(int)(GameMain.GraphicsWidth*lightmapScale), (int)(GameMain.GraphicsHeight*lightmapScale), false,
|
||||||
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount,
|
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount,
|
||||||
RenderTargetUsage.DiscardContents);
|
RenderTargetUsage.DiscardContents);
|
||||||
|
|
||||||
losTexture = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
losTexture = new RenderTarget2D(graphics, (int)(GameMain.GraphicsWidth*lightmapScale), (int)(GameMain.GraphicsHeight*lightmapScale), false, SurfaceFormat.Alpha8, DepthFormat.None);
|
||||||
|
|
||||||
|
losSource = new LightSource(Vector2.Zero, GameMain.GraphicsWidth, Color.White, null, false);
|
||||||
|
losSource.texture = new Texture2D(graphics, 1, 1);
|
||||||
|
losSource.texture.SetData(new Color[] { Color.White });// fill the texture with white
|
||||||
|
|
||||||
if (lightEffect == null)
|
if (lightEffect == null)
|
||||||
{
|
{
|
||||||
lightEffect = new BasicEffect(GameMain.Instance.GraphicsDevice);
|
lightEffect = new BasicEffect(GameMain.Instance.GraphicsDevice);
|
||||||
lightEffect.VertexColorEnabled = false;
|
lightEffect.VertexColorEnabled = true;
|
||||||
|
|
||||||
lightEffect.TextureEnabled = true;
|
lightEffect.TextureEnabled = true;
|
||||||
lightEffect.Texture = LightSource.LightTexture;
|
lightEffect.Texture = LightSource.LightTexture;
|
||||||
@@ -142,7 +158,7 @@ namespace Barotrauma.Lights
|
|||||||
graphics.Clear(AmbientLight);
|
graphics.Clear(AmbientLight);
|
||||||
graphics.BlendState = BlendState.Additive;
|
graphics.BlendState = BlendState.Additive;
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform);
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, null, null, null, cam.Transform * Matrix.CreateScale(new Vector3(lightmapScale, lightmapScale, 1.0f)));
|
||||||
|
|
||||||
Matrix transform = cam.ShaderTransform
|
Matrix transform = cam.ShaderTransform
|
||||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||||
@@ -159,7 +175,7 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
lightEffect.World = Matrix.CreateTranslation(offset) * transform;
|
lightEffect.World = Matrix.CreateTranslation(offset) * transform;
|
||||||
|
|
||||||
GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive);
|
//GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive);
|
||||||
|
|
||||||
if (Character.Controlled != null)
|
if (Character.Controlled != null)
|
||||||
{
|
{
|
||||||
@@ -201,56 +217,43 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
public void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition)
|
public void UpdateObstructVision(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Vector2 lookAtPosition)
|
||||||
{
|
{
|
||||||
if (!LosEnabled && !ObstructVision) return;
|
if (!LosEnabled || ViewTarget == null) return;
|
||||||
|
|
||||||
graphics.SetRenderTarget(losTexture);
|
graphics.SetRenderTarget(losTexture);
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cam.Transform);
|
//--------------------------------------
|
||||||
|
|
||||||
|
graphics.Clear(Color.Black);
|
||||||
if (ObstructVision)
|
if (ObstructVision)
|
||||||
{
|
{
|
||||||
//graphics.Clear(Color.Black);
|
|
||||||
|
|
||||||
Vector2 diff = lookAtPosition - ViewTarget.WorldPosition;
|
Vector2 diff = lookAtPosition - ViewTarget.WorldPosition;
|
||||||
diff.Y = -diff.Y;
|
|
||||||
float rotation = MathUtils.VectorToAngle(diff);
|
float rotation = MathUtils.VectorToAngle(diff);
|
||||||
|
|
||||||
Vector2 scale = new Vector2(MathHelper.Clamp(diff.Length()/256.0f, 2.0f, 5.0f), 2.0f);
|
Vector2 scale = new Vector2(MathHelper.Clamp(diff.Length() / 256.0f, 2.0f, 5.0f), 2.0f) * 0.3f;
|
||||||
|
|
||||||
spriteBatch.Draw(visionCircle, new Vector2(ViewTarget.WorldPosition.X, -ViewTarget.WorldPosition.Y), null, Color.White, rotation,
|
visionCircle.size = new Vector2(visionCircle.SourceRect.Width * scale.X, visionCircle.SourceRect.Height * scale.Y);
|
||||||
new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f);
|
losSource.overrideLightTexture = visionCircle;
|
||||||
|
losSource.Rotation = rotation;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
graphics.Clear(Color.White);
|
losSource.overrideLightTexture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
spriteBatch.End();
|
graphics.BlendState = BlendState.Additive;
|
||||||
|
|
||||||
//--------------------------------------
|
Vector2 pos = ViewTarget.Position;
|
||||||
|
losSource.Position = pos;
|
||||||
|
losSource.NeedsRecalculation = true;
|
||||||
|
losSource.ParentSub = ViewTarget.Submarine;
|
||||||
|
|
||||||
if (LosEnabled && ViewTarget != null)
|
Matrix transform = cam.ShaderTransform
|
||||||
{
|
|
||||||
Vector2 pos = ViewTarget.WorldPosition;
|
|
||||||
|
|
||||||
Rectangle camView = new Rectangle(cam.WorldView.X, cam.WorldView.Y - cam.WorldView.Height, cam.WorldView.Width, cam.WorldView.Height);
|
|
||||||
|
|
||||||
Matrix shadowTransform = cam.ShaderTransform
|
|
||||||
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
* Matrix.CreateOrthographic(GameMain.GraphicsWidth, GameMain.GraphicsHeight, -1, 1) * 0.5f;
|
||||||
|
|
||||||
var convexHulls = ConvexHull.GetHullsInRange(viewTarget.Position, cam.WorldView.Width*0.75f, viewTarget.Submarine);
|
losSource.Draw(spriteBatch, lightEffect, transform);
|
||||||
|
|
||||||
if (convexHulls != null)
|
graphics.BlendState = BlendState.AlphaBlend;
|
||||||
{
|
|
||||||
foreach (ConvexHull convexHull in convexHulls)
|
|
||||||
{
|
|
||||||
if (!convexHull.Intersects(camView)) continue;
|
|
||||||
//if (!camView.Intersects(convexHull.BoundingBox)) continue;
|
|
||||||
|
|
||||||
convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
graphics.SetRenderTarget(null);
|
graphics.SetRenderTarget(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,22 +341,11 @@ namespace Barotrauma.Lights
|
|||||||
{
|
{
|
||||||
if (!LightingEnabled) return;
|
if (!LightingEnabled) return;
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, effect);
|
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null, null);
|
||||||
spriteBatch.Draw(lightMap, Vector2.Zero, Color.White);
|
spriteBatch.Draw(lightMap, new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.White);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawLOS(SpriteBatch spriteBatch, Effect effect,bool renderingBackground)
|
|
||||||
{
|
|
||||||
if (!LosEnabled || ViewTarget == null) return;
|
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, renderingBackground ? CustomBlendStates.LOS : CustomBlendStates.Multiplicative, null, null, null, effect);
|
|
||||||
spriteBatch.Draw(losTexture, Vector2.Zero, Color.White);
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
if (!renderingBackground) ObstructVision = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ClearLights()
|
public void ClearLights()
|
||||||
{
|
{
|
||||||
lights.Clear();
|
lights.Clear();
|
||||||
@@ -376,16 +368,10 @@ namespace Barotrauma.Lights
|
|||||||
MultiplyWithAlpha = new BlendState();
|
MultiplyWithAlpha = new BlendState();
|
||||||
MultiplyWithAlpha.ColorDestinationBlend = MultiplyWithAlpha.AlphaDestinationBlend = Blend.One;
|
MultiplyWithAlpha.ColorDestinationBlend = MultiplyWithAlpha.AlphaDestinationBlend = Blend.One;
|
||||||
MultiplyWithAlpha.ColorSourceBlend = MultiplyWithAlpha.AlphaSourceBlend = Blend.DestinationAlpha;
|
MultiplyWithAlpha.ColorSourceBlend = MultiplyWithAlpha.AlphaSourceBlend = Blend.DestinationAlpha;
|
||||||
|
|
||||||
LOS = new BlendState();
|
|
||||||
LOS.ColorSourceBlend = LOS.AlphaSourceBlend = Blend.Zero;
|
|
||||||
LOS.ColorDestinationBlend = LOS.AlphaDestinationBlend = Blend.InverseSourceColor;
|
|
||||||
LOS.ColorBlendFunction = LOS.AlphaBlendFunction = BlendFunction.Add;
|
|
||||||
}
|
}
|
||||||
public static BlendState Multiplicative { get; private set; }
|
public static BlendState Multiplicative { get; private set; }
|
||||||
public static BlendState WriteToAlpha { get; private set; }
|
public static BlendState WriteToAlpha { get; private set; }
|
||||||
public static BlendState MultiplyWithAlpha { get; private set; }
|
public static BlendState MultiplyWithAlpha { get; private set; }
|
||||||
public static BlendState LOS { get; private set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -17,8 +17,8 @@ namespace Barotrauma.Lights
|
|||||||
private Color color;
|
private Color color;
|
||||||
private float range;
|
private float range;
|
||||||
|
|
||||||
private Sprite overrideLightTexture;
|
public Sprite overrideLightTexture;
|
||||||
private Texture2D texture;
|
public Texture2D texture;
|
||||||
|
|
||||||
public Sprite LightSprite;
|
public Sprite LightSprite;
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LightSource(Vector2 position, float range, Color color, Submarine submarine)
|
public LightSource(Vector2 position, float range, Color color, Submarine submarine, bool addLight=true)
|
||||||
{
|
{
|
||||||
hullsInRange = new List<ConvexHullList>();
|
hullsInRange = new List<ConvexHullList>();
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
diffToSub = new Dictionary<Submarine, Vector2>();
|
diffToSub = new Dictionary<Submarine, Vector2>();
|
||||||
|
|
||||||
GameMain.LightManager.AddLight(this);
|
if (addLight) GameMain.LightManager.AddLight(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform)
|
/*public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform)
|
||||||
@@ -322,6 +322,7 @@ namespace Barotrauma.Lights
|
|||||||
hulls.AddRange(chList.List);
|
hulls.AddRange(chList.List);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float bounds = range*2;
|
||||||
//find convexhull segments that are close enough and facing towards the light source
|
//find convexhull segments that are close enough and facing towards the light source
|
||||||
List<Segment> visibleSegments = new List<Segment>();
|
List<Segment> visibleSegments = new List<Segment>();
|
||||||
List<SegmentPoint> points = new List<SegmentPoint>();
|
List<SegmentPoint> points = new List<SegmentPoint>();
|
||||||
@@ -336,6 +337,10 @@ namespace Barotrauma.Lights
|
|||||||
{
|
{
|
||||||
points.Add(s.Start);
|
points.Add(s.Start);
|
||||||
points.Add(s.End);
|
points.Add(s.End);
|
||||||
|
if (Math.Abs(s.Start.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.Start.WorldPos.X - drawPos.X);
|
||||||
|
if (Math.Abs(s.Start.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.Start.WorldPos.Y - drawPos.Y);
|
||||||
|
if (Math.Abs(s.End.WorldPos.X - drawPos.X) > bounds) bounds = Math.Abs(s.End.WorldPos.X - drawPos.X);
|
||||||
|
if (Math.Abs(s.End.WorldPos.Y - drawPos.Y) > bounds) bounds = Math.Abs(s.End.WorldPos.Y - drawPos.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,14 +349,21 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
//(might be more effective to calculate if we actually need these extra points)
|
//(might be more effective to calculate if we actually need these extra points)
|
||||||
var boundaryCorners = new List<SegmentPoint> {
|
var boundaryCorners = new List<SegmentPoint> {
|
||||||
new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y + range*2)),
|
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y + bounds)),
|
||||||
new SegmentPoint(new Vector2(drawPos.X + range*2, drawPos.Y - range*2)),
|
new SegmentPoint(new Vector2(drawPos.X + bounds, drawPos.Y - bounds)),
|
||||||
new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y - range*2)),
|
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y - bounds)),
|
||||||
new SegmentPoint(new Vector2(drawPos.X - range*2, drawPos.Y + range*2))
|
new SegmentPoint(new Vector2(drawPos.X - bounds, drawPos.Y + bounds))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//points.Clear();
|
||||||
points.AddRange(boundaryCorners);
|
points.AddRange(boundaryCorners);
|
||||||
|
|
||||||
|
//visibleSegments.Clear();
|
||||||
|
for (int i=0;i<4;i++)
|
||||||
|
{
|
||||||
|
visibleSegments.Add(new Segment(boundaryCorners[i], boundaryCorners[(i + 1) % 4]));
|
||||||
|
}
|
||||||
|
|
||||||
var compareCCW = new CompareSegmentPointCW(drawPos);
|
var compareCCW = new CompareSegmentPointCW(drawPos);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -368,14 +380,16 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Vector2> output = new List<Vector2>();
|
List<Vector2> output = new List<Vector2>();
|
||||||
|
//List<Pair<int, Vector2>> preOutput = new List<Pair<int, Vector2>>();
|
||||||
|
|
||||||
//remove points that are very close to each other
|
//remove points that are very close to each other
|
||||||
for (int i = 0; i < points.Count - 1; i++)
|
for (int i = 0; i < points.Count - 1; i++)
|
||||||
{
|
{
|
||||||
if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 3 &&
|
if (Math.Abs(points[i].WorldPos.X - points[i + 1].WorldPos.X) < 6 &&
|
||||||
Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 3)
|
Math.Abs(points[i].WorldPos.Y - points[i + 1].WorldPos.Y) < 6)
|
||||||
{
|
{
|
||||||
points.RemoveAt(i + 1);
|
points.RemoveAt(i + 1);
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,32 +399,52 @@ namespace Barotrauma.Lights
|
|||||||
Vector2 dirNormal = new Vector2(-dir.Y, dir.X)*3;
|
Vector2 dirNormal = new Vector2(-dir.Y, dir.X)*3;
|
||||||
|
|
||||||
//do two slightly offset raycasts to hit the segment itself and whatever's behind it
|
//do two slightly offset raycasts to hit the segment itself and whatever's behind it
|
||||||
Vector2 intersection1 = RayCast(drawPos, drawPos + dir * range * 2 - dirNormal, visibleSegments);
|
Pair<int,Vector2> intersection1 = RayCast(drawPos, drawPos + dir * bounds * 2 - dirNormal, visibleSegments);
|
||||||
Vector2 intersection2 = RayCast(drawPos, drawPos + dir * range * 2 + dirNormal, visibleSegments);
|
Pair<int,Vector2> intersection2 = RayCast(drawPos, drawPos + dir * bounds * 2 + dirNormal, visibleSegments);
|
||||||
|
|
||||||
//hit almost the same position -> only add one vertex to output
|
if (intersection1.First < 0) return new List<Vector2>();
|
||||||
if ((Math.Abs(intersection1.X - intersection2.X) < 5 &&
|
if (intersection2.First < 0) return new List<Vector2>();
|
||||||
Math.Abs(intersection1.Y - intersection2.Y) < 5))
|
Segment seg1 = visibleSegments[intersection1.First];
|
||||||
|
Segment seg2 = visibleSegments[intersection2.First];
|
||||||
|
|
||||||
|
bool isPoint1 = MathUtils.LineToPointDistance(seg1.Start.WorldPos, seg1.End.WorldPos, p.WorldPos) < 5.0f;
|
||||||
|
bool isPoint2 = MathUtils.LineToPointDistance(seg2.Start.WorldPos, seg2.End.WorldPos, p.WorldPos) < 5.0f;
|
||||||
|
|
||||||
|
//hit at the current segmentpoint -> place the segmentpoint into the list
|
||||||
|
if (isPoint1 && isPoint2)
|
||||||
{
|
{
|
||||||
output.Add(intersection1);
|
output.Add(p.WorldPos);
|
||||||
}
|
}
|
||||||
else
|
else if (intersection1.First != intersection2.First)
|
||||||
{
|
{
|
||||||
output.Add(intersection1);
|
output.Add(isPoint1 ? p.WorldPos : intersection1.Second);
|
||||||
output.Add(intersection2);
|
output.Add(isPoint2 ? p.WorldPos : intersection2.Second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove points that are very close to each other
|
||||||
|
for (int i = 0; i < output.Count - 1; i++)
|
||||||
|
{
|
||||||
|
if (Math.Abs(output[i].X - output[i + 1].X) < 6 &&
|
||||||
|
Math.Abs(output[i].Y - output[i + 1].Y) < 6)
|
||||||
|
{
|
||||||
|
output.RemoveAt(i + 1);
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 RayCast(Vector2 rayStart, Vector2 rayEnd, List<Segment> segments)
|
private Pair<int,Vector2> RayCast(Vector2 rayStart, Vector2 rayEnd, List<Segment> segments)
|
||||||
{
|
{
|
||||||
float closestDist = 0.0f;
|
float closestDist = 0.0f;
|
||||||
Vector2? closestIntersection = null;
|
Vector2? closestIntersection = null;
|
||||||
|
int segment = -1;
|
||||||
|
|
||||||
foreach (Segment s in segments)
|
for (int i=0;i<segments.Count;i++)
|
||||||
{
|
{
|
||||||
|
Segment s = segments[i];
|
||||||
Vector2? intersection = MathUtils.GetAxisAlignedLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, s.IsHorizontal);
|
Vector2? intersection = MathUtils.GetAxisAlignedLineIntersection(rayStart, rayEnd, s.Start.WorldPos, s.End.WorldPos, s.IsHorizontal);
|
||||||
|
|
||||||
if (intersection != null)
|
if (intersection != null)
|
||||||
@@ -420,16 +454,20 @@ namespace Barotrauma.Lights
|
|||||||
{
|
{
|
||||||
closestDist = dist;
|
closestDist = dist;
|
||||||
closestIntersection = intersection;
|
closestIntersection = intersection;
|
||||||
|
segment = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return closestIntersection == null ? rayEnd : (Vector2)closestIntersection;
|
Pair<int,Vector2> retVal = new Pair<int,Vector2>();
|
||||||
|
retVal.Second = closestIntersection == null ? rayEnd : (Vector2)closestIntersection;
|
||||||
|
retVal.First = segment;
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CalculateLightVertices(List<Vector2> rayCastHits)
|
private void CalculateLightVertices(List<Vector2> rayCastHits)
|
||||||
{
|
{
|
||||||
List<VertexPositionTexture> vertices = new List<VertexPositionTexture>();
|
List<VertexPositionColorTexture> vertices = new List<VertexPositionColorTexture>();
|
||||||
|
|
||||||
Vector2 drawPos = position;
|
Vector2 drawPos = position;
|
||||||
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
||||||
@@ -446,16 +484,19 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add a vertex for the center of the mesh
|
// Add a vertex for the center of the mesh
|
||||||
vertices.Add(new VertexPositionTexture(new Vector3(position.X, position.Y, 0),
|
vertices.Add(new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0),
|
||||||
new Vector2(0.5f, 0.5f) + uvOffset));
|
Color.White,new Vector2(0.5f, 0.5f) + uvOffset));
|
||||||
|
|
||||||
// Add all the other encounter points as vertices
|
// Add all the other encounter points as vertices
|
||||||
// storing their world position as UV coordinates
|
// storing their world position as UV coordinates
|
||||||
foreach (Vector2 vertex in rayCastHits)
|
for (int i = 0; i < rayCastHits.Count; i++)
|
||||||
{
|
{
|
||||||
|
Vector2 vertex = rayCastHits[i];
|
||||||
|
Vector2 prevVertex = rayCastHits[i > 0 ? i - 1 : rayCastHits.Count - 1];
|
||||||
|
Vector2 nextVertex = rayCastHits[i < rayCastHits.Count - 1 ? i + 1 : 0];
|
||||||
Vector2 rawDiff = vertex - drawPos;
|
Vector2 rawDiff = vertex - drawPos;
|
||||||
Vector2 diff = rawDiff;
|
Vector2 diff = rawDiff;
|
||||||
diff /= range*2.0f;
|
diff /= range * 2.0f;
|
||||||
if (overrideLightTexture != null)
|
if (overrideLightTexture != null)
|
||||||
{
|
{
|
||||||
Vector2 originDiff = diff;
|
Vector2 originDiff = diff;
|
||||||
@@ -467,22 +508,52 @@ namespace Barotrauma.Lights
|
|||||||
diff += uvOffset;
|
diff += uvOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices.Add(new VertexPositionTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0),
|
Vector2 nDiff1 = vertex - nextVertex;
|
||||||
new Vector2(0.5f, 0.5f) + diff));
|
float tx = nDiff1.X; nDiff1.X = -nDiff1.Y; nDiff1.Y = tx;
|
||||||
|
nDiff1 /= Math.Max(Math.Abs(nDiff1.X), Math.Abs(nDiff1.Y));
|
||||||
|
Vector2 nDiff2 = prevVertex - vertex;
|
||||||
|
tx = nDiff2.X; nDiff2.X = -nDiff2.Y; nDiff2.Y = tx;
|
||||||
|
nDiff2 /= Math.Max(Math.Abs(nDiff2.X),Math.Abs(nDiff2.Y));
|
||||||
|
Vector2 nDiff = nDiff1 + nDiff2;
|
||||||
|
nDiff /= Math.Max(Math.Abs(nDiff.X), Math.Abs(nDiff.Y));
|
||||||
|
nDiff *= 50.0f;
|
||||||
|
if (Vector2.DistanceSquared(nDiff, rawDiff) > Vector2.DistanceSquared(-nDiff, rawDiff)) nDiff = -nDiff;
|
||||||
|
VertexPositionColorTexture fadeVert = new VertexPositionColorTexture(new Vector3(position.X + rawDiff.X + nDiff.X, position.Y + rawDiff.Y + nDiff.Y, 0),
|
||||||
|
Color.White * 0.0f, new Vector2(0.5f, 0.5f) + diff);
|
||||||
|
|
||||||
|
vertices.Add(new VertexPositionColorTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0),
|
||||||
|
Color.White, new Vector2(0.5f, 0.5f) + diff));
|
||||||
|
vertices.Add(fadeVert);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the indices to form triangles
|
// Compute the indices to form triangles
|
||||||
List<short> indices = new List<short>();
|
List<short> indices = new List<short>();
|
||||||
for (int i = 0; i < rayCastHits.Count - 1; i++)
|
for (int i = 0; i < rayCastHits.Count-1; i++)
|
||||||
{
|
{
|
||||||
indices.Add(0);
|
indices.Add(0);
|
||||||
indices.Add((short)((i + 2) % vertices.Count));
|
indices.Add((short)((i*2 + 3) % vertices.Count));
|
||||||
indices.Add((short)((i + 1) % vertices.Count));
|
indices.Add((short)((i*2 + 1) % vertices.Count));
|
||||||
|
|
||||||
|
indices.Add((short)((i*2 + 1) % vertices.Count));
|
||||||
|
indices.Add((short)((i*2 + 3) % vertices.Count));
|
||||||
|
indices.Add((short)((i*2 + 4) % vertices.Count));
|
||||||
|
|
||||||
|
indices.Add((short)((i*2 + 2) % vertices.Count));
|
||||||
|
indices.Add((short)((i*2 + 1) % vertices.Count));
|
||||||
|
indices.Add((short)((i*2 + 4) % vertices.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
indices.Add(0);
|
indices.Add(0);
|
||||||
indices.Add((short)(1));
|
indices.Add((short)(1));
|
||||||
indices.Add((short)(vertices.Count - 1));
|
indices.Add((short)(vertices.Count - 2));
|
||||||
|
|
||||||
|
indices.Add((short)(1));
|
||||||
|
indices.Add((short)(vertices.Count-1));
|
||||||
|
indices.Add((short)(vertices.Count-2));
|
||||||
|
|
||||||
|
indices.Add((short)(1));
|
||||||
|
indices.Add((short)(2));
|
||||||
|
indices.Add((short)(vertices.Count-1));
|
||||||
|
|
||||||
vertexCount = vertices.Count;
|
vertexCount = vertices.Count;
|
||||||
indexCount = indices.Count;
|
indexCount = indices.Count;
|
||||||
@@ -491,19 +562,19 @@ namespace Barotrauma.Lights
|
|||||||
//now we just create a buffer for 64 verts and make it larger if needed
|
//now we just create a buffer for 64 verts and make it larger if needed
|
||||||
if (lightVolumeBuffer == null)
|
if (lightVolumeBuffer == null)
|
||||||
{
|
{
|
||||||
lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None);
|
lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, Math.Max(64, (int)(vertexCount*1.5)), BufferUsage.None);
|
||||||
lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None);
|
lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), Math.Max(64*3, (int)(indexCount * 1.5)), BufferUsage.None);
|
||||||
}
|
}
|
||||||
else if (vertexCount > lightVolumeBuffer.VertexCount)
|
else if (vertexCount > lightVolumeBuffer.VertexCount || indexCount > lightVolumeIndexBuffer.IndexCount)
|
||||||
{
|
{
|
||||||
lightVolumeBuffer.Dispose();
|
lightVolumeBuffer.Dispose();
|
||||||
lightVolumeIndexBuffer.Dispose();
|
lightVolumeIndexBuffer.Dispose();
|
||||||
|
|
||||||
lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None);
|
lightVolumeBuffer = new DynamicVertexBuffer(GameMain.Instance.GraphicsDevice, VertexPositionColorTexture.VertexDeclaration, (int)(vertexCount*1.5), BufferUsage.None);
|
||||||
lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None);
|
lightVolumeIndexBuffer = new DynamicIndexBuffer(GameMain.Instance.GraphicsDevice, typeof(short), (int)(indexCount * 1.5), BufferUsage.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
lightVolumeBuffer.SetData<VertexPositionTexture>(vertices.ToArray());
|
lightVolumeBuffer.SetData<VertexPositionColorTexture>(vertices.ToArray());
|
||||||
lightVolumeIndexBuffer.SetData<short>(indices.ToArray());
|
lightVolumeIndexBuffer.SetData<short>(indices.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,7 +633,7 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lightEffect.Texture = LightTexture;
|
lightEffect.Texture = texture??LightTexture;
|
||||||
}
|
}
|
||||||
lightEffect.CurrentTechnique.Passes[0].Apply();
|
lightEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
|
|
||||||
@@ -571,6 +642,7 @@ namespace Barotrauma.Lights
|
|||||||
|
|
||||||
GameMain.Instance.GraphicsDevice.DrawIndexedPrimitives
|
GameMain.Instance.GraphicsDevice.DrawIndexedPrimitives
|
||||||
(
|
(
|
||||||
|
//PrimitiveType.LineList, 0, 0, indexCount / 2
|
||||||
PrimitiveType.TriangleList, 0, 0, indexCount / 3
|
PrimitiveType.TriangleList, 0, 0, indexCount / 3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ namespace Barotrauma.Particles
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Hull newHull = Hull.FindHull(position);
|
Hull newHull = Hull.FindHull(position,currentHull);
|
||||||
if (newHull != currentHull)
|
if (newHull != currentHull)
|
||||||
{
|
{
|
||||||
currentHull = newHull;
|
currentHull = newHull;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
using Microsoft.Xna.Framework.Content;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
@@ -14,7 +14,7 @@ namespace Barotrauma
|
|||||||
readonly RenderTarget2D renderTargetBackground;
|
readonly RenderTarget2D renderTargetBackground;
|
||||||
readonly RenderTarget2D renderTarget;
|
readonly RenderTarget2D renderTarget;
|
||||||
readonly RenderTarget2D renderTargetWater;
|
readonly RenderTarget2D renderTargetWater;
|
||||||
readonly RenderTarget2D renderTargetAir;
|
readonly RenderTarget2D renderTargetFinal;
|
||||||
|
|
||||||
private Effect damageEffect;
|
private Effect damageEffect;
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ namespace Barotrauma
|
|||||||
cam.Translate(new Vector2(-10.0f, 50.0f));
|
cam.Translate(new Vector2(-10.0f, 50.0f));
|
||||||
|
|
||||||
renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
renderTargetBackground = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||||
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
renderTarget = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
|
||||||
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
renderTargetWater = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
||||||
renderTargetAir = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight);
|
renderTargetFinal = new RenderTarget2D(graphics, GameMain.GraphicsWidth, GameMain.GraphicsHeight, false, SurfaceFormat.Color, DepthFormat.None);
|
||||||
|
|
||||||
|
|
||||||
#if LINUX
|
#if LINUX
|
||||||
@@ -97,7 +97,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (Submarine sub in Submarine.Loaded)
|
foreach (Submarine sub in Submarine.Loaded)
|
||||||
{
|
{
|
||||||
sub.UpdateTransform();
|
sub.UpdateTransform();
|
||||||
@@ -113,64 +112,55 @@ namespace Barotrauma
|
|||||||
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition);
|
GameMain.LightManager.UpdateObstructVision(graphics, spriteBatch, cam, Character.Controlled.CursorWorldPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
//1. draw the background, characters and the parts of the submarine that are behind them
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
graphics.SetRenderTarget(renderTargetBackground);
|
graphics.SetRenderTarget(renderTargetBackground);
|
||||||
|
|
||||||
if (Level.Loaded == null)
|
if (Level.Loaded == null)
|
||||||
{
|
{
|
||||||
graphics.Clear(new Color(11, 18, 26, 255));
|
graphics.Clear(new Color(11, 18, 26, 255));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//graphics.Clear(new Color(255, 255, 255, 255));
|
||||||
Level.Loaded.DrawBack(graphics, spriteBatch, cam);
|
Level.Loaded.DrawBack(graphics, spriteBatch, cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw structures that are in water and not part of any sub (e.g. ruins)
|
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform);
|
|
||||||
Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine == null);
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
//draw alpha blended particles that are in water and behind subs
|
//draw alpha blended particles that are in water and behind subs
|
||||||
#if LINUX
|
#if LINUX
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.DepthRead, null, null, cam.Transform);
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
#else
|
#else
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.DepthRead, null, null, cam.Transform);
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
#endif
|
#endif
|
||||||
GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.AlphaBlend);
|
GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.AlphaBlend);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
//draw additive particles that are in water and behind subs
|
//draw additive particles that are in water and behind subs
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform);
|
//TODO: make these draw properly somehow, since they're not rendered into the lightmap anymore
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.Additive);
|
GameMain.ParticleManager.Draw(spriteBatch, true, false, Particles.ParticleBlendState.Additive);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
//draw submarine structures that are behind water
|
Submarine.DrawBack(spriteBatch, false, s => s is Structure && ((Structure)s).ResizeVertical && ((Structure)s).ResizeHorizontal);
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform);
|
foreach (Structure s in Structure.WallList)
|
||||||
Submarine.DrawBack(spriteBatch, false, s => s is Structure && s.Submarine != null);
|
{
|
||||||
|
if ((s.ResizeVertical != s.ResizeHorizontal) && s.CastShadow)
|
||||||
|
{
|
||||||
|
GUI.DrawRectangle(spriteBatch, new Vector2(s.DrawPosition.X-s.WorldRect.Width/2,-s.DrawPosition.Y-s.WorldRect.Height/2), new Vector2(s.WorldRect.Width, s.WorldRect.Height), Color.Black, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
graphics.SetRenderTarget(renderTarget);
|
graphics.SetRenderTarget(renderTarget);
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, null);
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred,
|
|
||||||
BlendState.Opaque);
|
|
||||||
spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
|
||||||
BlendState.AlphaBlend,
|
|
||||||
null, null, null, null,
|
|
||||||
cam.Transform);
|
|
||||||
|
|
||||||
Submarine.DrawBack(spriteBatch, false, s => !(s is Structure));
|
Submarine.DrawBack(spriteBatch, false, s => !(s is Structure));
|
||||||
|
Submarine.DrawBack(spriteBatch, false, s => s is Structure && !(((Structure)s).ResizeVertical && ((Structure)s).ResizeHorizontal));
|
||||||
foreach (Character c in Character.CharacterList) c.Draw(spriteBatch);
|
foreach (Character c in Character.CharacterList) c.Draw(spriteBatch);
|
||||||
|
spriteBatch.End();
|
||||||
|
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, null, null, cam.Transform);
|
||||||
|
|
||||||
|
Submarine.DrawFront(spriteBatch, false, null);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
//draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater
|
//draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater
|
||||||
graphics.SetRenderTarget(renderTargetWater);
|
graphics.SetRenderTarget(renderTargetWater);
|
||||||
|
|
||||||
@@ -187,18 +177,7 @@ namespace Barotrauma
|
|||||||
GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.AlphaBlend);
|
GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.AlphaBlend);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
//draw additive particles that are inside a sub
|
graphics.SetRenderTarget(renderTarget);
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform);
|
|
||||||
GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.Additive);
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
//draw the rendertarget and particles that are only supposed to be drawn in air into renderTargetAir
|
|
||||||
|
|
||||||
graphics.SetRenderTarget(renderTargetAir);
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque);
|
|
||||||
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
//draw alpha blended particles that are not in water
|
//draw alpha blended particles that are not in water
|
||||||
#if LINUX
|
#if LINUX
|
||||||
@@ -210,39 +189,11 @@ namespace Barotrauma
|
|||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
//draw additive particles that are not in water
|
//draw additive particles that are not in water
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.DepthRead, null, null, cam.Transform);
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.None, null, null, cam.Transform);
|
||||||
GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive);
|
GameMain.ParticleManager.Draw(spriteBatch, false, null, Particles.ParticleBlendState.Additive);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
if (Character.Controlled != null && GameMain.LightManager.LosEnabled)
|
graphics.SetRenderTarget(renderTargetFinal);
|
||||||
{
|
|
||||||
graphics.SetRenderTarget(renderTarget);
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Deferred,
|
|
||||||
BlendState.Opaque, null, null, null, lightBlur.Effect);
|
|
||||||
|
|
||||||
spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
|
||||||
BlendState.AlphaBlend, SamplerState.LinearWrap,
|
|
||||||
null, null, null,
|
|
||||||
cam.Transform);
|
|
||||||
|
|
||||||
Submarine.DrawDamageable(spriteBatch, null, false);
|
|
||||||
Submarine.DrawFront(spriteBatch, false, s => s is Structure);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
graphics.SetRenderTarget(null);
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
//2. pass the renderTarget to the water shader to do the water effect
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Hull.renderer.RenderBack(spriteBatch, renderTargetWater);
|
Hull.renderer.RenderBack(spriteBatch, renderTargetWater);
|
||||||
|
|
||||||
Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length);
|
Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length);
|
||||||
@@ -252,58 +203,46 @@ namespace Barotrauma
|
|||||||
hull.Render(graphics, cam);
|
hull.Render(graphics, cam);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
|
Hull.renderer.Render(graphics, cam, renderTarget, Cam.ShaderTransform);
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
//3. draw the sections of the map that are on top of the water
|
|
||||||
//----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
|
||||||
BlendState.AlphaBlend, SamplerState.LinearWrap,
|
|
||||||
null, null, null,
|
|
||||||
cam.Transform);
|
|
||||||
|
|
||||||
Submarine.DrawFront(spriteBatch, false, null);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
|
||||||
|
|
||||||
spriteBatch.Begin(SpriteSortMode.Immediate,
|
spriteBatch.Begin(SpriteSortMode.Immediate,
|
||||||
BlendState.NonPremultiplied, SamplerState.LinearWrap,
|
BlendState.NonPremultiplied, SamplerState.LinearWrap,
|
||||||
null, null,
|
null, null,
|
||||||
damageEffect,
|
damageEffect,
|
||||||
cam.Transform);
|
cam.Transform);
|
||||||
|
|
||||||
Submarine.DrawDamageable(spriteBatch, damageEffect, false);
|
Submarine.DrawDamageable(spriteBatch, damageEffect, false);
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
GameMain.LightManager.DrawLightMap(spriteBatch, lightBlur.Effect);
|
//draw additive particles that are inside a sub
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, null, DepthStencilState.Default, null, null, cam.Transform);
|
||||||
spriteBatch.Begin(SpriteSortMode.BackToFront,
|
GameMain.ParticleManager.Draw(spriteBatch, true, true, Particles.ParticleBlendState.Additive);
|
||||||
BlendState.AlphaBlend, SamplerState.LinearWrap,
|
|
||||||
null, null, null,
|
|
||||||
cam.Transform);
|
|
||||||
|
|
||||||
if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch);
|
|
||||||
|
|
||||||
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch, cam);
|
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
if (Character.Controlled != null && GameMain.LightManager.LosEnabled)
|
if (GameMain.LightManager.LightingEnabled)
|
||||||
{
|
{
|
||||||
GameMain.LightManager.DrawLOS(spriteBatch, lightBlur.Effect, false);
|
spriteBatch.Begin(SpriteSortMode.Deferred, Lights.CustomBlendStates.Multiplicative, null, DepthStencilState.None, null, null, null);
|
||||||
|
spriteBatch.Draw(GameMain.LightManager.lightMap, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
||||||
spriteBatch.Begin(SpriteSortMode.Immediate,
|
|
||||||
BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone, null);
|
|
||||||
|
|
||||||
float r = Math.Min(CharacterHUD.damageOverlayTimer * 0.5f, 0.5f);
|
|
||||||
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight),
|
|
||||||
Color.Lerp(GameMain.LightManager.AmbientLight * 0.5f, Color.Red, r));
|
|
||||||
|
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, null, null, cam.Transform);
|
||||||
|
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch, cam);
|
||||||
|
|
||||||
|
if (Level.Loaded != null) Level.Loaded.DrawFront(spriteBatch);
|
||||||
|
spriteBatch.End();
|
||||||
|
|
||||||
|
graphics.SetRenderTarget(null);
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.None, null, null, null);
|
||||||
|
if (GameMain.LightManager.LosEnabled && Character.Controlled!=null)
|
||||||
|
{
|
||||||
|
spriteBatch.Draw(renderTargetBackground, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), new Color(10, 24, 30, 255));
|
||||||
|
spriteBatch.End();
|
||||||
|
Hull.renderer.waterEffect.CurrentTechnique = Hull.renderer.waterEffect.Techniques["LosShader"];
|
||||||
|
Hull.renderer.waterEffect.Parameters["xLosTexture"].SetValue(GameMain.LightManager.losTexture);
|
||||||
|
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, null, Hull.renderer.waterEffect, null);
|
||||||
|
}
|
||||||
|
spriteBatch.Draw(renderTargetFinal, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White);
|
||||||
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -186,18 +186,23 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color)
|
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Color color)
|
||||||
{
|
{
|
||||||
DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color);
|
DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color, Vector2.One);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color)
|
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color)
|
||||||
|
{
|
||||||
|
DrawTiled(spriteBatch, pos, targetSize, startOffset, sourceRect, color, Vector2.One);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DrawTiled(SpriteBatch spriteBatch, Vector2 pos, Vector2 targetSize, Vector2 startOffset, Rectangle sourceRect, Color color, Vector2 scale)
|
||||||
{
|
{
|
||||||
//pos.X = (int)pos.X;
|
//pos.X = (int)pos.X;
|
||||||
//pos.Y = (int)pos.Y;
|
//pos.Y = (int)pos.Y;
|
||||||
|
|
||||||
//how many times the texture needs to be drawn on the x-axis
|
//how many times the texture needs to be drawn on the x-axis
|
||||||
int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / sourceRect.Width);
|
int xTiles = (int)Math.Ceiling((targetSize.X + startOffset.X) / (sourceRect.Width*scale.X));
|
||||||
//how many times the texture needs to be drawn on the y-axis
|
//how many times the texture needs to be drawn on the y-axis
|
||||||
int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / sourceRect.Height);
|
int yTiles = (int)Math.Ceiling((targetSize.Y + startOffset.Y) / (sourceRect.Height*scale.Y));
|
||||||
|
|
||||||
Vector2 position = pos - startOffset;
|
Vector2 position = pos - startOffset;
|
||||||
Rectangle drawRect = sourceRect;
|
Rectangle drawRect = sourceRect;
|
||||||
@@ -211,11 +216,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (x == xTiles - 1)
|
if (x == xTiles - 1)
|
||||||
{
|
{
|
||||||
drawRect.Width -= (int)((position.X + sourceRect.Width) - (pos.X + targetSize.X));
|
drawRect.Width -= (int)((position.X + sourceRect.Width*scale.X) - (pos.X + targetSize.X));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawRect.Width = sourceRect.Width;
|
drawRect.Width = (int)(sourceRect.Width*scale.X);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position.X < pos.X)
|
if (position.X < pos.X)
|
||||||
@@ -234,11 +239,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (y == yTiles - 1)
|
if (y == yTiles - 1)
|
||||||
{
|
{
|
||||||
drawRect.Height -= (int)((position.Y + sourceRect.Height) - (pos.Y + targetSize.Y));
|
drawRect.Height -= (int)((position.Y + sourceRect.Height*scale.Y) - (pos.Y + targetSize.Y));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawRect.Height = sourceRect.Height;
|
drawRect.Height = (int)(sourceRect.Height*scale.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position.Y < pos.Y)
|
if (position.Y < pos.Y)
|
||||||
@@ -252,10 +257,10 @@ namespace Barotrauma
|
|||||||
spriteBatch.Draw(texture, position,
|
spriteBatch.Draw(texture, position,
|
||||||
drawRect, color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
drawRect, color, rotation, Vector2.Zero, 1.0f, effects, depth);
|
||||||
|
|
||||||
position.Y += sourceRect.Height;
|
position.Y += sourceRect.Height*scale.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
position.X += sourceRect.Width;
|
position.X += sourceRect.Width*scale.X;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Color = Microsoft.Xna.Framework.Color;
|
using Color = Microsoft.Xna.Framework.Color;
|
||||||
|
|||||||
@@ -48,8 +48,9 @@ float4 main(float4 position : SV_Position, float4 color : COLOR0, float2 texCoor
|
|||||||
float4 main2(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
float4 main2(float4 position : SV_Position, float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
|
||||||
{
|
{
|
||||||
float4 losColor = tex2D(LosSampler, texCoord);
|
float4 losColor = tex2D(LosSampler, texCoord);
|
||||||
|
float4 sample = tex2D(TextureSampler, texCoord);
|
||||||
|
|
||||||
float4 outColor = float4(losColor.x, losColor.y, losColor.z, color.w);
|
float4 outColor = float4(sample.x, sample.y, sample.z, losColor.x);
|
||||||
|
|
||||||
return outColor;
|
return outColor;
|
||||||
}
|
}
|
||||||
|
|||||||
Regular → Executable
BIN
Binary file not shown.
@@ -13,13 +13,15 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
public string Text;
|
public string Text;
|
||||||
public Color Color;
|
public Color Color;
|
||||||
|
public bool IsCommand;
|
||||||
|
|
||||||
public readonly string Time;
|
public readonly string Time;
|
||||||
|
|
||||||
public ColoredText(string text, Color color)
|
public ColoredText(string text, Color color, bool isCommand)
|
||||||
{
|
{
|
||||||
this.Text = text;
|
this.Text = text;
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
|
this.IsCommand = isCommand;
|
||||||
|
|
||||||
Time = DateTime.Now.ToString();
|
Time = DateTime.Now.ToString();
|
||||||
}
|
}
|
||||||
@@ -1028,9 +1030,14 @@ namespace Barotrauma
|
|||||||
|
|
||||||
direction = MathHelper.Clamp(direction, -1, 1);
|
direction = MathHelper.Clamp(direction, -1, 1);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
selectedIndex += direction;
|
selectedIndex += direction;
|
||||||
if (selectedIndex < 0) selectedIndex = Messages.Count - 1;
|
if (selectedIndex < 0) selectedIndex = Messages.Count - 1;
|
||||||
selectedIndex = selectedIndex % Messages.Count;
|
selectedIndex = selectedIndex % Messages.Count;
|
||||||
|
if (++i >= Messages.Count) break;
|
||||||
|
} while (!Messages[selectedIndex].IsCommand);
|
||||||
|
|
||||||
return Messages[selectedIndex].Text;
|
return Messages[selectedIndex].Text;
|
||||||
}
|
}
|
||||||
@@ -1042,7 +1049,7 @@ namespace Barotrauma
|
|||||||
#if CLIENT
|
#if CLIENT
|
||||||
activeQuestionText = null;
|
activeQuestionText = null;
|
||||||
#endif
|
#endif
|
||||||
NewMessage(command, Color.White);
|
NewMessage(command, Color.White, true);
|
||||||
//reset the variable before invoking the delegate because the method may need to activate another question
|
//reset the variable before invoking the delegate because the method may need to activate another question
|
||||||
var temp = activeQuestionCallback;
|
var temp = activeQuestionCallback;
|
||||||
activeQuestionCallback = null;
|
activeQuestionCallback = null;
|
||||||
@@ -1056,7 +1063,7 @@ namespace Barotrauma
|
|||||||
|
|
||||||
if (!splitCommand[0].ToLowerInvariant().Equals("admin"))
|
if (!splitCommand[0].ToLowerInvariant().Equals("admin"))
|
||||||
{
|
{
|
||||||
NewMessage(command, Color.White);
|
NewMessage(command, Color.White, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !DEBUG && CLIENT
|
#if !DEBUG && CLIENT
|
||||||
@@ -1131,12 +1138,12 @@ namespace Barotrauma
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NewMessage(string msg, Color color)
|
public static void NewMessage(string msg, Color color, bool isCommand = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty((msg))) return;
|
if (string.IsNullOrEmpty((msg))) return;
|
||||||
|
|
||||||
#if SERVER
|
#if SERVER
|
||||||
Messages.Add(new ColoredText(msg, color));
|
Messages.Add(new ColoredText(msg, color, isCommand));
|
||||||
|
|
||||||
//TODO: REMOVE
|
//TODO: REMOVE
|
||||||
Console.ForegroundColor = XnaToConsoleColor.Convert(color);
|
Console.ForegroundColor = XnaToConsoleColor.Convert(color);
|
||||||
@@ -1151,7 +1158,7 @@ namespace Barotrauma
|
|||||||
#elif CLIENT
|
#elif CLIENT
|
||||||
lock (queuedMessages)
|
lock (queuedMessages)
|
||||||
{
|
{
|
||||||
queuedMessages.Enqueue(new ColoredText(msg, color));
|
queuedMessages.Enqueue(new ColoredText(msg, color, isCommand));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1204,7 +1204,7 @@ namespace Barotrauma
|
|||||||
Color color = Color.Red;
|
Color color = Color.Red;
|
||||||
if (ic.HasRequiredSkills(character) && ic.HasRequiredItems(character, false)) color = Color.Orange;
|
if (ic.HasRequiredSkills(character) && ic.HasRequiredItems(character, false)) color = Color.Orange;
|
||||||
|
|
||||||
texts.Add(new ColoredText(ic.Msg, color));
|
texts.Add(new ColoredText(ic.Msg, color, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
return texts;
|
return texts;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Created by SharpDevelop.
|
* Created by SharpDevelop.
|
||||||
* User: Burhan
|
* User: Burhan
|
||||||
* Date: 17/06/2014
|
* Date: 17/06/2014
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Created by SharpDevelop.
|
* Created by SharpDevelop.
|
||||||
* User: Burhan
|
* User: Burhan
|
||||||
* Date: 17/06/2014
|
* Date: 17/06/2014
|
||||||
|
|||||||
@@ -89,11 +89,11 @@ namespace Barotrauma
|
|||||||
get { return false; }
|
get { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool ResizeHorizontal
|
public bool ResizeHorizontal
|
||||||
{
|
{
|
||||||
get { return prefab != null && prefab.ResizeHorizontal; }
|
get { return prefab != null && prefab.ResizeHorizontal; }
|
||||||
}
|
}
|
||||||
protected bool ResizeVertical
|
public bool ResizeVertical
|
||||||
{
|
{
|
||||||
get { return prefab != null && prefab.ResizeVertical; }
|
get { return prefab != null && prefab.ResizeVertical; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user