- disabled FOW blurring (made it possible to see through corners) and re-enabled penumbra
- fixed structures being assigned the misc category by default - turrets don't require a barrel sprite - OnImpact statuseffect is applied when a projectile hits something - WIP depth charges
This commit is contained in:
@@ -13,7 +13,7 @@ namespace Barotrauma.Lights
|
||||
|
||||
public Vector2 LightPos;
|
||||
|
||||
public int ShadowVertexCount;//, PenumbraVertexCount;
|
||||
public int ShadowVertexCount, PenumbraVertexCount;
|
||||
|
||||
public CachedShadow(VertexPositionColor[] shadowVertices, Vector2 lightPos, int shadowVertexCount, int penumbraVertexCount)
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace Barotrauma.Lights
|
||||
ShadowBuffer.SetData(shadowVertices, 0, shadowVertices.Length);
|
||||
|
||||
ShadowVertexCount = shadowVertexCount;
|
||||
//PenumbraVertexCount = penumbraVertexCount;
|
||||
PenumbraVertexCount = penumbraVertexCount;
|
||||
|
||||
LightPos = lightPos;
|
||||
}
|
||||
@@ -46,7 +46,8 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
public static List<ConvexHull> list = new List<ConvexHull>();
|
||||
static BasicEffect shadowEffect;
|
||||
|
||||
static BasicEffect penumbraEffect;
|
||||
|
||||
private Dictionary<LightSource, CachedShadow> cachedShadows;
|
||||
|
||||
private Vector2[] vertices;
|
||||
@@ -56,6 +57,7 @@ namespace Barotrauma.Lights
|
||||
private bool[] backFacing;
|
||||
|
||||
private VertexPositionColor[] shadowVertices;
|
||||
private VertexPositionTexture[] penumbraVertices;
|
||||
|
||||
int shadowVertexCount;
|
||||
|
||||
@@ -87,21 +89,21 @@ namespace Barotrauma.Lights
|
||||
shadowEffect = new BasicEffect(GameMain.CurrGraphicsDevice);
|
||||
shadowEffect.VertexColorEnabled = true;
|
||||
}
|
||||
//if (penumbraEffect == null)
|
||||
//{
|
||||
// penumbraEffect = new BasicEffect(GameMain.CurrGraphicsDevice);
|
||||
// penumbraEffect.TextureEnabled = true;
|
||||
// //shadowEffect.VertexColorEnabled = true;
|
||||
// penumbraEffect.LightingEnabled = false;
|
||||
// penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
||||
//}
|
||||
if (penumbraEffect == null)
|
||||
{
|
||||
penumbraEffect = new BasicEffect(GameMain.CurrGraphicsDevice);
|
||||
penumbraEffect.TextureEnabled = true;
|
||||
//shadowEffect.VertexColorEnabled = true;
|
||||
penumbraEffect.LightingEnabled = false;
|
||||
penumbraEffect.Texture = TextureLoader.FromFile("Content/Lights/penumbra.png");
|
||||
}
|
||||
|
||||
parentEntity = parent;
|
||||
|
||||
cachedShadows = new Dictionary<LightSource, CachedShadow>();
|
||||
|
||||
shadowVertices = new VertexPositionColor[6 * 2];
|
||||
//penumbraVertices = new VertexPositionTexture[6];
|
||||
penumbraVertices = new VertexPositionTexture[6];
|
||||
|
||||
//vertices = points;
|
||||
primitiveCount = points.Length;
|
||||
@@ -151,7 +153,7 @@ namespace Barotrauma.Lights
|
||||
vertices = points;
|
||||
losVertices = points;
|
||||
|
||||
int margin = 7;
|
||||
int margin = 0;
|
||||
|
||||
if (Math.Abs(points[0].X - points[2].X) < Math.Abs(points[0].Y - points[1].Y))
|
||||
{
|
||||
@@ -283,6 +285,54 @@ namespace Barotrauma.Lights
|
||||
svCount += 2;
|
||||
currentIndex = (currentIndex + 1) % primitiveCount;
|
||||
}
|
||||
|
||||
if (los)
|
||||
{
|
||||
CalculatePenumbraVertices(startingIndex, endingIndex, lightSourcePos, los);
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculatePenumbraVertices(int startingIndex, int endingIndex, Vector2 lightSourcePos, bool los)
|
||||
{
|
||||
for (int n = 0; n < 4; n += 3)
|
||||
{
|
||||
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f);
|
||||
|
||||
penumbraVertices[n] = new VertexPositionTexture();
|
||||
penumbraVertices[n].Position = penumbraStart;
|
||||
penumbraVertices[n].TextureCoordinate = new Vector2(0.0f, 1.0f);
|
||||
//penumbraVertices[0].te = fow ? Color.Black : Color.Transparent;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
penumbraVertices[n + i + 1] = new VertexPositionTexture();
|
||||
Vector3 vertexDir = penumbraStart - new Vector3(lightSourcePos, 0);
|
||||
vertexDir.Normalize();
|
||||
|
||||
Vector3 normal = (i == 0) ? new Vector3(-vertexDir.Y, vertexDir.X, 0.0f) : new Vector3(vertexDir.Y, -vertexDir.X, 0.0f) * 0.05f;
|
||||
if (n > 0) normal = -normal;
|
||||
|
||||
vertexDir = penumbraStart - (new Vector3(lightSourcePos, 0) - normal * 20.0f);
|
||||
vertexDir.Normalize();
|
||||
penumbraVertices[n + i + 1].Position = new Vector3(lightSourcePos, 0) + vertexDir * 9000;
|
||||
|
||||
if (los)
|
||||
{
|
||||
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(0.05f, 0.0f) : new Vector2(1.0f, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
penumbraVertices[n + i + 1].TextureCoordinate = (i == 0) ? new Vector2(1.0f, 0.0f) : Vector2.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 0)
|
||||
{
|
||||
var temp = penumbraVertices[4];
|
||||
penumbraVertices[4] = penumbraVertices[5];
|
||||
penumbraVertices[5] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, LightSource light, Matrix transform, bool los = true)
|
||||
@@ -345,24 +395,37 @@ namespace Barotrauma.Lights
|
||||
if (los)
|
||||
{
|
||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2, VertexPositionColor.VertexDeclaration);
|
||||
}
|
||||
else
|
||||
{
|
||||
shadowEffect.CurrentTechnique.Passes[0].Apply();
|
||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, shadowVertexCount * 2 - 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (los)
|
||||
{
|
||||
penumbraEffect.World = shadowEffect.World;
|
||||
penumbraEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
#if WINDOWS
|
||||
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, penumbraVertices, 0, 2, VertexPositionTexture.VertexDeclaration);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
|
||||
|
||||
ClearCachedShadows();
|
||||
|
||||
list.Remove(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,47 +69,6 @@ namespace Barotrauma.Lights
|
||||
lights.Remove(light);
|
||||
}
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Effect effect)
|
||||
{
|
||||
if (!LosEnabled || ViewTarget==null) return;
|
||||
|
||||
//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;
|
||||
|
||||
//graphics.SetRenderTarget(losTexture);
|
||||
//graphics.Clear(Color.Transparent);
|
||||
|
||||
//foreach (ConvexHull convexHull in ConvexHull.list)
|
||||
//{
|
||||
// if (!convexHull.Intersects(camView)) continue;
|
||||
// //if (!camView.Intersects(convexHull.BoundingBox)) continue;
|
||||
|
||||
// convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
||||
//}
|
||||
|
||||
//graphics.SetRenderTarget(null);
|
||||
|
||||
//if (!ObstructVision) return;
|
||||
|
||||
//spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative);
|
||||
//spriteBatch.Draw(losTexture, Vector2.Zero);
|
||||
//spriteBatch.End();
|
||||
|
||||
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, ObstructVision ? CustomBlendStates.Multiplicative : BlendState.AlphaBlend, null, null, null, effect);
|
||||
//effect.CurrentTechnique.Passes[0].Apply();
|
||||
spriteBatch.Draw(losTexture, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
ObstructVision = false;
|
||||
|
||||
}
|
||||
|
||||
public void OnMapLoaded()
|
||||
{
|
||||
foreach (LightSource light in lights)
|
||||
@@ -191,11 +150,11 @@ namespace Barotrauma.Lights
|
||||
|
||||
graphics.SetRenderTarget(losTexture);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cam.Transform);
|
||||
|
||||
if (ObstructVision)
|
||||
{
|
||||
graphics.Clear(Color.Black);
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, cam.Transform);
|
||||
//graphics.Clear(Color.Black);
|
||||
|
||||
Vector2 diff = lookAtPosition - ViewTarget.WorldPosition;
|
||||
diff.Y = -diff.Y;
|
||||
@@ -205,14 +164,16 @@ namespace Barotrauma.Lights
|
||||
|
||||
spriteBatch.Draw(visionCircle, new Vector2(ViewTarget.WorldPosition.X, -ViewTarget.WorldPosition.Y), null, Color.White, rotation,
|
||||
new Vector2(LightSource.LightTexture.Width*0.2f, LightSource.LightTexture.Height/2), scale, SpriteEffects.None, 0.0f);
|
||||
spriteBatch.End();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics.Clear(Color.Transparent);
|
||||
graphics.Clear(Color.White);
|
||||
}
|
||||
|
||||
spriteBatch.End();
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
if (LosEnabled && ViewTarget != null)
|
||||
@@ -232,7 +193,6 @@ namespace Barotrauma.Lights
|
||||
convexHull.DrawShadows(graphics, cam, pos, shadowTransform);
|
||||
}
|
||||
}
|
||||
|
||||
graphics.SetRenderTarget(null);
|
||||
}
|
||||
|
||||
@@ -253,7 +213,16 @@ namespace Barotrauma.Lights
|
||||
spriteBatch.End();
|
||||
}
|
||||
|
||||
public void DrawLOS(GraphicsDevice graphics, SpriteBatch spriteBatch, Camera cam, Effect effect)
|
||||
{
|
||||
if (!LosEnabled || ViewTarget == null) return;
|
||||
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.Multiplicative, null, null, null);
|
||||
spriteBatch.Draw(losTexture, Vector2.Zero, Color.White);
|
||||
spriteBatch.End();
|
||||
|
||||
ObstructVision = false;
|
||||
}
|
||||
|
||||
public void ClearLights()
|
||||
{
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Barotrauma
|
||||
|
||||
MapEntityCategory category;
|
||||
|
||||
if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Misc"), true, out category))
|
||||
if (!Enum.TryParse(ToolBox.GetAttributeString(element, "category", "Structure"), true, out category))
|
||||
{
|
||||
category = MapEntityCategory.Structure;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user