diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 9e1b193488..83114d8232 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -176,6 +176,7 @@ namespace CalamityMod.Effects #region Aqua's Shaders internal static Effect CircularGradientWithEdge; + internal static Effect WavyOpacity; #endregion // @@ -383,8 +384,10 @@ namespace CalamityMod.Effects #region Loading Aqua's Shaders CircularGradientWithEdge = LoadShader("CircularGradientWithEdge"); RegisterMiscShader(CircularGradientWithEdge, "CircularGradientWithEdgePass", "CircularGradientWithEdge"); + WavyOpacity = LoadShader("WavyOpacity"); + RegisterMiscShader(WavyOpacity, "WavyOpacityPass", "WavyOpacity"); #endregion - + #region Loading Amber's Shaders PrimitiveClearShader = LoadShader("PrimitiveClearShader"); RegisterScreenShader(PrimitiveClearShader, "AutoloadPass", "PrimitiveClearShader"); diff --git a/Effects/WavyOpacity.fx b/Effects/WavyOpacity.fx new file mode 100644 index 0000000000..fe08fcc4c6 --- /dev/null +++ b/Effects/WavyOpacity.fx @@ -0,0 +1,74 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity : register(C0); +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +float4 uShaderSpecificData; + +// Cosine does not work in shaders in Terraria 1.4. It returns incredibly corrupted values and nobody is sure why. +// This reimplements cosine using trigonometric identities. +// +// Discovery of malfunctioning cosine attributed to ScalarVector from SLR: +// https://discord.com/channels/103110554649894912/445276626352209920/979928448300634175 +float realCos(float value) +{ + return sin(value + 1.57079); +} + +//Shader overall based on Ozzatron's miracle blight shader. slightly edited for a different use case. +float4 PixelShaderFunction(float2 coords : TEXCOORD0) : COLOR0 +{ + float4 color = tex2D(uImage0, coords); + if (!any(color)) + return color; + + // Framed coordinates -- a UV of the Projectile's current framed sprite, instead of the whole sheet + float2 framedCoords = (coords * uImageSize0 - uSourceRect.xy) / uSourceRect.zw; + + // Temporal drift to make the sprite slide through the noise texture + float2 drift = float2(5 * sin(4 * uTime), 220 * -uTime); + + float2 noiseMapTexCoords = framedCoords * uSourceRect.zw + drift; + float4 noiseColor = tex2D(uImage1, noiseMapTexCoords / uImageSize1); + + // Define thresholds for total pixel erasure and glowing lines. + // + // Rapidly flickering sinewave produced by Desmos, loosely based on the Weierstrass function + // (infinitely sharp vague sinewave, periodic, continuous everywhere but differentiable nowhere) + // https://en.wikipedia.org/wiki/Weierstrass_function + float flickerOne = 0.05 * realCos(7 * uTime); + float flickerTwo = 0.06 * realCos(31 * uTime); + float flickerThree = 0.04 * sin(167 * uTime); + float fullErasureThreshold = uOpacity + flickerOne + flickerTwo + flickerThree; + float glowThreshold = fullErasureThreshold - 0.3; + + // If the noise over the erasure threshold, completely erase this pixel. + if (noiseColor.r > fullErasureThreshold) + { + color.rgba = 0; + } + // Otherwise, if it's over the slightly lower threshold, change the opacity relative to how close it was to erasure + else if (noiseColor.r > glowThreshold) + { + color.rgba = color.rgba * (1 - ((noiseColor.r - glowThreshold) / (fullErasureThreshold - glowThreshold))); + } + + return color; +} + +technique Technique1 +{ + pass WavyOpacityPass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/WavyOpacity.xnb b/Effects/WavyOpacity.xnb new file mode 100644 index 0000000000..fa908885e8 Binary files /dev/null and b/Effects/WavyOpacity.xnb differ diff --git a/Items/Weapons/Summon/AquasScepter.cs b/Items/Weapons/Summon/AquasScepter.cs index 5d3ab670b2..3e8f4c70d8 100644 --- a/Items/Weapons/Summon/AquasScepter.cs +++ b/Items/Weapons/Summon/AquasScepter.cs @@ -25,8 +25,8 @@ namespace CalamityMod.Items.Weapons.Summon Item.mana = 50; Item.DamageType = DamageClass.Summon; Item.sentry = true; - Item.width = 48; - Item.height = 48; + Item.width = 56; + Item.height = 56; Item.useTime = 30; Item.useAnimation = 30; Item.useStyle = 1; diff --git a/Items/Weapons/Summon/AquasScepter.png b/Items/Weapons/Summon/AquasScepter.png index 8c62607bb7..5cf53f4288 100644 Binary files a/Items/Weapons/Summon/AquasScepter.png and b/Items/Weapons/Summon/AquasScepter.png differ diff --git a/Projectiles/Summon/AquasScepterCloud.cs b/Projectiles/Summon/AquasScepterCloud.cs index 02950e2294..29558b9a37 100644 --- a/Projectiles/Summon/AquasScepterCloud.cs +++ b/Projectiles/Summon/AquasScepterCloud.cs @@ -3,6 +3,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.Graphics.Shaders; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Summon @@ -10,20 +13,16 @@ namespace CalamityMod.Projectiles.Summon public class AquasScepterCloud : ModProjectile, ILocalizedModType { public new string LocalizationCategory => "Projectiles.Summon"; + Texture2D flashTex = ModContent.Request("CalamityMod/Projectiles/Summon/AquasScepterCloudFlash").Value; + Texture2D glowTex = ModContent.Request("CalamityMod/Projectiles/Summon/AquasScepterCloudGlowmask").Value; public ref float LightningTimer => ref Projectile.ai[0]; public ref float RainTimer => ref Projectile.ai[1]; public int DrawFlashTimer = 0; - public override void SetStaticDefaults() - { - // Sets the amount of frames this minion has on its spritesheet - Main.projFrames[Projectile.type] = 5; - } - public sealed override void SetDefaults() { - Projectile.width = 252; - Projectile.height = 78; + Projectile.width = 238; + Projectile.height = 98; Projectile.hide = true; Projectile.tileCollide = false; Projectile.timeLeft = Projectile.SentryLifeTime; @@ -31,7 +30,6 @@ namespace CalamityMod.Projectiles.Summon Projectile.sentry = true; Projectile.DamageType = DamageClass.Summon; Projectile.penetrate = -1; - Projectile.light = 1f; } public override void DrawBehind(int index, List behindNPCsAndTiles, List behindNPCs, List behindProjectiles, List overPlayers, List overWiresUI) @@ -41,12 +39,7 @@ namespace CalamityMod.Projectiles.Summon } public override bool? CanDamage() => false; - - public override Color? GetAlpha(Color drawColor) - { - return Color.White; - } - + public override Color? GetAlpha(Color lightColor) => Color.White; public override void AI() { float distanceFromTarget = 700f; @@ -56,18 +49,9 @@ namespace CalamityMod.Projectiles.Summon LightningTimer++; RainTimer++; - Projectile.frameCounter++; - if (Projectile.frameCounter >= 6) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - Projectile.frame = 0; - if (RainTimer >= 3f) // Spawns a raindrop every 3 frames, displaced down and randomly along the length of the cloud { - Projectile.NewProjectile(Projectile.GetSource_FromThis(), (Projectile.Center.X + Main.rand.Next(-110, 111)), (Projectile.Center.Y + 57f), 0f, 15f, ModContent.ProjectileType(), Projectile.damage, 0, Projectile.owner); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), (Projectile.Center.X + Main.rand.Next(-100, 101)), (Projectile.Bottom.Y + 24f), 0f, 15f, ModContent.ProjectileType(), Projectile.damage, 0, Projectile.owner); RainTimer = 0f; } @@ -97,8 +81,8 @@ namespace CalamityMod.Projectiles.Summon { if (LightningTimer >= 60f) //Every 60 AI cycles, plays the lightning sound and spawns 2 projectiles: the tesla aura for dealing damage in an aoe, and the cloud flash to simulate the brightness of the main cloud changing. { - SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Item/LightningAura")); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Center.Y, 0f, 0f, ModContent.ProjectileType(), (int)(Projectile.damage * 7.2f), 16, Projectile.owner); + SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Item/LightningAura"), Projectile.Center); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center.X, Projectile.Bottom.Y, 0f, 0f, ModContent.ProjectileType(), (int)(Projectile.damage * 7.2f), 16, Projectile.owner); LightningTimer = 0f; DrawFlashTimer = 27; } @@ -107,12 +91,36 @@ namespace CalamityMod.Projectiles.Summon } public override void PostDraw(Color lightColor) { - if (DrawFlashTimer > 0) + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.GameViewMatrix.ZoomMatrix); + + MiscShaderData msd = GameShaders.Misc["CalamityMod:WavyOpacity"]; + msd.SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/BlobbyNoise"), 1); + msd.UseOpacity(0.7f); + DrawData dd = new() { - Texture2D texture = ModContent.Request("CalamityMod/Projectiles/Summon/AquasScepterCloudFlash").Value; - lightColor *= 1f - ((27 - DrawFlashTimer) / 27f); - Vector2 drawPosition = Projectile.position - Main.screenPosition + (texture.Size() * 0.5f); - Main.EntitySpriteDraw(texture, drawPosition, null, lightColor, 0f, texture.Size() * 0.5f, 1f, SpriteEffects.None); + texture = glowTex, + position = Projectile.position - Main.screenPosition, + sourceRect = glowTex.Bounds, + }; + msd.Apply(dd); + Vector2 glowPos = Projectile.position - Main.screenPosition + (glowTex.Size() * 0.5f); + Main.EntitySpriteDraw(glowTex, glowPos, null, dd.color, 0f, glowTex.Size() * 0.5f, 1f, SpriteEffects.None); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(); + + if (Main.rand.NextBool(240)) + { + DrawFlashTimer += Main.rand.Next(15, 23); + if (DrawFlashTimer > 27) + DrawFlashTimer = 27; + } + + if (DrawFlashTimer > 0) + { + float opacity = 1f - ((27 - DrawFlashTimer) / 27f); + Vector2 drawPosition = Projectile.position - Main.screenPosition + (flashTex.Size() * 0.5f); + Main.EntitySpriteDraw(flashTex, drawPosition, null, Color.White * opacity, 0f, flashTex.Size() * 0.5f, 1f, SpriteEffects.None); DrawFlashTimer--; } } diff --git a/Projectiles/Summon/AquasScepterCloud.png b/Projectiles/Summon/AquasScepterCloud.png index f51a5db6ae..6c8b2b1a41 100644 Binary files a/Projectiles/Summon/AquasScepterCloud.png and b/Projectiles/Summon/AquasScepterCloud.png differ diff --git a/Projectiles/Summon/AquasScepterCloudFlash.png b/Projectiles/Summon/AquasScepterCloudFlash.png index d2deca9c47..00e6bdf029 100644 Binary files a/Projectiles/Summon/AquasScepterCloudFlash.png and b/Projectiles/Summon/AquasScepterCloudFlash.png differ diff --git a/Projectiles/Summon/AquasScepterCloudGlowmask.png b/Projectiles/Summon/AquasScepterCloudGlowmask.png new file mode 100644 index 0000000000..9158e5829e Binary files /dev/null and b/Projectiles/Summon/AquasScepterCloudGlowmask.png differ diff --git a/Projectiles/Summon/AquasScepterRaindrop.png b/Projectiles/Summon/AquasScepterRaindrop.png index 78df290d74..6979f00d85 100644 Binary files a/Projectiles/Summon/AquasScepterRaindrop.png and b/Projectiles/Summon/AquasScepterRaindrop.png differ diff --git a/Projectiles/Summon/AquasScepterTeslaAura.cs b/Projectiles/Summon/AquasScepterTeslaAura.cs index cf376ff9b3..5892dc33aa 100644 --- a/Projectiles/Summon/AquasScepterTeslaAura.cs +++ b/Projectiles/Summon/AquasScepterTeslaAura.cs @@ -29,9 +29,11 @@ namespace CalamityMod.Projectiles.Summon Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 28; Projectile.alpha = 0; + Projectile.spriteDirection = Main.rand.NextBool() ? -1 : 1; } public override bool? CanDamage() => ableToHit ? (bool?)null : false; + public override Color? GetAlpha(Color lightColor) => Color.White * (1 - (Projectile.alpha / 255f)); public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) => CalamityUtils.CircularHitboxCollision(Projectile.Center, (TeslaAuraScale * 96.0f), targetHitbox); @@ -46,13 +48,7 @@ namespace CalamityMod.Projectiles.Summon Projectile.ai[0]++; Projectile.frameCounter++; - if (Projectile.frameCounter >= 4) - { - Projectile.frame++; - Projectile.frameCounter = 0; - } - if (Projectile.frame >= Main.projFrames[Projectile.type]) - Projectile.frame = 0; + Projectile.frame = (int)(Projectile.frameCounter / 5.4f); if (Projectile.ai[0] > 8f) //After the Tesla Aura has been alive for 8 frames, disables it's ability to deal damage. This is done so that there is some leniency on allowing new enemies to enter the damaging range for a bit to make the sentry feel better to use. {