diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs
index c7a64e729e..8c52399b6a 100644
--- a/CalPlayer/CalamityPlayer.cs
+++ b/CalPlayer/CalamityPlayer.cs
@@ -13,6 +13,7 @@ using CalamityMod.DataStructures;
using CalamityMod.Dusts;
using CalamityMod.Events;
using CalamityMod.FluidSimulation;
+using CalamityMod.Graphics;
using CalamityMod.Items;
using CalamityMod.Items.Accessories;
using CalamityMod.Items.Accessories.Vanity;
@@ -222,7 +223,6 @@ namespace CalamityMod.CalPlayer
#endregion
#region External variables -- Not used by Calamity, only via Mod.Call or reflection
- public int externalAbyssLight = 0;
public float externalBreathTickBoost = 0f;
public float externalFlightTimeMultBoost = 0f;
@@ -709,6 +709,12 @@ namespace CalamityMod.CalPlayer
public int abyssLifeLostAtZeroBreathStat = 0;
/// The amount which defense is reduced while in the Abyss.
public int abyssDefenseLossStat = 0;
+
+ //These stats are for the abyss darkness system.
+ public float abyssDarkness = 0f;
+ public float abyssPlayerGlowMultiplier = 1f;
+ public float abyssFlashlightWidthMultiplier = 1f;
+ public float darknessIntensity = 0;
#endregion
#region Permanent Buff
@@ -2068,7 +2074,6 @@ namespace CalamityMod.CalPlayer
DashID = string.Empty;
- externalAbyssLight = 0;
externalBreathTickBoost = 0f;
externalFlightTimeMultBoost = 0f;
externalRageEnabled = externalAdrenalineEnabled = null;
@@ -2796,6 +2801,14 @@ namespace CalamityMod.CalPlayer
disablePerfCystSpawns = false;
disableVoodooSpawns = false;
+
+ #region Abyss
+ abyssDarkness = 0;
+ abyssPlayerGlowMultiplier = 1;
+ abyssFlashlightWidthMultiplier = 1;
+ darknessIntensity = 0;
+ #endregion
+
EnchantHeldItemEffects(Player, Player.Calamity(), Player.ActiveItem());
}
#endregion
@@ -2924,7 +2937,6 @@ namespace CalamityMod.CalPlayer
rOfResilienceEffect = 0;
demonSwordKillMode = false;
- externalAbyssLight = 0;
externalBreathTickBoost = 0f;
externalFlightTimeMultBoost = 0f;
externalColdImmunity = externalHeatImmunity = false;
@@ -4526,7 +4538,16 @@ namespace CalamityMod.CalPlayer
public override void PostUpdate()
{
+ if (ZoneAbyss && Main.netMode != NetmodeID.Server)
+ {
+ //Main aura
+ EnhancedDarknessSystem.lights.Add(new() { center = Player.Center, rotation = 0, scale = 4 * abyssPlayerGlowMultiplier, texture = ModContent.Request("CalamityMod/Particles/BloomCircle") });
+
+ //Flashlight
+ EnhancedDarknessSystem.lights.Add(new() { center = Player.Center + Player.DirectionTo(mouseWorld) * 750f, rotation = Player.DirectionTo(Main.MouseWorld).ToRotation() - MathHelper.PiOver2, vectorScale = new Vector2(0.75f * abyssFlashlightWidthMultiplier, 0.75f), texture = Request("CalamityMod/Particles/BloomLineFade") });
+ }
+
if (subtitletext != null)
{
if (!subtitletext.active)
diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs
index 9dfd0ab0f6..7e09581eb2 100644
--- a/CalPlayer/CalamityPlayerMiscEffects.cs
+++ b/CalPlayer/CalamityPlayerMiscEffects.cs
@@ -3040,7 +3040,7 @@ namespace CalamityMod.CalPlayer
#region Abyss Effects
private void AbyssEffects()
{
- int lightStrength = Player.GetCurrentAbyssLightLevel();
+ Player.SetAbyssLightLevels();
if (ZoneAbyss)
{
@@ -3058,42 +3058,7 @@ namespace CalamityMod.CalPlayer
double depthRatioFromAbyssLayer1 = playerAbyssDepthFromLayer1 / totalAbyssDepthFromLayer1;
// Darkness strength scales smoothly with how deep you are.
- float darknessStrength = (float)depthRatio;
-
- // Reduce the power of abyss darkness based on your light level.
- float multiplier = 1f;
- switch (lightStrength)
- {
- case 0:
- break;
- case 1:
- multiplier = 0.85f;
- break;
- case 2:
- multiplier = 0.7f;
- break;
- case 3:
- multiplier = 0.55f;
- break;
- case 4:
- multiplier = 0.4f;
- break;
- case 5:
- multiplier = 0.25f;
- break;
- case 6:
- multiplier = 0.15f;
- break;
- case 7:
- multiplier = 0.1f;
- break;
- default:
- multiplier = 0.05f;
- break;
- }
-
- // Modify darkness variable
- caveDarkness = darknessStrength * multiplier;
+ darknessIntensity = abyssDarkness + (float)depthRatio * 3;
// Nebula Headcrab darkness effect
if (!Player.headcovered)
@@ -3233,26 +3198,6 @@ namespace CalamityMod.CalPlayer
// Reduce the power of Signus darkness based on your light level.
float multiplier = 1f;
- switch (Main.LocalPlayer.GetCurrentAbyssLightLevel())
- {
- case 0:
- break;
- case 1:
- case 2:
- multiplier = 0.75f;
- break;
- case 3:
- case 4:
- multiplier = 0.5f;
- break;
- case 5:
- case 6:
- multiplier = 0.25f;
- break;
- default:
- multiplier = 0f;
- break;
- }
float signusDarkness = signusLifeRatio * multiplier;
darkRatio = MathHelper.Clamp(signusDarkness, 0f, 1f);
diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs
index 83d6559fb6..2cd7e2f594 100644
--- a/Effects/CalamityShaders.cs
+++ b/Effects/CalamityShaders.cs
@@ -213,6 +213,11 @@ namespace CalamityMod.Effects
#endregion
#region Doze's Shaders
+ ///
+ /// The shader used for Abyss's custom light system.
+ /// Basically works by turning textures into an opacity mask
+ ///
+ internal static Effect DozeLightingShader;
internal static Effect FlipScreenShader;
#endregion
@@ -456,6 +461,9 @@ namespace CalamityMod.Effects
#endregion
#region Loading Doze's Shaders
+ DozeLightingShader = LoadShader("DozeLightingShader");
+ RegisterMiscShader(DozeLightingShader, "ShadowPass", "DozeLightingShader");
+
FlipScreenShader = LoadShader("ScreenShaders/FlipScreen");
RegisterScreenShader(FlipScreenShader, "FlipTheScreen", "FlipScreen",EffectPriority.VeryHigh);
#endregion
diff --git a/Effects/DozeLightingShader.fx b/Effects/DozeLightingShader.fx
new file mode 100644
index 0000000000..21375981f2
--- /dev/null
+++ b/Effects/DozeLightingShader.fx
@@ -0,0 +1,15 @@
+sampler uImage0 : register(s0);
+float uOpacity;
+
+float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0
+{
+ float4 baseColor = tex2D(uImage0, coords);
+ return float4(0, 0, 0, (1 - baseColor.x) * uOpacity);
+}
+technique Technique1
+{
+ pass ShadowPass
+ {
+ PixelShader = compile ps_2_0 PixelShaderFunction();
+ }
+}
\ No newline at end of file
diff --git a/Effects/DozeLightingShader.xnb b/Effects/DozeLightingShader.xnb
new file mode 100644
index 0000000000..5016f55158
Binary files /dev/null and b/Effects/DozeLightingShader.xnb differ
diff --git a/Graphics/EnhancedDarknessSystem.cs b/Graphics/EnhancedDarknessSystem.cs
new file mode 100644
index 0000000000..b06bbf4e84
--- /dev/null
+++ b/Graphics/EnhancedDarknessSystem.cs
@@ -0,0 +1,103 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using CalamityMod.World;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+using ReLogic.Content;
+using Terraria;
+using Terraria.Graphics.Light;
+using Terraria.Graphics.Shaders;
+using Terraria.ModLoader;
+
+namespace CalamityMod.Graphics
+{
+ public class EnhancedDarknessSystem : ModSystem
+ {
+ public class LightSource
+ {
+ public Asset texture;
+ public float scale = 1;
+ public Vector2 vectorScale = Vector2.One;
+ public Vector2 center = Main.LocalPlayer.Center;
+ public float rotation = 0;
+ }
+ ManagedRenderTarget rt = null;
+
+ public static List lights = new();
+ public override void OnModLoad()
+ {
+ On_Main.DrawInterface += DrawShadows;
+ On_LightingEngine.UpdateLightDecay += AdjustTransmissiveness;
+ RenderTargetManager.RenderTargetUpdateLoopEvent += PrepareTargets;
+ rt = new ManagedRenderTarget(true, ManagedRenderTarget.CreateScreenSizedTarget);
+ }
+
+ private void AdjustTransmissiveness(On_LightingEngine.orig_UpdateLightDecay orig, LightingEngine self)
+ {
+ orig(self);
+ FieldInfo field = typeof(LightingEngine).GetField("_workingLightMap", BindingFlags.Instance | BindingFlags.NonPublic);
+
+ if (field != null)
+ {
+ var mp = Main.LocalPlayer.Calamity();
+ var map = (LightMap)field.GetValue(self);
+ if (mp.ZoneAbyss)
+ {
+ //This converts the light decay amount from the amount it normally is in water into the amount it normally is in air, depending on the intensity of the abyss darkness.
+ //This is to offset the abyss darkness system to make the parts that are supposed to be visible easier to see.
+ //Dividing by 0.91 brings the water back to 100% transmissiveness with the original color
+ map.LightDecayThroughWater = Vector3.Lerp(map.LightDecayThroughWater, (map.LightDecayThroughWater / 0.91f) * 0.95f, MathHelper.Clamp(mp.darknessIntensity, 0, 1));
+ }
+ }
+ }
+
+ private void PrepareTargets()
+ {
+ //This system works by drawing all the light sources additively onto a plain black RenderTarget.
+ //The shader then uses this as an opacity mask, where black = opaque and white = transparent.
+ var gd = Main.instance.GraphicsDevice;
+ gd.SetRenderTarget(rt);
+ gd.Clear(Color.Black);
+ 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, null, Color.White, item.rotation, item.texture.Size() * 0.5f, item.vectorScale * item.scale, SpriteEffects.None, 0);
+ }
+ Main.spriteBatch.End();
+ gd.SetRenderTarget(null);
+ }
+ private void DrawShadows(On_Main.orig_DrawInterface orig, Main self, GameTime gameTime)
+ {
+ var mp = Main.LocalPlayer.Calamity();
+ if (mp.darknessIntensity <= 0)
+ {
+ orig(self, gameTime);
+ return;
+ }
+ var gd = Main.graphics.GraphicsDevice;
+ Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix);
+ Main.spriteBatch.EnterShaderRegion();
+ var shader = GameShaders.Misc["CalamityMod:DozeLightingShader"];
+ var abyssDarkness = Utils.Remap(Main.LocalPlayer.Center.Y, (float)Main.rockLayer * 16f, Main.UnderworldLayer * 16f, 0, 3, true);
+ shader.UseOpacity(mp.darknessIntensity);
+ shader.Apply();
+ Main.spriteBatch.Draw(rt, Main.screenLastPosition - Main.screenPosition, Color.White);
+ Main.spriteBatch.ExitShaderRegion();
+ Main.spriteBatch.End();
+ orig(self, gameTime);
+ }
+
+ public override void OnWorldUnload()
+ {
+ lights.Clear();
+ }
+
+ 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();
+ }
+
+ }
+}
diff --git a/Items/Accessories/StatMeter.cs b/Items/Accessories/StatMeter.cs
index 10edb5b418..24e0269642 100644
--- a/Items/Accessories/StatMeter.cs
+++ b/Items/Accessories/StatMeter.cs
@@ -222,7 +222,9 @@ namespace CalamityMod.Items.Accessories
// Detailed Abyss stats only render if the player is in the Abyss.
string stats4 = "\n" + (!modPlayer.ZoneAbyss ? this.GetLocalizedValue("AbyssStatsHidden") : this.GetLocalization("AbyssStats").Format(
- player.GetCurrentAbyssLightLevel(),
+ modPlayer.abyssDarkness,
+ modPlayer.abyssPlayerGlowMultiplier,
+ modPlayer.abyssFlashlightWidthMultiplier,
TwoPlaces(modPlayer.abyssBreathLossRateStat),
modPlayer.abyssLifeLostAtZeroBreathStat,
modPlayer.abyssDefenseLossStat));
diff --git a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson
index 60b3c0f0b4..1e8d4dc1a2 100644
--- a/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson
+++ b/Localization/en-US/Mods.CalamityMod.Items.Accessories.hjson
@@ -1821,10 +1821,10 @@ StatMeter: {
MiscStats: Aggro: {0} | Luck: {1}%
AbyssStats:
'''
- Abyss Light Strength: {0}
- Breath Loss Rate: {1}
- Life Lost Per Tick at Zero Breath: {2}
- Defense Lost From Pressure: {3}
+ Abyss Darkness: {0} | Player Glow: {1}x | Flashlight: {2}x
+ Breath Loss Rate: {3}
+ Life Lost Per Tick at Zero Breath: {4}
+ Defense Lost From Pressure: {5}
'''
AbyssStatsHidden: Abyss stats are only displayed while in the Abyss
}
diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs
index 9d2985bac3..49bee82e11 100644
--- a/ModSupport/ModCalls.cs
+++ b/ModSupport/ModCalls.cs
@@ -663,12 +663,17 @@ namespace CalamityMod
#endregion
#region Other Player Stats
- public static int GetLightStrength(Player p) => p?.GetCurrentAbyssLightLevel() ?? 0;
-
- public static void AddAbyssLightStrength(Player p, int add)
+ public static float GetDarknessIntensity(Player p)
{
if (p != null)
- p.Calamity().externalAbyssLight += add;
+ return p.Calamity().darknessIntensity;
+ return 0;
+ }
+
+ public static void AddAbyssLightStrength(Player p, float add)
+ {
+ if (p != null)
+ p.Calamity().abyssDarkness -= add;
}
public static void AddBreathTick(Player p, float add)
@@ -1206,11 +1211,14 @@ namespace CalamityMod
case "GetAbyssLight":
case "GetAbyssLightLevel":
case "GetAbyssLightStrength":
+ case "GetDarkness":
+ case "GetAbyssDarkness":
+ case "GetDarknessIntensity":
if (args.Length < 2)
return new ArgumentNullException("ERROR: Must specify a Player object (or int index of a Player).");
if (!isValidPlayerArg(args[1]))
return new ArgumentException("ERROR: The argument to \"GetLightStrength\" must be a Player or an int.");
- return GetLightStrength(castPlayer(args[1]));
+ return GetDarknessIntensity(castPlayer(args[1]));
case "AddLight":
case "AddLightLevel":
diff --git a/Projectiles/Pets/BabyGhostBell.cs b/Projectiles/Pets/BabyGhostBell.cs
index ec696d2407..4556e2a2a7 100644
--- a/Projectiles/Pets/BabyGhostBell.cs
+++ b/Projectiles/Pets/BabyGhostBell.cs
@@ -1,4 +1,6 @@
using CalamityMod.CalPlayer;
+using CalamityMod.Graphics;
+using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -46,6 +48,7 @@ namespace CalamityMod.Projectiles.Pets
underwater = Collision.DrownCollision(player.position, player.width, player.height, player.gravDir);
if (underwater)
{
+ EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 3, texture = ModContent.Request("CalamityMod/Particles/BloomCircle") });
Lighting.AddLight(Projectile.Center, 0.3f, 0.9f, 1.5f);
}
else
diff --git a/Projectiles/Pets/OceanSpirit.cs b/Projectiles/Pets/OceanSpirit.cs
index 233fb80d29..600d1cf18d 100644
--- a/Projectiles/Pets/OceanSpirit.cs
+++ b/Projectiles/Pets/OceanSpirit.cs
@@ -1,5 +1,7 @@
using CalamityMod.CalPlayer;
+using CalamityMod.Graphics;
using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -76,6 +78,7 @@ namespace CalamityMod.Projectiles.Pets
underwater = player.IsUnderwater();
if (underwater)
{
+ EnhancedDarknessSystem.lights.Add(new() { center = Projectile.Center, rotation = 0, scale = 6, texture = ModContent.Request("CalamityMod/Particles/BloomCircle") });
if (Projectile.frame == 16)
Projectile.frame = 0;
if (sleepyTimer > 0)
diff --git a/Systems/Graphic/LightingEffectsSystem.cs b/Systems/Graphic/LightingEffectsSystem.cs
index 1bc1a1631b..8f4c75e59f 100644
--- a/Systems/Graphic/LightingEffectsSystem.cs
+++ b/Systems/Graphic/LightingEffectsSystem.cs
@@ -36,28 +36,7 @@ namespace CalamityMod.Systems
{
float signusLifeRatio = 1f - (Main.npc[CalamityGlobalNPC.signus].life / Main.npc[CalamityGlobalNPC.signus].lifeMax);
- // Reduce the power of Signus darkness based on your light level.
float multiplier = 1f;
- switch (Main.LocalPlayer.GetCurrentAbyssLightLevel())
- {
- case 0:
- break;
- case 1:
- case 2:
- multiplier = 0.75f;
- break;
- case 3:
- case 4:
- multiplier = 0.5f;
- break;
- case 5:
- case 6:
- multiplier = 0.25f;
- break;
- default:
- multiplier = 0f;
- break;
- }
// Total darkness
float signusDarkness = signusLifeRatio * multiplier;
diff --git a/Utilities/PlayerUtils.cs b/Utilities/PlayerUtils.cs
index 44011b1330..d5df797029 100644
--- a/Utilities/PlayerUtils.cs
+++ b/Utilities/PlayerUtils.cs
@@ -170,82 +170,44 @@ namespace CalamityMod
/// Calculates and returns the player's total light strength. This is used for Abyss darkness, among other things.
/// The Stat Meter also reports this stat.
///
- /// The player's total light strength.
- public static int GetCurrentAbyssLightLevel(this Player player)
+ public static void SetAbyssLightLevels(this Player player)
{
CalamityPlayer mp = player.Calamity();
- int light = mp.externalAbyssLight;
bool underwater = player.IsUnderwater();
bool miningHelmet = player.head == ArmorIDs.Head.MiningHelmet || player.head == ArmorIDs.Head.UltraBrightHelmet;
-
- // The campfire bonus does not apply while in the Abyss.
- if (!mp.ZoneAbyss && (player.HasBuff(BuffID.Campfire) || Main.SceneMetrics.HasCampfire))
- light += 1;
- if (mp.camper) // inherits Campfire so it is +2 in practice
- light += 1;
+ //Things that include darkness multipliers
+ if (mp.camper)
+ mp.abyssPlayerGlowMultiplier += Utils.Remap(player.velocity.Length(), 0, 5, 1, 0);
if (miningHelmet)
- light += 1;
- if (player.hasMagiluminescence)
- light += 1;
- if (player.lightOrb)
- light += 1;
- if (player.crimsonHeart)
- light += 1;
- if (player.magicLantern)
- light += 1;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
+ if (player.nightVision)
+ mp.abyssDarkness -= 0.4f;
if (mp.giantPearl)
- light += 1;
- if (mp.radiator)
- light += 1;
- if (mp.bendyPet)
- light += 1;
- if (mp.sparks)
- light += 1;
- if (mp.thiefsDime)
- light += 1;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
if (mp.fathomSwarmerVisage)
- light += 1;
+ {
+ mp.abyssDarkness -= 0.2f;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
+ mp.abyssFlashlightWidthMultiplier += 0.5f;
+ }
if (mp.aquaticHeart)
- light += 1;
- if (mp.purity) // does not stack with downgrades
- light += 2;
- else if (mp.rOoze || mp.aAmpoule) // the two "yellow lights" do not stack with each other
- light += 1;
- if (mp.aquaticEmblem && underwater)
- light += 1;
- if (player.arcticDivingGear && underwater) // inherited by abyssal diving gear/suit. jellyfish necklace is inherited so arctic diving gear is really +2
- light += 1;
+ mp.abyssDarkness -= 0.1f;
if (mp.jellyfishNecklace && underwater) // inherited by jellyfish diving gear and higher
- light += 1;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
if (mp.reaverExplore)
- light += 2;
+ {
+ mp.abyssDarkness -= 0.2f;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
+ mp.abyssFlashlightWidthMultiplier += 0.5f;
+ }
if (mp.shine)
- light += 2;
- if (mp.blazingCore)
- light += 2;
- if (player.redFairy || player.greenFairy || player.blueFairy)
- light += 2;
- if (mp.babyGhostBell)
- light += underwater ? 2 : 1;
- if (player.petFlagDD2Ghost)
- light += 2;
- if (mp.sirenPet)
- light += underwater ? 3 : 1;
- if (player.petFlagPumpkingPet)
- light += 3;
- if (player.petFlagGolemPet)
- light += 3;
- if (player.petFlagFairyQueenPet)
- light += 3;
- if (player.wisp)
- light += 3;
- if (player.suspiciouslookingTentacle)
- light += 3;
+ mp.abyssPlayerGlowMultiplier += 0.2f;
+ if (mp.babyGhostBell && underwater)
+ mp.abyssDarkness -= 0.1f;
+ if (mp.sirenPet && underwater)
+ mp.abyssDarkness -= 0.2f;
if (mp.littleLightPet)
- light += 3;
- if (mp.profanedCrystalBuffs && !mp.ZoneAbyss)
- light += (Main.dayTime || player.lavaWet) ? 2 : 1; // not sure how you'd be in lava in the abyss but go ham I guess
- return light;
+ mp.abyssDarkness -= 0.4f;
}
///