diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index e9ff7b8999..6c70e67afb 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -266,6 +266,9 @@ namespace CalamityMod.Effects // The swirling aura effect seen around Horrible Hog while its idling. internal static Asset HorribleHogAuraShader; + + // The shader effect for the primitive trails drawn for Providence's HolyBurnOrb/HolyLight projectiles. + internal static Asset ProvidenceHolyOrbTrailShader; #endregion #region Big E's Shaders @@ -537,6 +540,9 @@ namespace CalamityMod.Effects HorribleHogAuraShader = LoadShader("HorribleHogAuraShader"); RegisterMiscShader(HorribleHogAuraShader, "ScaryAuraPass", "HorribleHogAura"); + + ProvidenceHolyOrbTrailShader = LoadShader("ProvidenceHolyOrbTrailShader"); + RegisterMiscShader(ProvidenceHolyOrbTrailShader, "TrailPass", "ProvidenceHolyOrbTrail"); #endregion #region Loading Big E's Shaders diff --git a/Effects/ProvidenceHolyOrbTrailShader.fx b/Effects/ProvidenceHolyOrbTrailShader.fx new file mode 100644 index 0000000000..9f5c67d241 --- /dev/null +++ b/Effects/ProvidenceHolyOrbTrailShader.fx @@ -0,0 +1,68 @@ +// 29JUN2026: fryzahh +// Programmed to work under the use of SanePrimitiveRenderer. +// Never use this shader with PrimitveRenderer. + +sampler baseStreakTexture : register(s0); +sampler distortionTexture : register(s1); + +matrix uTransformMatrix; +float time; +float glowPower; +float pixelationFactor; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +struct VertexShaderOutput +{ + float4 Position : SV_POSITION; + float4 Color : COLOR0; + float2 TextureCoordinates : TEXCOORD0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output; + output.Position = mul(input.Position, uTransformMatrix); + output.Color = input.Color; + output.TextureCoordinates = input.TextureCoordinates; + return output; +} + +float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 +{ + float4 color = input.Color; + float2 coords = input.TextureCoordinates; + + // Fade out at the horizontal and vertical ends of the streak. + float horizonatalDistanceFromCenter = distance(0.5, coords.y); + float opacity = smoothstep(0.5, 0.5 - 0.486, horizonatalDistanceFromCenter); + + // Glow from the center go out. + float glow = pow(0.1 / horizonatalDistanceFromCenter, glowPower); + + float2 distortionCoords = coords + float2(time * -3.12, 0); + distortionCoords *= float2(0.25, 1); + float distortion = tex2D(distortionTexture, distortionCoords).r * 0.43; + + float2 streakCoords = coords + float2(time * -2.34, 0); + streakCoords *= float2(1.25, 1); + float4 streakMapColor = tex2D(baseStreakTexture, streakCoords + distortion); + + float4 returnColor = (streakMapColor * color * glow) * opacity; + returnColor = round(returnColor * 7) / 7; + return returnColor; +} + +technique Technique1 +{ + pass TrailPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/ProvidenceHolyOrbTrailShader.xnb b/Effects/ProvidenceHolyOrbTrailShader.xnb new file mode 100644 index 0000000000..dda2ab7acc Binary files /dev/null and b/Effects/ProvidenceHolyOrbTrailShader.xnb differ diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index f7466891f6..b01544e1ca 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -30,6 +30,7 @@ using CalamityMod.Tiles; using CalamityMod.Utilities.Daybreak; using CalamityMod.Walls; using CalamityMod.Walls.UnsafeWalls; +using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Mono.Cecil.Cil; @@ -1118,19 +1119,92 @@ namespace CalamityMod.ILEditing { // If an Abyss wall is detected, try to find another teleportation location bool canSpawn = false; - int teleportStartX = 100; + int halfWorldWidth = Main.maxTilesX / 2; + + int teleportStartX = Abyss.AtLeftSideOfWorld ? halfWorldWidth - (halfWorldWidth - 175) + 35 : halfWorldWidth + (halfWorldWidth - 175) - 35; int teleportRangeX = Main.maxTilesX - 200; int teleportStartY = 100; - int underworldLayer = Main.UnderworldLayer; - Vector2 newerPos = self.CheckForGoodTeleportationSpot(ref canSpawn, teleportStartX, teleportRangeX, teleportStartY, underworldLayer, new Player.RandomTeleportationAttemptSettings + int teleportRangeY = Main.UnderworldLayer; + + int attempts = 0; + int maxAttempts = 1000; + int teleportPositionX = 0; + int teleportPositionY = 0; + Vector2 teleportPosition = new Vector2(teleportPositionX, teleportPositionY) * 16f - new Vector2(self.width * 0.5f + 8, self.height); + while (!canSpawn && attempts < maxAttempts) { - avoidLava = true, - avoidHurtTiles = true, - maximumFallDistanceFromOrignalPoint = 100, - attemptsBeforeGivingUp = 1000 - }); + attempts++; + + if (Abyss.AtLeftSideOfWorld) + teleportPositionX = teleportStartX + Main.rand.Next(teleportRangeX); + else + teleportPositionX = teleportStartX - Main.rand.Next(teleportRangeX); + teleportPositionY = teleportStartY + Main.rand.Next(teleportRangeY); + + teleportPositionX = MathHelper.Clamp(teleportPositionX, 5, Main.maxTilesX - 5); + teleportPositionY = MathHelper.Clamp(teleportPositionY, 5, Main.maxTilesY - 5); + teleportPosition = new Vector2(teleportPositionX, teleportPositionY) * 16f - new Vector2(self.width * 0.5f + 8, self.height); + + if (Collision.SolidCollision(teleportPosition, self.width, self.height)) + continue; + + Tile tile = Framing.GetTileSafely(new Point(teleportPositionX, teleportPositionY)); + bool behindTempleWalls = tile.WallType == WallID.LihzahrdBrickUnsafe && teleportPositionY > Main.worldSurface && !NPC.downedPlantBoss; + bool behindDungeonWalls = Main.wallDungeon[tile.WallType] && teleportPositionY > Main.worldSurface && !NPC.downedBoss3; + if (behindTempleWalls || behindDungeonWalls) + continue; + + int distanceToGround = 0; + int maxFallDistance = 100; + while (distanceToGround < maxFallDistance) + { + Tile groundTile = Framing.GetTileSafely(new Point(teleportPositionX, teleportPositionY + distanceToGround)); + teleportPosition = new Vector2(teleportPositionX, teleportPositionY + distanceToGround) * 16f - new Vector2(self.width * 0.5f + 8, self.height); + Collision.SlopeCollision(teleportPosition, self.velocity, self.width, self.height, self.gravDir); + if (!Collision.SolidCollision(teleportPosition, self.width, self.height)) + { + distanceToGround++; + continue; + } + + if (groundTile.HasUnactuatedTile && Main.tileSolid[groundTile.TileType]) + break; + + distanceToGround++; + } + + teleportPosition.Y -= 16f; + bool inLava = Collision.LavaCollision(teleportPosition, self.width, self.height); + bool onHurtingTile = Collision.AnyHurtingTiles(teleportPosition, self.width, self.height); + bool insideBlocks = Collision.SolidCollision(teleportPosition, self.width, self.height); + bool reachedMaxFallDistance = distanceToGround >= maxFallDistance; + if (inLava || onHurtingTile || insideBlocks || reachedMaxFallDistance) + continue; + + Vector2 checkDirection = Vector2.UnitX * 16f; + if (Collision.TileCollision(teleportPosition - checkDirection, checkDirection, self.width, self.height, false, false, (int)self.gravDir) != checkDirection) + continue; + + checkDirection = Vector2.UnitX * -16f; + if (Collision.TileCollision(teleportPosition - checkDirection, checkDirection, self.width, self.height, false, false, (int)self.gravDir) != checkDirection) + continue; + + checkDirection = Vector2.UnitY * 16f; + if (Collision.TileCollision(teleportPosition - checkDirection, checkDirection, self.width, self.height, false, false, (int)self.gravDir) == checkDirection) + { + checkDirection = Vector2.UnitY * -16f; + if (Collision.TileCollision(teleportPosition - checkDirection, checkDirection, self.width, self.height, false, false, (int)self.gravDir) == checkDirection) + { + canSpawn = true; + teleportPositionY += distanceToGround; + teleportPosition = new Vector2(teleportPositionX, teleportPositionY) * 16f - new Vector2(self.width * 0.5f + 8, self.height); + break; + } + } + } + // Attempt teleporting again with the new location - orig(self, newerPos, Style, extraInfo); + orig(self, teleportPosition, Style, extraInfo); } else { diff --git a/NPCs/NormalNPCs/DivineSwine.cs b/NPCs/NormalNPCs/DivineSwine.cs index 931bab8b93..8743051f3b 100644 --- a/NPCs/NormalNPCs/DivineSwine.cs +++ b/NPCs/NormalNPCs/DivineSwine.cs @@ -112,7 +112,9 @@ namespace CalamityMod.NPCs.NormalNPCs Main.npcFrameCount[Type] = 14; NPCID.Sets.CountsAsCritter[Type] = true; NPCID.Sets.CantTakeLunchMoney[Type] = true; - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 3, Type); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type); + NPCID.Sets.ImmuneToAllBuffs[Type] = true; + NPCID.Sets.ShimmerImmunity[Type] = true; } public override void SetDefaults() @@ -129,9 +131,12 @@ namespace CalamityMod.NPCs.NormalNPCs NPC.DeathSound = SoundID.NPCDeath1; NPC.immortal = true; NPC.noGravity = true; - NPC.Calamity().VulnerableToHeat = true; - NPC.Calamity().VulnerableToCold = true; - NPC.Calamity().VulnerableToSickness = true; + + NPC.Calamity().VulnerableToCold = false; + NPC.Calamity().VulnerableToElectricity = false; + NPC.Calamity().VulnerableToHeat = false; + NPC.Calamity().VulnerableToSickness = false; + NPC.Calamity().VulnerableToWater = false; } public override void OnSpawn(IEntitySource source) @@ -290,14 +295,10 @@ namespace CalamityMod.NPCs.NormalNPCs SoundEngine.PlaySound(SoundID.Item29 with { Volume = 0.1f }, NPC.Center); SoundEngine.PlaySound(IdleSound, NPC.Center); - if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out var activeSound)) - activeSound.Stop(); + if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) + swineSpeakInstance.Stop(); - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NPC.Transform(ModContent.NPCType()); - NPC.netUpdate = true; - } + NPC.Transform(ModContent.NPCType()); } } @@ -432,6 +433,9 @@ namespace CalamityMod.NPCs.NormalNPCs GeneralParticleHandler.SpawnParticle(Main.rand.NextBool() ? meatSparkle : meatLight, true, Enums.GeneralDrawLayer.AfterNPCs); } + if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) + swineSpeakInstance.Stop(); + // Despawn immediately afterwards. NPC.checkDead(); NPC.active = false; @@ -465,6 +469,8 @@ namespace CalamityMod.NPCs.NormalNPCs SoundEngine.PlaySound(SoundID.Item29 with { Volume = 0.1f }, NPC.Center); SoundEngine.PlaySound(IdleSound, NPC.Center); + if (SoundEngine.TryGetActiveSound(SwineSpeakSoundSlot, out ActiveSound swineSpeakInstance)) + swineSpeakInstance.Stop(); NPC.checkDead(); NPC.active = false; diff --git a/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs index 5d8522b4fe..0dd70afbc7 100644 --- a/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs +++ b/NPCs/NormalNPCs/HorribleHog/HorribleHog.AI.Transitionals.cs @@ -104,11 +104,7 @@ namespace CalamityMod.NPCs.NormalNPCs.HorribleHog if (SoundEngine.TryGetActiveSound(DevilsTongueSlot, out var activeSound)) activeSound.Stop(); - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NPC.Transform(ModContent.NPCType()); - NPC.netUpdate = true; - } + NPC.Transform(ModContent.NPCType()); } Animate(IdleFrame, IdleFrame, 0, false, dynamicChanges: true); diff --git a/NPCs/NormalNPCs/Piggy.cs b/NPCs/NormalNPCs/Piggy.cs index 86fc4b4116..20f8127463 100644 --- a/NPCs/NormalNPCs/Piggy.cs +++ b/NPCs/NormalNPCs/Piggy.cs @@ -168,7 +168,7 @@ namespace CalamityMod.NPCs.NormalNPCs { NPC.velocity.X *= 0.9f; NPC.rotation = 0f; - if (!SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) + if (Timer < 2 && !SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) NearbySoundSlot = SoundEngine.PlaySound(DivineSwine_SwineSpeakLoopingSound, NPC.Center, NearbySoundCallbackMethod); float lightSpawnDistance = MathHelper.Lerp(52f, 84f, Timer / 180f); @@ -211,7 +211,7 @@ namespace CalamityMod.NPCs.NormalNPCs GeneralParticleHandler.SpawnParticle(feather, manualDrawLayerOverride: Enums.GeneralDrawLayer.BeforeNPCs); } - if (Timer >= 180f && Main.netMode != NetmodeID.MultiplayerClient) + if (Timer >= 180f) { CustomPulse lightRing = new(NPC.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomRing", Vector2.One, 0f, 0f, 2f, 75); GeneralParticleHandler.SpawnParticle(lightRing); @@ -232,7 +232,6 @@ namespace CalamityMod.NPCs.NormalNPCs activeSound.Stop(); NPC.Transform(ModContent.NPCType()); - NPC.netUpdate = true; } } @@ -240,7 +239,7 @@ namespace CalamityMod.NPCs.NormalNPCs { NPC.velocity.X *= 0.9f; NPC.rotation = 0f; - if (!SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) + if (Timer < 2 && !SoundEngine.TryGetActiveSound(NearbySoundSlot, out _)) NearbySoundSlot = SoundEngine.PlaySound(HorribleHog_DevilsTongueLoopingSound, NPC.Center, NearbySoundCallbackMethod); float smokeOpacity = Utils.GetLerpValue(0f, 45f, Timer, true); @@ -264,11 +263,7 @@ namespace CalamityMod.NPCs.NormalNPCs if (SoundEngine.TryGetActiveSound(NearbySoundSlot, out var activeSound)) activeSound.Stop(); - if (Main.netMode != NetmodeID.MultiplayerClient) - { - NPC.Transform(ModContent.NPCType()); - NPC.netUpdate = true; - } + NPC.Transform(ModContent.NPCType()); } } diff --git a/NPCs/NormalNPCs/PiggyGold.cs b/NPCs/NormalNPCs/PiggyGold.cs index de5acee1b0..5f6978d906 100644 --- a/NPCs/NormalNPCs/PiggyGold.cs +++ b/NPCs/NormalNPCs/PiggyGold.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using CalamityMod.Items.Critters; using CalamityMod.Items.Placeables.Banners; using Microsoft.Xna.Framework; +using Terraria; using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; @@ -16,9 +17,13 @@ namespace CalamityMod.NPCs.NormalNPCs { public override void SetStaticDefaults() { + Main.npcFrameCount[Type] = 8; + Main.npcCatchable[Type] = true; + NPCID.Sets.CountsAsCritter[Type] = true; + NPCID.Sets.CantTakeLunchMoney[Type] = true; + NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true; NPCID.Sets.GoldCrittersCollection.Add(Type); - NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 2, Type); - base.SetStaticDefaults(); + NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(ModContent.NPCType()) + 1, Type); } public override void SetDefaults() diff --git a/NPCs/Providence/Providence.cs b/NPCs/Providence/Providence.cs index 395e594285..3a418d463e 100644 --- a/NPCs/Providence/Providence.cs +++ b/NPCs/Providence/Providence.cs @@ -2803,14 +2803,6 @@ namespace CalamityMod.NPCs.Providence // These will be used for almost every single one of her projectiles, so it's useful to have. public static class ProvUtils { - /// - /// This lease should be used to draw all of a projectile's effects onto directly, then be drawn onto the screen as one. This is for opacity reasons - /// - public static RenderTargetLease PrimaryLease { get => field ??= ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice); set; } - /// - /// This should be used for secondary effects like trails, then drawn to PrimaryLease. This is for opacity reasons. - /// - public static RenderTargetLease SecondaryLease { get => field ??= ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice); set; } public static bool StandardAI() => (CalamityGlobalNPC.holyBoss == -1 || !Main.npc[CalamityGlobalNPC.holyBoss].Calamity().CurrentlyEnraged) && !Main.zenithWorld; public static int CalculateProvidenceDamage(this int damage) diff --git a/Projectiles/Boss/HolyBurnOrb.cs b/Projectiles/Boss/HolyBurnOrb.cs index e76ac00c6f..a88beb4dcf 100644 --- a/Projectiles/Boss/HolyBurnOrb.cs +++ b/Projectiles/Boss/HolyBurnOrb.cs @@ -1,18 +1,18 @@ using System; using System.Collections.Generic; -using System.Linq; using CalamityMod.Dusts; +using CalamityMod.Effects; using CalamityMod.Graphics.Primitives; using CalamityMod.NPCs.Providence; using CalamityMod.Particles; +using CalamityMod.Systems.Graphic; using CalamityMod.Utilities.Daybreak; using CalamityMod.Utilities.Daybreak.Buffers; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Newtonsoft.Json.Serialization; +using ReLogic.Content; using Terraria; using Terraria.Audio; -using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; @@ -20,14 +20,29 @@ namespace CalamityMod.Projectiles.Boss { public class HolyBurnOrb : ModProjectile, ILocalizedModType { + private static Asset TrailNoiseTexture; + private static Asset TrailDistortionTexture; + private static Asset GlowOrbTexture; + bool started = false; + public new string LocalizationCategory => "Projectiles.Boss"; public override string Texture => "CalamityMod/Projectiles/StarProj"; + public override void Load() + { + if (!Main.dedServ) + { + TrailNoiseTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/HarshNoise"); + TrailDistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Neurons2"); + GlowOrbTexture = ModContent.Request("CalamityMod/Particles/GlowOrbParticle"); + } + } + public override void SetStaticDefaults() { - ProjectileID.Sets.TrailCacheLength[Type] = 32; - ProjectileID.Sets.TrailingMode[Type] = 2; + ProjectileID.Sets.TrailCacheLength[Type] = 12; + ProjectileID.Sets.TrailingMode[Type] = 0; } public override void SetDefaults() { @@ -87,59 +102,6 @@ namespace CalamityMod.Projectiles.Boss Projectile.position -= (Projectile.velocity / Projectile.MaxUpdates) * (Projectile.MaxUpdates - 1); } - public override bool PreDraw(ref Color lightColor) - { - //drawn by the HolyBurnOrbDrawer system - return false; - } - public float FireWidthFunction(float completion, Vector2 pos) - { - float width; - float maxBodyWidth = 32f * Projectile.scale; - float curveRatio = 0.2f; - var positions = Projectile.oldPos.ToList(); - positions.RemoveAll(x => x == Vector2.Zero); - // Crop the tip of the trail into a conic shape. - if (completion < curveRatio) - width = MathF.Pow(completion / curveRatio, 0.5f) * maxBodyWidth; - else - width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); - - // Pulse inwards and outwards over time. - float pulseInterpolant = MathF.Cos(MathHelper.Pi * completion - Main.GlobalTimeWrappedHourly * 20f) * 0.5f + 0.5f; - float additionalPulseWidth = MathHelper.Lerp(0f, 12f, pulseInterpolant); - return (width + additionalPulseWidth) * positions.Count() / (float)ProjectileID.Sets.TrailCacheLength[Type]; - } - - public Color FireColorFunction(float completion, Vector2 pos) - { - Color mainColor = ProvUtils.GetProjectileColor(255) * 1.3f; - Color endColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); - return Color.Lerp(mainColor, endColor, completion) * Projectile.Opacity; - } - - public float FireCoreWidthFunction(float completion, Vector2 pos) - { - float width; - float maxBodyWidth = Projectile.scale * 24; - float curveRatio = 0.25f; - var positions = Projectile.oldPos.ToList(); - positions.RemoveAll(x => x == Vector2.Zero); - - if (completion < curveRatio) - width = MathF.Sin(completion / curveRatio * MathHelper.PiOver2) * maxBodyWidth + curveRatio; - else - width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); - return width * positions.Count() / (float)ProjectileID.Sets.TrailCacheLength[Type]; - } - - public Color FireCoreColorFunction(float completion, Vector2 pos) - { - Color mainColor = ProvUtils.GetProjectileColor(255); - Color tipColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); - Color fullBodyColor = Color.Lerp(mainColor, tipColor, completion); - return Color.Lerp(fullBodyColor, Color.White, 0.175f) * Projectile.Opacity; - } public override void OnKill(int timeLeft) { @@ -173,191 +135,168 @@ namespace CalamityMod.Projectiles.Boss ProvUtils.ApplyDebuffs(target, 120); } - } - - public class HolyBurnOrbDrawer : ModSystem - { - public override void Load() + public float FireWidthFunction(float completion) { - On_Main.DrawProjectiles += DrawAll; + float width; + float maxBodyWidth = 36f * Projectile.scale; + float curveRatio = 0.2f; + + // Crop the tip of the trail into a conic shape. + if (completion < curveRatio) + width = MathF.Pow(completion / curveRatio, 0.5f) * maxBodyWidth; + else + width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); + + // Pulse inwards and outwards over time. + float pulseInterpolant = MathF.Cos(MathHelper.Pi * completion - Main.GlobalTimeWrappedHourly * 12f) * 0.5f + 0.5f; + float additionalPulseWidth = MathHelper.Lerp(0f, 6f, pulseInterpolant); + return (width + additionalPulseWidth); } - private void DrawAll(On_Main.orig_DrawProjectiles orig, Main self) + public Color FireColorFunction(float completion) { - orig(self); - - var device = Main.instance.GraphicsDevice; - - List burnToDraw = []; - List healToDraw = []; - - - foreach (var item in Main.ActiveProjectiles) - { - if (item.type == ModContent.ProjectileType()) - burnToDraw.Add(item); - - if (item.type == ModContent.ProjectileType()) - healToDraw.Add(item); - } - - if ((healToDraw.Count() + burnToDraw.Count()) < 1) - return; - - using (Main.spriteBatch.Scope()) - { - - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - - //Burn trails - using (ProvUtils.PrimaryLease.Scope(clearColor: Color.Transparent)) - { - foreach (var item in burnToDraw) - DrawBurnOrbTrail(item); - - } - Main.spriteBatch.Draw(ProvUtils.PrimaryLease.Target, Vector2.Zero, null, Color.White * 0.75f, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); - - //Heal trail - using (ProvUtils.SecondaryLease.Scope(clearColor: Color.Transparent)) - { - foreach (var item in healToDraw) - DrawHealOrbTrail(item); - - } - Main.spriteBatch.Draw(ProvUtils.SecondaryLease.Target, Vector2.Zero, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); - - //Main orb - foreach (var item in burnToDraw) - DrawBurnOrb(item); - foreach (var item in healToDraw) - DrawHealOrb(item); - - //Additive orb - Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); - foreach (var item in burnToDraw) - DrawBurnOrbAdditive(item); - foreach (var item in healToDraw) - DrawHealOrbAdditive(item); - Main.spriteBatch.End(); - } + Color mainColor = Color.Lerp(ProvUtils.GetProjectileColor(255, true) * 2f, ProvUtils.GetProjectileColor(255), 0.75f); + Color endColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); + return Color.Lerp(mainColor, endColor, completion) * Projectile.Opacity; } - void DrawBurnOrbTrail(Projectile Projectile) + public void DrawTrail() { - if (Projectile.ModProjectile is HolyBurnOrb M) + Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f); + Vector2 basePosition = Projectile.Center - Main.screenPosition; + Rectangle screenBounds = new Rectangle(-40, -40, Main.screenWidth + 40, Main.screenHeight + 40); + if (screenBounds.Contains(basePosition.ToPoint())) { - var tex = GeneralParticleHandler.GetTexture(GeneralParticleHandler.particleIDsByTypes[typeof(BloomParticle)]); - var len = Math.Min(Projectile.oldPos.Length, 32); - for (var i = 0; i < len; i++) + List path = []; + for (var i = 0; i < Projectile.oldPos.Length; i++) { - Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); - Color color = M.FireColorFunction(i / (float)len, Projectile.oldPos[i]); - var color2 = ProvUtils.GetProjectileColor(255, true); - float width = M.FireWidthFunction(i / (float)len, Projectile.oldPos[i]); - Main.spriteBatch.Draw(tex, drawPos, null, (color2 with { A = 0 }) * (1 - i / (float)len), 0f, tex.Size() * 0.5f, new Vector2(width) / tex.Width, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(tex, drawPos, null, (color with { A = 0 }) * (1 - i / (float)len), 0f, tex.Size() * 0.5f, new Vector2(width) / tex.Width * 0.25f, SpriteEffects.None, 0f); + Vector2 trailDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition; + path.Add(new Vector3(trailDrawPosition.X, trailDrawPosition.Y, 0f)); + } + + if (path.Count > 2 && Projectile.ai[0] > 6) + { + Effect shader = CalamityShaders.ProvidenceHolyOrbTrailShader.Value; + shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + shader.Parameters["glowPower"].SetValue(1.48f); + + Main.graphics.GraphicsDevice.Textures[0] = TrailNoiseTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; + Main.graphics.GraphicsDevice.Textures[1] = TrailDistortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; + + using var shaderScope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, Matrix.Identity, projection); + using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true); + shaderScope.Draw(trailMesh.View); } } } - void DrawBurnOrb(Projectile Projectile) + + public override bool PreDraw(ref Color lightColor) { - float lerpMult = MathHelper.Lerp(0.5f, 1.5f, Math.Abs(MathF.Sin(Projectile.localAI[1] / 10f))); - - Texture2D texture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; - Vector2 drawPos = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); - Color baseColor = ProvUtils.GetProjectileColor(255, true) * 4; - Color baseColor2 = ProvUtils.GetProjectileColor(255); - baseColor.A = 0; - baseColor *= lerpMult; - baseColor2 *= lerpMult; - Vector2 origin = texture.Size() / 2f; - Vector2 scale = new Vector2(0.5f, 1f) * ((lerpMult - 1) * 0.5f + 1f); - - SpriteEffects spriteEffects = SpriteEffects.None; - if (Projectile.spriteDirection == -1) - spriteEffects = SpriteEffects.FlipHorizontally; - - Projectile.rotation += MathHelper.ToRadians(lerpMult * 2f); - - float upRight = MathHelper.PiOver4; - float up = MathHelper.PiOver2; - float upLeft = 3f * MathHelper.PiOver4; - float left = MathHelper.Pi; - Main.EntitySpriteDraw(texture, drawPos, null, baseColor, upLeft + Projectile.rotation, origin, scale, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor, upRight - Projectile.rotation, origin, scale, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, upLeft + Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, upRight - Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor, up + Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor, left - Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, up + Projectile.rotation, origin, scale * 0.36f, spriteEffects, 0); - Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, left - Projectile.rotation, origin, scale * 0.36f, spriteEffects, 0); + // Trail drawn by the HolyBurnOrbDrawer system. + DrawBurnOrb(); + DrawBurnOrbAdditive(); + return false; } - void DrawBurnOrbAdditive(Projectile Projectile) + private void DrawBurnOrb() { - var texture = ModContent.Request("CalamityMod/Particles/GlowOrbParticle").Value; - Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, ProvUtils.GetProjectileColor(255), 0, texture.Size() * 0.5f, 1f, 0, 0f); - Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, Color.White, 0, texture.Size() * 0.5f, 0.5f, 0, 0f); - } - void DrawHealOrbTrail(Projectile Projectile) - { - if (Projectile.ModProjectile is HolyLight M) - { - var tex = GeneralParticleHandler.GetTexture(GeneralParticleHandler.particleIDsByTypes[typeof(BloomParticle)]); - var len = Math.Min(Projectile.oldPos.Length, 32); - for (var i = 0; i < len; i++) - { - Vector2 drawPos = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); - Color color = M.FireCoreColorFunction(i / (float)len, Projectile.oldPos[i]); - var color2 = new Color(0, 25, 0); - float width = M.FireWidthFunction(i / (float)len, Projectile.oldPos[i]); - Main.spriteBatch.Draw(tex, drawPos, null, (color2 with { A = 0 }) * (1 - i / (float)len), 0f, tex.Size() * 0.5f, new Vector2(width) / tex.Width, SpriteEffects.None, 0f); - Main.spriteBatch.Draw(tex, drawPos, null, (color with { A = 0 }) * (1 - i / (float)len), 0f, tex.Size() * 0.5f, new Vector2(width) / tex.Width * 0.25f, SpriteEffects.None, 0f); - } - } - } - void DrawHealOrb(Projectile Projectile) - { - float vel = Projectile.velocity.Length() / 8; - Projectile.localAI[1] += vel; + float lerpMult = MathHelper.Lerp(0.5f, 1.5f, Math.Abs(MathF.Sin(Projectile.localAI[1] / 10f))); - Texture2D drawTexture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; - Color brightGreen = new Color(54, 209, 54, 0); - Vector2 projDirection = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); - Vector2 halfTextureSize = drawTexture.Size() / 2f; - Color halfBrightGreen = brightGreen * 0.5f; - float timeLeftColorScale = MathHelper.Lerp(0.5f, 1.5f, Math.Abs(MathF.Sin(Projectile.localAI[1] / 10f))); - Projectile.rotation += MathHelper.ToRadians(timeLeftColorScale * 2f); - Vector2 timeLeftDrawEffect = new Vector2(0.5f, 1f) * timeLeftColorScale; - Vector2 timeLeftDrawEffect2 = new Vector2(0.5f, 1f) * timeLeftColorScale; - brightGreen *= timeLeftColorScale; - halfBrightGreen *= timeLeftColorScale; - - Vector2 position3 = projDirection + Projectile.velocity.SafeNormalize(Vector2.Zero) * Utils.GetLerpValue(0.5f, 1f, Projectile.localAI[0] / 60f, clamped: true) * 0; + Texture2D texture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; + Vector2 drawPos = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + Color baseColor = ProvUtils.GetProjectileColor(255, true) * 4; + Color baseColor2 = ProvUtils.GetProjectileColor(255); + baseColor.A = 0; + baseColor *= lerpMult; + baseColor2 *= lerpMult; + Vector2 origin = texture.Size() * 0.5f; + Vector2 scale = new Vector2(0.5f, 1f) * ((lerpMult - 1) * 0.5f + 1f); SpriteEffects spriteEffects = SpriteEffects.None; if (Projectile.spriteDirection == -1) spriteEffects = SpriteEffects.FlipHorizontally; - Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); + Projectile.rotation += MathHelper.ToRadians(lerpMult * 2f); - Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.36f, spriteEffects, 0); - Main.EntitySpriteDraw(drawTexture, position3, null, halfBrightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.36f, spriteEffects, 0); + float upRight = MathHelper.PiOver4; + float up = MathHelper.PiOver2; + float upLeft = 3f * MathHelper.PiOver4; + float left = MathHelper.Pi; + Main.EntitySpriteDraw(texture, drawPos, null, baseColor, upLeft + Projectile.rotation, origin, scale, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor, upRight - Projectile.rotation, origin, scale, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, upLeft + Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, upRight - Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor, up + Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor, left - Projectile.rotation, origin, scale * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, up + Projectile.rotation, origin, scale * 0.36f, spriteEffects, 0); + Main.EntitySpriteDraw(texture, drawPos, null, baseColor2, left - Projectile.rotation, origin, scale * 0.36f, spriteEffects, 0); } - void DrawHealOrbAdditive(Projectile Projectile) + private void DrawBurnOrbAdditive() { - var texture = ModContent.Request("CalamityMod/Particles/GlowOrbParticle").Value; - Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, new Color(54, 209, 54), 0, texture.Size() * 0.5f, 1f, 0, 0f); - Main.spriteBatch.Draw(texture, Projectile.Center - Main.screenPosition, null, Color.White, 0, texture.Size() * 0.5f, 0.5f, 0, 0f); + Main.EntitySpriteDraw(GlowOrbTexture.Value, Projectile.Center - Main.screenPosition, null, ProvUtils.GetProjectileColor(255) with { A = 0 }, 0, GlowOrbTexture.Size() * 0.5f, 1f, 0, 0f); + Main.EntitySpriteDraw(GlowOrbTexture.Value, Projectile.Center - Main.screenPosition, null, Color.White with { A = 0 }, 0, GlowOrbTexture.Size() * 0.5f, 0.5f, 0, 0f); + } + } + + public class HolyBurnOrbDrawer : ModSystem + { + public static RenderTargetLease TrailPixelationLease { get; private set; } + + private List HolyBurnOrbs = []; + private List HolyLights = []; + + public override void Load() + { + GeneralDrawLayerSystem.OnBeforeProjectiles += DrawOrbTrails; + if (!Main.dedServ) + { + Main.QueueMainThreadAction(() => TrailPixelationLease = ScreenspaceTargetPool.Shared.Rent(Main.instance.GraphicsDevice, (w, h) => (w / 2, h / 2))); + } + } + + public override void PostUpdateProjectiles() + { + foreach (var item in Main.ActiveProjectiles) + { + if (item.type == ModContent.ProjectileType() && !HolyBurnOrbs.Contains(item)) + HolyBurnOrbs.Add(item); + if (item.type == ModContent.ProjectileType() && !HolyLights.Contains(item)) + HolyLights.Add(item); + } + + HolyBurnOrbs.RemoveAll(p => !p.active || p.timeLeft <= 1); + HolyLights.RemoveAll(p => !p.active || p.timeLeft <= 1); + } + + private void DrawOrbTrails() + { + if ((HolyBurnOrbs.Count + HolyLights.Count) > 0) + { + using (Main.spriteBatch.Scope()) + { + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + using (TrailPixelationLease.Scope(clearColor: Color.Transparent)) + { + foreach (var item in HolyBurnOrbs) + item.ModProjectile().DrawTrail(); + + foreach (var item in HolyLights) + item.ModProjectile().DrawTrail(); + } + + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); + + // Redraw at double scale to pixelate the trails. + Main.spriteBatch.Draw(TrailPixelationLease.Target, Vector2.Zero, null, Color.White with { A = 0 }, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); + + Main.spriteBatch.End(); + } + } } } } diff --git a/Projectiles/Boss/HolyLight.cs b/Projectiles/Boss/HolyLight.cs index 71fcbfaa70..54fc96cc2d 100644 --- a/Projectiles/Boss/HolyLight.cs +++ b/Projectiles/Boss/HolyLight.cs @@ -1,13 +1,13 @@ using System; -using System.Linq; +using System.Collections.Generic; using CalamityMod.Dusts; +using CalamityMod.Effects; using CalamityMod.Enums; -using CalamityMod.NPCs.Providence; +using CalamityMod.Graphics.Primitives; using CalamityMod.Particles; -using CalamityMod.Utilities.Daybreak; -using CalamityMod.Utilities.Daybreak.Buffers; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.DataStructures; @@ -18,13 +18,29 @@ namespace CalamityMod.Projectiles.Boss { public class HolyLight : ModProjectile, ILocalizedModType { + private static Asset TrailNoiseTexture; + private static Asset TrailDistortionTexture; + private static Asset GlowOrbTexture; + public new string LocalizationCategory => "Projectiles.Boss"; public override string Texture => "CalamityMod/Projectiles/StarProj"; + + public override void Load() + { + if (!Main.dedServ) + { + TrailNoiseTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/EternityStreak"); + TrailDistortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/HarshNoise"); + GlowOrbTexture = ModContent.Request("CalamityMod/Particles/GlowOrbParticle"); + } + } + public override void SetStaticDefaults() { - ProjectileID.Sets.TrailCacheLength[Type] = 32; - ProjectileID.Sets.TrailingMode[Type] = 2; + ProjectileID.Sets.TrailCacheLength[Type] = 16; + ProjectileID.Sets.TrailingMode[Type] = 0; } + public override void SetDefaults() { Projectile.localAI[1] = Main.rand.NextFloat(30f); @@ -85,60 +101,6 @@ namespace CalamityMod.Projectiles.Boss } } - public override bool PreDraw(ref Color lightColor) - { - //drawn by the HolyBurnOrbDrawer system - return false; - } - public float FireWidthFunction(float completion, Vector2 pos) - { - float width; - float maxBodyWidth = 32f * Projectile.scale; - float curveRatio = 0.2f; - var positions = Projectile.oldPos.ToList(); - positions.RemoveAll(x => x == Vector2.Zero); - // Crop the tip of the trail into a conic shape. - if (completion < curveRatio) - width = MathF.Pow(completion / curveRatio, 0.5f) * maxBodyWidth; - else - width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); - - // Pulse inwards and outwards over time. - float pulseInterpolant = MathF.Cos(MathHelper.Pi * completion - Main.GlobalTimeWrappedHourly * 20f) * 0.5f + 0.5f; - float additionalPulseWidth = MathHelper.Lerp(0f, 12f, pulseInterpolant); - return (width + additionalPulseWidth) * positions.Count() / (float)ProjectileID.Sets.TrailCacheLength[Type]; - } - - public Color FireColorFunction(float completion, Vector2 pos) - { - Color mainColor = new Color(54, 209, 54) * 1.3f; - Color endColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); - return Color.Lerp(mainColor, endColor, completion) * Projectile.Opacity; - } - - public float FireCoreWidthFunction(float completion, Vector2 pos) - { - float width; - float maxBodyWidth = Projectile.scale * 24; - float curveRatio = 0.25f; - var positions = Projectile.oldPos.ToList(); - positions.RemoveAll(x => x == Vector2.Zero); - - if (completion < curveRatio) - width = MathF.Sin(completion / curveRatio * MathHelper.PiOver2) * maxBodyWidth + curveRatio; - else - width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); - return width * positions.Count() / (float)ProjectileID.Sets.TrailCacheLength[Type]; - } - - public Color FireCoreColorFunction(float completion, Vector2 pos) - { - Color mainColor = new Color(54, 209, 54); - Color tipColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); - Color fullBodyColor = Color.Lerp(mainColor, tipColor, completion); - return Color.Lerp(fullBodyColor, Color.White, 0.175f) * Projectile.Opacity; - } - public override void OnKill(int timeLeft) { SoundEngine.PlaySound(SoundID.Item14 with { Pitch = -0.3f, Volume = 0.7f }, Projectile.Center); @@ -162,5 +124,110 @@ namespace CalamityMod.Projectiles.Boss dust.noLightEmittence = true; } } + + public float FireWidthFunction(float completion) + { + float width; + float maxBodyWidth = 56f * Projectile.scale; + float curveRatio = 0.2f; + + // Crop the tip of the trail into a conic shape. + if (completion < curveRatio) + width = MathF.Pow(completion / curveRatio, 0.5f) * maxBodyWidth; + else + width = Utils.Remap(completion, curveRatio, 1f, maxBodyWidth, 0f); + + // Pulse inwards and outwards over time. + float pulseInterpolant = MathF.Cos(MathHelper.Pi * completion - Main.GlobalTimeWrappedHourly * 20f) * 0.5f + 0.5f; + float additionalPulseWidth = MathHelper.Lerp(0f, 12f, pulseInterpolant); + return (width + additionalPulseWidth); + } + + public Color FireColorFunction(float completion) + { + Color mainColor = new Color(54, 209, 54) * 1.3f; + Color endColor = Color.Lerp(mainColor, Color.Transparent, Utils.GetLerpValue(0.8f, 1f, completion, true)); + return Color.Lerp(mainColor, endColor, completion) * Projectile.Opacity; + } + + public void DrawTrail() + { + Matrix projection = Matrix.CreateOrthographicOffCenter(0, Main.screenWidth, Main.screenHeight, 0, -200f, 200f); + Vector2 basePosition = Projectile.Center - Main.screenPosition; + Rectangle screenBounds = new Rectangle(-40, -40, Main.screenWidth + 40, Main.screenHeight + 40); + if (screenBounds.Contains(basePosition.ToPoint())) + { + List path = []; + for (var i = 0; i < Projectile.oldPos.Length; i++) + { + Vector2 trailDrawPosition = Projectile.oldPos[i] + Projectile.Size * 0.5f - Main.screenPosition; + path.Add(new Vector3(trailDrawPosition.X, trailDrawPosition.Y, 0f)); + } + + if (path.Count > 2 && Projectile.ai[0] > 6) + { + Effect shader = CalamityShaders.ProvidenceHolyOrbTrailShader.Value; + shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + shader.Parameters["glowPower"].SetValue(1.48f); + + Main.graphics.GraphicsDevice.Textures[0] = TrailNoiseTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap; + Main.graphics.GraphicsDevice.Textures[1] = TrailDistortionTexture.Value; + Main.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearWrap; + + using var shaderScope = SanePrimitiveRenderer.BeginShaderScope(shader, Matrix.Identity, Matrix.Identity, projection); + using var trailMesh = TriangleStripBuilder.BuildStripPooled(path, progress => FireWidthFunction(progress), progress => FireColorFunction(progress), PrimitiveMeshCache.Shared, textured: true); + shaderScope.Draw(trailMesh.View); + } + } + } + + public override bool PreDraw(ref Color lightColor) + { + // Trail drawn by the HolyBurnOrbDrawer system. + DrawHealOrb(); + DrawHealOrbAdditive(); + return false; + } + + private void DrawHealOrb() + { + float vel = Projectile.velocity.Length() / 8; + Projectile.localAI[1] += vel; + + Texture2D drawTexture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; + Color brightGreen = new Color(54, 209, 54, 0); + Vector2 projDirection = Projectile.Center - Main.screenPosition + new Vector2(0f, Projectile.gfxOffY); + Vector2 halfTextureSize = drawTexture.Size() / 2f; + Color halfBrightGreen = brightGreen * 0.5f; + float timeLeftColorScale = MathHelper.Lerp(0.5f, 1.5f, Math.Abs(MathF.Sin(Projectile.localAI[1] / 10f))); + Projectile.rotation += MathHelper.ToRadians(timeLeftColorScale * 2f); + Vector2 timeLeftDrawEffect = new Vector2(0.5f, 1f) * timeLeftColorScale; + Vector2 timeLeftDrawEffect2 = new Vector2(0.5f, 1f) * timeLeftColorScale; + brightGreen *= timeLeftColorScale; + halfBrightGreen *= timeLeftColorScale; + + Vector2 position3 = projDirection + Projectile.velocity.SafeNormalize(Vector2.Zero) * Utils.GetLerpValue(0.5f, 1f, Projectile.localAI[0] / 60f, clamped: true) * 0; + + SpriteEffects spriteEffects = SpriteEffects.None; + if (Projectile.spriteDirection == -1) + spriteEffects = SpriteEffects.FlipHorizontally; + + Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3, null, brightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3 + Vector2.UnitX * 60f, null, halfBrightGreen, MathHelper.PiOver2 - Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3 + Vector2.UnitX * 60f, null, halfBrightGreen, 0f - Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); + + Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitX * 60f, null, brightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitX * 60f, null, brightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.6f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitY * 60f, null, halfBrightGreen, MathHelper.PiOver4 + Projectile.rotation, halfTextureSize, timeLeftDrawEffect * 0.36f, spriteEffects, 0); + Main.EntitySpriteDraw(drawTexture, position3 - Vector2.UnitY * 60f, null, halfBrightGreen, MathHelper.PiOver4 * 3f + Projectile.rotation, halfTextureSize, timeLeftDrawEffect2 * 0.36f, spriteEffects, 0); + } + + private void DrawHealOrbAdditive() + { + Main.spriteBatch.Draw(GlowOrbTexture.Value, Projectile.Center - Main.screenPosition, null, new Color(54, 209, 54) with { A = 0 }, 0, GlowOrbTexture.Size() * 0.5f, 1f, 0, 0f); + Main.spriteBatch.Draw(GlowOrbTexture.Value, Projectile.Center - Main.screenPosition, null, Color.White with { A = 0 }, 0, GlowOrbTexture.Size() * 0.5f, 0.5f, 0, 0f); + } } }