- 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:
Regalis
2016-05-13 18:00:31 +03:00
parent aaa84ef4ac
commit d884f84346
13 changed files with 239 additions and 83 deletions
+80 -17
View File
@@ -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);
}
}
}