abyss darkness tweaks

- Flashlight is wider
- Luminous Corvina glows through the darkness
- T3/4 torches can glow through the darkness
- Internal refactoring to make more flexible
This commit is contained in:
doze-zoze committed 2026-01-15 20:54:05 -06:00
1 parent fe158cd2f4
commit 261af27a5d
9 files changed
+84 -19

No files matched your search

+2 -2
View File
@@ -4956,7 +4956,7 @@ namespace CalamityMod.CalPlayer
//Flashlight
//Due to being in postUpdate we need to adjust the mousepos for the player's movement that will have happened
var mouseworld = Main.MouseWorld + Player.position - Player.oldPosition;
EnhancedDarknessSystem.lights.Add(new(center: Player.Center + Player.DirectionTo(mouseworld) * 750f, rotation: Player.DirectionTo(mouseworld).ToRotation() - MathHelper.PiOver2, vectorScale: new Vector2(0.75f * abyssFlashlightWidthMultiplier, 0.75f), texture: Request<Texture2D>("CalamityMod/Particles/BloomLineFade")));
EnhancedDarknessSystem.lights.Add(new(center: Player.Center + Player.DirectionTo(mouseworld) * 750f, rotation: Player.DirectionTo(mouseworld).ToRotation() - MathHelper.PiOver2, vectorScale: new Vector2(0.85f * abyssFlashlightWidthMultiplier, 0.75f), texture: Request<Texture2D>("CalamityMod/Particles/BloomLineFade").Value));
}
if (lastDeerclopsPosition.HasValue)
@@ -4969,7 +4969,7 @@ namespace CalamityMod.CalPlayer
//Add the main light circle for the arena
DeerclopsAI.ArenaTex ??= ModContent.Request<Texture2D>(DeerclopsAI.ArenaTexPath);
EnhancedDarknessSystem.lights.Add(new(lastDeerclopsPosition.Value, scale: DeerclopsAI.borderScale, texture: DeerclopsAI.ArenaTex));
EnhancedDarknessSystem.lights.Add(new(lastDeerclopsPosition.Value, scale: DeerclopsAI.borderScale, texture: DeerclopsAI.ArenaTex.Value));
//we draw light around the player when far away so they have some visibility, although very small. This is especially nice in multiplayer. we scale opacity with distance bc it looks better
EnhancedDarknessSystem.lights.Add(new EnhancedDarknessSystem.LightSource(scale: 0.75f, opacity: MathHelper.Clamp(Main.LocalPlayer.DistanceSQ(lastDeerclopsPosition.Value) / (409600 /*640^2*/), 0, 1)));
+27 -10
View File
@@ -14,20 +14,26 @@ namespace CalamityMod.Graphics
{
public class EnhancedDarknessSystem : ModSystem
{
private static Asset<Texture2D> _defaultTexture;
public class LightSource
{
public Asset<Texture2D> texture;
public Texture2D texture = _defaultTexture.Value;
public float scale = 1;
public Vector2 vectorScale = Vector2.One;
public Vector2 center = Main.LocalPlayer.Center;
public float rotation = 0;
public float opacity = 1;
public Color color = Color.White;
public int lifetime = 1;
public Rectangle? frame = null;
public LightSource() { }
public LightSource(Vector2? center = null, Asset<Texture2D> texture = null, float scale = 1, float rotation = 0, Vector2? vectorScale = null, float opacity = 1)
// This constructor only gives the most common arguments. Frame, Color, lifetime, etc. must be set in curly braces afterwards to prevent this constructor getting too unwieldy.
public LightSource(Vector2? center = null, Texture2D texture = null, float scale = 1, float rotation = 0, Vector2? vectorScale = null, float opacity = 1)
{
this.texture = texture ?? ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle");
this.texture = texture ?? ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle").Value;
this.scale = scale;
this.vectorScale = vectorScale ?? Vector2.One;
this.center = center ?? Main.LocalPlayer.Center;
@@ -37,10 +43,11 @@ namespace CalamityMod.Graphics
}
public static List<LightSource> lights = new();
public override void OnModLoad()
public override void Load()
{
On_OverlayManager.Draw += DrawShadowOverlay;
On_LightingEngine.UpdateLightDecay += AdjustTransmissiveness;
_defaultTexture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle");
}
private void DrawShadowOverlay(On_OverlayManager.orig_Draw orig, OverlayManager self, SpriteBatch spriteBatch, RenderLayers layer, bool beginSpriteBatch)
@@ -58,8 +65,8 @@ namespace CalamityMod.Graphics
var device = Main.instance.GraphicsDevice;
using var lease = RenderTargetPool.Shared.Rent(
device,
Main.screenWidth / 2,
Main.screenHeight / 2,
Main.screenWidth,
Main.screenHeight,
RenderTargetDescriptor.Default
);
@@ -68,7 +75,7 @@ namespace CalamityMod.Graphics
Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, Main.Rasterizer, null, Matrix.Identity);
foreach (var item in lights)
{
Main.spriteBatch.Draw(item.texture.Value, (item.center - Main.screenPosition) * 0.5f, null, Color.White * item.opacity, item.rotation, item.texture.Size() * 0.5f, item.vectorScale * item.scale * 0.5f, SpriteEffects.None, 0);
Main.spriteBatch.Draw(item.texture, (item.center - Main.screenPosition), item.frame, item.color * item.opacity, item.rotation, item.frame is null ? item.texture.Size() * 0.5f : item.frame.Value.Size(), item.vectorScale * item.scale, SpriteEffects.None, 0);
}
Main.spriteBatch.End();
}
@@ -79,7 +86,7 @@ namespace CalamityMod.Graphics
var shader = GameShaders.Misc["CalamityMod:DozeLightingShader"];
shader.UseOpacity(mp.darknessIntensity);
shader.Apply();
Main.spriteBatch.Draw(lease.Target, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 2, 0, 0);
Main.spriteBatch.Draw(lease.Target, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, 0, 0);
spriteBatch.End();
}
}
@@ -109,7 +116,17 @@ namespace CalamityMod.Graphics
public override void PreUpdateEntities()
{
//Every frame, the light sources are determined by what was added on that frame only. Therefore, we reset the light list every frame.
lights.Clear();
//Lifetime is provided to smooth out things that don't run every frame consistently to prevent flickering, such as the abyss torches.
for (var i = 0; i < lights.Count; i++)
{
var item = lights[i];
item.lifetime--;
if (item.lifetime <= 0)
{
lights.Remove(item);
i--;
}
}
}
}
@@ -992,7 +992,11 @@ ThaumaticChair: {
ThermalTorch: {
DisplayName: Thermal Torch
Tooltip: Can be placed in water
Tooltip:
'''
Can be placed in water
Can dispell the magical darkness of the Abyss when placed
'''
}
TranquilityCandle: {
@@ -1002,7 +1006,11 @@ TranquilityCandle: {
VoidTorch: {
DisplayName: Void Torch
Tooltip: Can be placed in water
Tooltip:
'''
Can be placed in water
Can dispell the magical darkness of the Abyss when placed
'''
}
AnahitaTrophy: {
+4
View File
@@ -3,6 +3,7 @@ using System.IO;
using CalamityMod.BiomeManagers;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Buffs.StatDebuffs;
using CalamityMod.Graphics;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables.Abyss;
using CalamityMod.Items.Placeables.Banners;
@@ -84,6 +85,9 @@ namespace CalamityMod.NPCs.Abyss
public override void AI()
{
EnhancedDarknessSystem.lights.Add(new(NPC.Center,scale: 1f));
NPC.spriteDirection = (NPC.direction > 0) ? 1 : -1;
NPC.noGravity = true;
if (NPC.direction == 0)
+1 -1
View File
@@ -428,7 +428,7 @@ namespace CalamityMod.Projectiles
//Light Pets will add light to the abyss darkness.
//This uses local player on purpose, as the abyss darkness system is entirely client side.
if (ProjectileID.Sets.LightPet[projectile.type] && Main.LocalPlayer.Calamity().ZoneAbyss)
EnhancedDarknessSystem.lights.Add(new() { center = projectile.Center, texture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle"), scale = 1 });
EnhancedDarknessSystem.lights.Add(new() { center = projectile.Center, scale = 1 });
///Apply Hybrid iframes
if (hybridIframes)
+1 -1
View File
@@ -49,7 +49,7 @@ namespace CalamityMod.Projectiles.Pets
if (underwater)
{
if (Main.LocalPlayer.Calamity().ZoneAbyss)
EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 3, texture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle") });
EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 3, texture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle").Value });
Lighting.AddLight(Projectile.Center, 0.3f, 0.9f, 1.5f);
}
else
+1 -1
View File
@@ -79,7 +79,7 @@ namespace CalamityMod.Projectiles.Pets
if (underwater)
{
if (Main.LocalPlayer.Calamity().ZoneAbyss)
EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 6, texture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle") });
EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 6, texture = ModContent.Request<Texture2D>("CalamityMod/Particles/BloomCircle").Value });
if (Projectile.frame == 16)
Projectile.frame = 0;
if (sleepyTimer > 0)
+19 -1
View File
@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework;
using System.Linq;
using CalamityMod.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
@@ -57,6 +59,22 @@ namespace CalamityMod.Tiles.Abyss
}
}
public override void NearbyEffects(int i, int j, bool closer)
{
//This makes the placed torch cut through the abyss darkness.
var pos = new Point(i, j).ToWorldCoordinates();
if (!closer && Main.LocalPlayer.Calamity().ZoneAbyss && !Main.gamePaused)
{
if (EnhancedDarknessSystem.lights.Any(x => x.center == pos))
{
var e = EnhancedDarknessSystem.lights.First(x => x.center == pos);
e.lifetime = 5;
}
else
EnhancedDarknessSystem.lights.Add(new EnhancedDarknessSystem.LightSource(pos, scale: 2f) { lifetime = 5 });
}
}
public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
{
FlameTexture ??= ModContent.Request<Texture2D>("CalamityMod/Tiles/Abyss/ThermalTorchFlame");
+19 -1
View File
@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework;
using System.Linq;
using CalamityMod.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using Terraria;
@@ -58,6 +60,22 @@ namespace CalamityMod.Tiles.Abyss
}
}
public override void NearbyEffects(int i, int j, bool closer)
{
//This makes the placed torch cut through the abyss darkness.
var pos = new Point(i, j).ToWorldCoordinates();
if (!closer && Main.LocalPlayer.Calamity().ZoneAbyss && !Main.gamePaused)
{
if (EnhancedDarknessSystem.lights.Any(x => x.center == pos))
{
var e = EnhancedDarknessSystem.lights.First(x => x.center == pos);
e.lifetime = 5;
}
else
EnhancedDarknessSystem.lights.Add(new EnhancedDarknessSystem.LightSource(pos, scale: 2f) { lifetime = 5 });
}
}
public override void PostDraw(int i, int j, SpriteBatch spriteBatch)
{
FlameTexture ??= ModContent.Request<Texture2D>("CalamityMod/Tiles/Abyss/VoidTorchFlame");