From f09b23a8a46de1d6258b5fef1032a0190e23ec79 Mon Sep 17 00:00:00 2001 From: Mishiro Usui Date: Tue, 3 Oct 2023 14:26:37 +0100 Subject: [PATCH] Fixes and adjustments to oathsword drawing --- Effects/CalamityShaders.cs | 2 +- Projectiles/Melee/BladecrestOathswordProj.cs | 49 +++++++++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 11ea63dea7..9e1b193488 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -387,7 +387,7 @@ namespace CalamityMod.Effects #region Loading Amber's Shaders PrimitiveClearShader = LoadShader("PrimitiveClearShader"); - RegisterScreenShader(PrimitiveClearShader, "SightLinePass", "PrimitiveClearShader"); + RegisterScreenShader(PrimitiveClearShader, "AutoloadPass", "PrimitiveClearShader"); #endregion } } diff --git a/Projectiles/Melee/BladecrestOathswordProj.cs b/Projectiles/Melee/BladecrestOathswordProj.cs index 4e0b5e15f9..95a066dcd5 100644 --- a/Projectiles/Melee/BladecrestOathswordProj.cs +++ b/Projectiles/Melee/BladecrestOathswordProj.cs @@ -3,6 +3,7 @@ using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; using System; using System.IO; +using CalamityMod.Effects; using Terraria; using Terraria.Graphics.Effects; using Terraria.Graphics.Shaders; @@ -76,10 +77,17 @@ namespace CalamityMod.Projectiles.Melee DecideCurrentState(); Direction = Owner.direction; + + //Set the owner's arm to rotate with the blade + if (Owner.itemAnimation > 0) + { + float armPointingDirection = Projectile.rotation + MathHelper.ToRadians(240); + Owner.SetCompositeArmFront(true, Player.CompositeArmStretchAmount.Full, armPointingDirection); + } // Glue the sword to its owner. Projectile.Opacity = 1f; - Projectile.position = Owner.RotatedRelativePoint(Owner.MountedCenter, true) - Projectile.Size / 2f + Vector2.UnitY * Owner.gfxOffY; + Projectile.position = Owner.RotatedRelativePoint(Owner.MountedCenter, true) - Projectile.Size * 0.5f + Vector2.UnitY * Owner.gfxOffY; float swingSpeedInterpolant = 0.27f; float swingCompletion = 1f - Owner.itemAnimation / (float)Owner.itemAnimationMax; @@ -105,7 +113,7 @@ namespace CalamityMod.Projectiles.Melee Projectile.Opacity = 0f; // Determine the horizontal stretch offset of the blade. This is used in matrix math below to create 2.5D visuals. - BladeHorizontalFactor = MathHelper.Lerp(1f, 1.5f, (aimDirection3D.X * 0.5f + 0.5f) * Utils.GetLerpValue(1f, 0.8f, unchangedSwingCompletion, true)); + BladeHorizontalFactor = MathHelper.Lerp(1f, 1.25f, (aimDirection3D.X * 0.5f + 0.5f) * Utils.GetLerpValue(1f, 0.8f, unchangedSwingCompletion, true)); float baseRotation = new Vector2(aimDirection3D.X, aimDirection3D.Y).ToRotation(); @@ -128,9 +136,8 @@ namespace CalamityMod.Projectiles.Melee Projectile.rotation = Projectile.rotation.AngleTowards(idealRotation, swingSpeedInterpolant * 0.45f).AngleLerp(idealRotation, swingSpeedInterpolant * 0.2f); // Offset the blade so that the handle is attached to the owner's hand. - float horizontalBladeOffset = MathHelper.Lerp(-4f, 10f, Utils.GetLerpValue(1f, 0.72f, unchangedSwingCompletion, true) * Utils.GetLerpValue(0f, 0.28f, unchangedSwingCompletion, true)); - Vector2 bladeOffset = (Projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * Projectile.width * 0.5f; - bladeOffset += new Vector2(Direction * horizontalBladeOffset, 2f).RotatedBy(Owner.fullRotation) + Vector2.UnitY * Owner.gfxOffY; + Vector2 bladeOffset = (Projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * Projectile.width * 0.65f; + bladeOffset += Vector2.UnitY * Owner.gfxOffY; Projectile.position += bladeOffset; // Create demon magic dust along the blade when swinging, as well as demon blood scythes. @@ -151,7 +158,7 @@ namespace CalamityMod.Projectiles.Melee Vector2 bloodScytheShootVelocity = (Projectile.rotation - MathHelper.PiOver4).ToRotationVector2(); bloodScytheShootVelocity.Y *= 0.04f; bloodScytheShootVelocity = bloodScytheShootVelocity.SafeNormalize(Vector2.UnitY) * 50f; - Vector2 bloodScytheSpawnPosition = Projectile.Center + bloodScytheShootVelocity.SafeNormalize(Vector2.UnitY) * 50f; + Vector2 bloodScytheSpawnPosition = Projectile.Center + bloodScytheShootVelocity.SafeNormalize(Vector2.UnitY) * 35f; Projectile.NewProjectile(Projectile.GetSource_FromThis(), bloodScytheSpawnPosition, bloodScytheShootVelocity, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack * 0.4f, Projectile.owner); } } @@ -179,6 +186,36 @@ namespace CalamityMod.Projectiles.Melee CurrentState = SwingState.Default; } } + + public override bool PreDraw(ref Color lightColor) + { + Main.spriteBatch.EnterShaderRegion(); + + CalamityUtils.CalculatePerspectiveMatricies(out Matrix viewMatrix, out Matrix projectionMatrix); + + GameShaders.Misc["CalamityMod:LinearTransformation"].UseColor(Main.hslToRgb(0.95f, 0.85f, 0.5f)); + GameShaders.Misc["CalamityMod:LinearTransformation"].UseOpacity(0f); + GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["uWorldViewProjection"].SetValue(viewMatrix * projectionMatrix); + GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["localMatrix"].SetValue(new Matrix() + { + M11 = BladeHorizontalFactor, + M12 = 0f, + M21 = 0f, + M22 = 1f, + }); + GameShaders.Misc["CalamityMod:LinearTransformation"].Apply(); + + CalamityUtils.DrawAfterimagesCentered(Projectile, 2, lightColor); + + Main.spriteBatch.ExitShaderRegion(); + + CalamityUtils.CalculatePerspectiveMatricies(out var view, out var proj); + CalamityShaders.PrimitiveClearShader.Parameters["uWorldViewProjection"].SetValue(view * proj); + CalamityShaders.PrimitiveClearShader.CurrentTechnique.Passes[0].Apply(); + Filters.Scene["CalamityMod:PrimitiveClearShader"].GetShader().Shader.CurrentTechnique.Passes[0].Apply(); + + return false; + } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) {