Lighting fixes:
- Re-enabled lightsprites (glowing lamp sprites on lamps). - Limb sprites use lightsprites instead of overriding the texture (positioned correctly now). - Fixed lights that don't cast shadows not being rendered.
This commit is contained in:
@@ -81,6 +81,7 @@ namespace Barotrauma
|
||||
if (LightSource != null)
|
||||
{
|
||||
LightSource.Position = body.DrawPosition;
|
||||
LightSource.LightSpriteEffect = (dir == Direction.Right) ? SpriteEffects.None : SpriteEffects.FlipVertically;
|
||||
}
|
||||
|
||||
foreach (WearableSprite wearable in wearingItems)
|
||||
|
||||
@@ -20,8 +20,16 @@ namespace Barotrauma.Lights
|
||||
public Sprite overrideLightTexture;
|
||||
public Texture2D texture;
|
||||
|
||||
//Additional sprite drawn on top of the lightsource. Ignores shadows.
|
||||
//Can be used to make lamp sprites glow for example.
|
||||
public Sprite LightSprite;
|
||||
|
||||
//Override the alpha value of the light sprite (if not set, the alpha of the light color is used)
|
||||
//Can be used to make lamp sprites glow at full brightness even if the light itself is dim.
|
||||
public float? OverrideLightSpriteAlpha;
|
||||
|
||||
public SpriteEffects LightSpriteEffect;
|
||||
|
||||
public Submarine ParentSub;
|
||||
|
||||
public bool CastShadows;
|
||||
@@ -125,6 +133,7 @@ namespace Barotrauma.Lights
|
||||
color = new Color(element.GetAttributeVector4("color", Vector4.One));
|
||||
|
||||
CastShadows = element.GetAttributeBool("castshadows", true);
|
||||
|
||||
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
@@ -132,6 +141,12 @@ namespace Barotrauma.Lights
|
||||
{
|
||||
case "sprite":
|
||||
LightSprite = new Sprite(subElement);
|
||||
|
||||
float spriteAlpha = subElement.GetAttributeFloat("alpha", -1.0f);
|
||||
if (spriteAlpha >= 0.0f)
|
||||
{
|
||||
OverrideLightSpriteAlpha = spriteAlpha;
|
||||
}
|
||||
break;
|
||||
case "lighttexture":
|
||||
overrideLightTexture = new Sprite(subElement);
|
||||
@@ -158,34 +173,6 @@ namespace Barotrauma.Lights
|
||||
|
||||
if (addLight) GameMain.LightManager.AddLight(this);
|
||||
}
|
||||
|
||||
/*public void DrawShadows(GraphicsDevice graphics, Camera cam, Matrix shadowTransform)
|
||||
{
|
||||
if (!CastShadows) return;
|
||||
if (range < 1.0f || color.A < 0.01f) return;
|
||||
|
||||
foreach (Submarine sub in Submarine.Loaded)
|
||||
{
|
||||
var hulls = GetHullsInRange(sub);
|
||||
|
||||
if (hulls == null) continue;
|
||||
|
||||
foreach ( ConvexHull ch in hulls)
|
||||
{
|
||||
ch.DrawShadows(graphics, cam, this, shadowTransform, false);
|
||||
}
|
||||
}
|
||||
|
||||
var outsideHulls = GetHullsInRange(null);
|
||||
|
||||
NeedsHullUpdate = false;
|
||||
|
||||
if (outsideHulls == null) return;
|
||||
foreach (ConvexHull ch in outsideHulls)
|
||||
{
|
||||
ch.DrawShadows(graphics, cam, this, shadowTransform, false);
|
||||
}
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Update the contents of ConvexHullList and check if we need to recalculate vertices
|
||||
@@ -310,7 +297,10 @@ namespace Barotrauma.Lights
|
||||
|
||||
private List<Vector2> FindRaycastHits()
|
||||
{
|
||||
if (!CastShadows) return null;
|
||||
if (!CastShadows)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (range < 1.0f || color.A < 0.01f) return null;
|
||||
|
||||
Vector2 drawPos = position;
|
||||
@@ -359,7 +349,7 @@ namespace Barotrauma.Lights
|
||||
points.AddRange(boundaryCorners);
|
||||
|
||||
//visibleSegments.Clear();
|
||||
for (int i=0;i<4;i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
visibleSegments.Add(new Segment(boundaryCorners[i], boundaryCorners[(i + 1) % 4]));
|
||||
}
|
||||
@@ -396,8 +386,8 @@ namespace Barotrauma.Lights
|
||||
foreach (SegmentPoint p in points)
|
||||
{
|
||||
Vector2 dir = Vector2.Normalize(p.WorldPos - drawPos);
|
||||
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
|
||||
Pair<int,Vector2> intersection1 = RayCast(drawPos, drawPos + dir * bounds * 2 - dirNormal, visibleSegments);
|
||||
Pair<int,Vector2> intersection2 = RayCast(drawPos, drawPos + dir * bounds * 2 + dirNormal, visibleSegments);
|
||||
@@ -580,7 +570,10 @@ namespace Barotrauma.Lights
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, BasicEffect lightEffect, Matrix transform)
|
||||
{
|
||||
CheckHullsInRange();
|
||||
if (CastShadows)
|
||||
{
|
||||
CheckHullsInRange();
|
||||
}
|
||||
|
||||
Vector3 offset = ParentSub == null ? Vector3.Zero :
|
||||
new Vector3(ParentSub.DrawPosition.X, ParentSub.DrawPosition.Y, 0.0f);
|
||||
@@ -592,28 +585,31 @@ namespace Barotrauma.Lights
|
||||
|
||||
drawPos.Y = -drawPos.Y;
|
||||
|
||||
/*if (range > 1.0f)
|
||||
{
|
||||
if (overrideLightTexture == null)
|
||||
{
|
||||
Vector2 center = new Vector2(LightTexture.Width / 2, LightTexture.Height / 2);
|
||||
float scale = range / (lightTexture.Width / 2.0f);
|
||||
|
||||
spriteBatch.Draw(lightTexture, drawPos, null, color * (color.A / 255.0f), 0, center, scale, SpriteEffects.None, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
overrideLightTexture.Draw(spriteBatch,
|
||||
drawPos, color * (color.A / 255.0f),
|
||||
overrideLightTexture.Origin, -Rotation,
|
||||
new Vector2(overrideLightTexture.size.X / overrideLightTexture.SourceRect.Width, overrideLightTexture.size.Y / overrideLightTexture.SourceRect.Height));
|
||||
}
|
||||
}
|
||||
|
||||
if (LightSprite != null)
|
||||
{
|
||||
LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin, -Rotation, 1);
|
||||
}*/
|
||||
Vector2 origin = LightSprite.Origin;
|
||||
if (LightSpriteEffect == SpriteEffects.FlipHorizontally) origin.X = LightSprite.SourceRect.Width - origin.X;
|
||||
if (LightSpriteEffect == SpriteEffects.FlipVertically) origin.Y = LightSprite.SourceRect.Height - origin.Y;
|
||||
|
||||
LightSprite.Draw(
|
||||
spriteBatch, drawPos,
|
||||
new Color(Color, OverrideLightSpriteAlpha ?? Color.A / 255.0f),
|
||||
origin, -Rotation, 1, LightSpriteEffect);
|
||||
}
|
||||
|
||||
//if the light doesn't cast shadows, we can simply render the texture without having to calculate the light volume
|
||||
if (!CastShadows)
|
||||
{
|
||||
Texture2D currentTexture = texture ?? LightTexture;
|
||||
if (overrideLightTexture != null) currentTexture = overrideLightTexture.Texture;
|
||||
|
||||
Vector2 center = new Vector2(currentTexture.Width / 2, currentTexture.Height / 2);
|
||||
float scale = range / (currentTexture.Width / 2.0f);
|
||||
|
||||
spriteBatch.Draw(currentTexture, drawPos, null, color * (color.A / 255.0f), 0, center, scale, SpriteEffects.None, 1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (NeedsRecalculation)
|
||||
{
|
||||
@@ -626,14 +622,14 @@ namespace Barotrauma.Lights
|
||||
|
||||
if (vertexCount == 0) return;
|
||||
|
||||
lightEffect.DiffuseColor = (new Vector3(color.R, color.G, color.B) * (color.A / 255.0f)) / 255.0f;// color.ToVector3();
|
||||
lightEffect.DiffuseColor = (new Vector3(color.R, color.G, color.B) * (color.A / 255.0f)) / 255.0f;
|
||||
if (overrideLightTexture != null)
|
||||
{
|
||||
lightEffect.Texture = overrideLightTexture.Texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightEffect.Texture = texture??LightTexture;
|
||||
lightEffect.Texture = texture ?? LightTexture;
|
||||
}
|
||||
lightEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
@@ -642,28 +638,10 @@ namespace Barotrauma.Lights
|
||||
|
||||
GameMain.Instance.GraphicsDevice.DrawIndexedPrimitives
|
||||
(
|
||||
//PrimitiveType.LineList, 0, 0, indexCount / 2
|
||||
PrimitiveType.TriangleList, 0, 0, indexCount / 3
|
||||
);
|
||||
}
|
||||
|
||||
/*public void FlipX()
|
||||
{
|
||||
if (LightSprite != null)
|
||||
{
|
||||
Vector2 lightOrigin = LightSprite.Origin;
|
||||
lightOrigin.X = LightSprite.SourceRect.Width - lightOrigin.X;
|
||||
LightSprite.Origin = lightOrigin;
|
||||
}
|
||||
|
||||
if (overrideLightTexture != null)
|
||||
{
|
||||
Vector2 lightOrigin = overrideLightTexture.Origin;
|
||||
lightOrigin.X = overrideLightTexture.SourceRect.Width - lightOrigin.X;
|
||||
overrideLightTexture.Origin = lightOrigin;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
if (LightSprite != null) LightSprite.Remove();
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
<limb id = "0" width="300" height="673" type="Head" steerforce="1.0" flip="true">
|
||||
<sprite texture="Content/Characters/Carrier/carrier.png" sourcerect="0,0,393,778" depth="0.02" origin ="0.5,0.45"/>
|
||||
|
||||
<lightsource range="400.0" color="0.7,0.8,1.0,1.0">
|
||||
<lighttexture texture="Content/Characters/Carrier/carrier.png" sourcerect="392,0,307,778" origin="0.5, 0.45"/>
|
||||
<lightsource range="1.0" color="0.7,0.8,1.0,1.0" castshadows="false">
|
||||
<sprite texture="Content/Characters/Carrier/carrier.png" sourcerect="392,0,307,778" origin="0.5, 0.45"/>
|
||||
</lightsource>
|
||||
|
||||
<damagemodifier armorsector="0.0,180.0" damagemultiplier="0.1" bleedingmultiplier="0.0" damagesound="SctructureBlunt" deflectprojectiles="true"/>
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
|
||||
<limb id = "1" radius="50" height="120" flip="true">
|
||||
<sprite texture="Content/Characters/Watcher/watcher.png" sourcerect="395,0,117,239" depth="0.025" origin="0.5,0.5"/>
|
||||
<lightsource range="200.0" color="0.8,0.8,1.0,1.0">
|
||||
<lighttexture texture="Content/Characters/Watcher/watcher.png" sourcerect="391,282,121,230" depth="0.025" origin="0.5,0.5"/>
|
||||
<lightsource range="200.0" color="0.8,0.8,1.0,1.0" castshadows="false">
|
||||
<sprite texture="Content/Characters/Watcher/watcher.png" sourcerect="391,282,121,230" depth="0.025" origin="0.5,0.5"/>
|
||||
</lightsource>
|
||||
</limb>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<Sprite texture="lamp.png" sourcerect="0,0,16,32" depth="0.8"/>
|
||||
|
||||
<LightComponent lightcolor="1.0,1.0,1.0,1.0" range ="800.0" powerconsumption="5">
|
||||
<sprite texture="Content/Items/Electricity/lamp.png" sourcerect="33,0,31,37"/>
|
||||
<sprite texture="Content/Items/Electricity/lamp.png" sourcerect="33,0,31,37" alpha="1.0"/>
|
||||
</LightComponent>
|
||||
|
||||
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||
@@ -31,7 +31,7 @@
|
||||
<Sprite texture="lamp.png" sourcerect="0,48,48,16" depth="0.8"/>
|
||||
|
||||
<LightComponent lightcolor="1.0,0.0,0.0,0.2" range="500.0" IsOn="true">
|
||||
<sprite texture="Content/Items/Electricity/lamp.png" sourcerect="0,48,48,16"/>
|
||||
<sprite texture="Content/Items/Electricity/lamp.png" sourcerect="0,48,48,16" alpha="1.0"/>
|
||||
</LightComponent>
|
||||
|
||||
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
|
||||
|
||||
@@ -120,14 +120,6 @@ namespace Barotrauma.Items.Components
|
||||
#endif
|
||||
|
||||
IsActive = IsOn;
|
||||
|
||||
//foreach (XElement subElement in element.Elements())
|
||||
//{
|
||||
// if (subElement.Name.ToString().ToLowerInvariant() != "sprite") continue;
|
||||
|
||||
// light.LightSprite = new Sprite(subElement);
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
|
||||
Reference in New Issue
Block a user