From 368f5fcfae54db2cba9e263203381f2bd8aeb259 Mon Sep 17 00:00:00 2001 From: DominicKarma <51094361+DominicKarma@users.noreply.github.com> Date: Mon, 3 Jan 2022 19:07:10 -0600 Subject: [PATCH] Manual merge of shader list --- Effects/CalamityShaders.cs | 3 + Effects/LocalLinearTransformationShader.fx | 62 ++++++++++ Effects/LocalLinearTransformationShader.xnb | Bin 0 -> 2868 bytes Projectiles/Melee/OldLordOathswordProj.cs | 122 +++++++++++++------- 4 files changed, 143 insertions(+), 44 deletions(-) create mode 100644 Effects/LocalLinearTransformationShader.fx create mode 100644 Effects/LocalLinearTransformationShader.xnb diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index e39af2af3f..242765f67a 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -30,6 +30,7 @@ namespace CalamityMod.Effects public static Effect DoGDisintegrationShader; public static Effect ArtAttackTrailShader; public static Effect CircularAoETelegraph; + public static Effect LocalLinearTransformationShader; public static Effect BaseFusableParticleEdgeShader; public static Effect AdditiveFusableParticleEdgeShader; @@ -63,6 +64,7 @@ namespace CalamityMod.Effects DoGDisintegrationShader = CalamityMod.Instance.GetEffect("Effects/DoGDisintegration"); ArtAttackTrailShader = CalamityMod.Instance.GetEffect("Effects/ArtAttackTrail"); CircularAoETelegraph = CalamityMod.Instance.GetEffect("Effects/CircularAoETelegraph"); + LocalLinearTransformationShader = CalamityMod.Instance.GetEffect("Effects/LocalLinearTransformationShader"); BaseFusableParticleEdgeShader = CalamityMod.Instance.GetEffect("Effects/ParticleFusion/BaseFusableParticleEdgeShader"); AdditiveFusableParticleEdgeShader = CalamityMod.Instance.GetEffect("Effects/ParticleFusion/AdditiveFusableParticleEdgeShader"); @@ -94,6 +96,7 @@ namespace CalamityMod.Effects GameShaders.Misc["CalamityMod:DoGDisintegration"] = new MiscShaderData(new Ref(DoGDisintegrationShader), "DisintegrationPass"); GameShaders.Misc["CalamityMod:ArtAttack"] = new MiscShaderData(new Ref(ArtAttackTrailShader), "TrailPass"); GameShaders.Misc["CalamityMod:CircularAoETelegraph"] = new MiscShaderData(new Ref(CircularAoETelegraph), "TelegraphPass"); + GameShaders.Misc["CalamityMod:LinearTransformation"] = new MiscShaderData(new Ref(LocalLinearTransformationShader), "TransformationPass"); GameShaders.Misc["CalamityMod:BaseFusableParticleEdge"] = new MiscShaderData(new Ref(BaseFusableParticleEdgeShader), "ParticlePass"); GameShaders.Misc["CalamityMod:AdditiveFusableParticleEdge"] = new MiscShaderData(new Ref(AdditiveFusableParticleEdgeShader), "ParticlePass"); diff --git a/Effects/LocalLinearTransformationShader.fx b/Effects/LocalLinearTransformationShader.fx new file mode 100644 index 0000000000..54c411a842 --- /dev/null +++ b/Effects/LocalLinearTransformationShader.fx @@ -0,0 +1,62 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity : register(C0); +float uSaturation; +float uCircularRotation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +float2 overallImageSize; +matrix uWorldViewProjection; +float2x2 localMatrix; + +struct VertexShaderInput +{ + float4 Position : POSITION0; + float2 Coordinates : TEXCOORD0; + float4 Color : COLOR0; +}; + +struct VertexShaderOutput +{ + float4 Position : POSITION0; + float2 Coordinates : TEXCOORD0; + float4 Color : COLOR0; +}; + +VertexShaderOutput VertexShaderFunction(in VertexShaderInput input) +{ + VertexShaderOutput output = (VertexShaderOutput) 0; + output.Color = input.Color; + output.Coordinates = mul(input.Coordinates - 0.5, localMatrix) + 0.5; + output.Position = mul(input.Position, uWorldViewProjection); + + return output; +} + +float4 PixelFunction(VertexShaderOutput input) : COLOR0 +{ + if (input.Coordinates.x < 0 || input.Coordinates.x > 1 || input.Coordinates.y < 0 || input.Coordinates.y > 1) + return 0; + + float4 color = tex2D(uImage0, input.Coordinates) * input.Color; + float originalAlpha = color.a; + color.rbg = lerp(color.rbg, uColor, uOpacity); + return color * originalAlpha; +} + +technique Technique1 +{ + pass TransformationPass + { + VertexShader = compile vs_2_0 VertexShaderFunction(); + PixelShader = compile ps_2_0 PixelFunction(); + } +} \ No newline at end of file diff --git a/Effects/LocalLinearTransformationShader.xnb b/Effects/LocalLinearTransformationShader.xnb new file mode 100644 index 0000000000000000000000000000000000000000..a4edfa8d9d20a2ef3e9b9f782997b818d962a6e7 GIT binary patch literal 2868 zcmb_eO>7%Q6n?vQQkMof{7ID>sXl-xQe-*CL8+9eAr3zkDVW$PxwYHPx?XB~&3d;X zh{IOmz@Y~hE*v=c&_ktEC`i3g2_!ghK!RfrJyggNIYfdZr}&=rk;>1rp7(uk zzBlvc&6~B?-(K1rqtXc?D*E5H+-wpaP97N?xN#&U9Y`R$`|-EohygUAoQJuwi5=v)tt^%!YfVJe#_aa zdDoow!d$6n*XOP{GaJrqVRrUqVli$$LG<&9KkiQoD8G#3!~Mmyv@uL*lK#H@Nj7sBxGear33}~QnluvWfF@Uh_H9en_m^&Kbuo%ugtU9*W-mv^F8O%JE zhw>r5d3{!v*Xz1oNvFDr^NPyT}bLnm>a7H1o@@Z--6G zU-beRCHKT}!4Yv>%P`@eO7gmW1b>|QHMiy9scQ33Q5J-yLj~Dv3vx>e;Vkb?- zAYxOG%>sw-d46-F;&ok7hNKS5S{%oyI5aBnA_80 z`3&Og1nb|+a|o67zvw!f72kV5uIg6{<7(Xp+Pa*Fw(VqLu2Ivot>y(Q@ZAr^S@9hj z&5>jI%t!stz*qCFcDL^NEz#H&tJ@{wv#vRIqwRhWIx|Fk2l%YVpqv)Za}uiL42*dN z@LYj5G#tVHQp5LQKhW?V?2KwO*i*3QG+cw-(eNj*`x@SX{ga0GU}v;~Jr8?P!!_6) z4fkN*)$k9nA8Ghc*w1R`QG#93@LkwHYPb*=no~L%+dSQ8P?kM#ccGt4NNMJ1yx2`c zh}zaop1>Rq_lNUTuD!Z61^5jU;p3$lLvr`%q-g>?xfausck%Z2Hm|6Ub-I^|mkN~pCg#qpzLa}&rMi-< zHu&c})Y#oGX>+U9_G_*}hC8Iwzk*r)ByP*4a6*v%T2vQ6}48 z65Gy#GuWZbppX5g49Wo0*Cws?QL8j^j0_q^7{j>onatTyJ{iY6g04jeadbm*q>tm) z{!yHqTf}KOnPMF^_vrd)m$XUaSZly~%b-(z=`(=Eal=P_+*usE*gx}n%pp3)9PD+# zzUc3qq1YS8ApQoAa}Kag)Kl<>Lqx~IJ*sSR=gfWd==r2af9FB?Fh|m(yRetpO=D2p zCFo^n1m(U(f}%I?;HkggQrLT|oQ1UUzaqk2;8zyTH3k2m2X0@U;Y5VWMq{)b;}q~98YkKJ%qRK{`YYxT t@sD^M{o2R>D9mSk2i(J)F*XH8pTsyVa4NwWfz!aEKPdYPxIONOzW@n}e*^#k literal 0 HcmV?d00001 diff --git a/Projectiles/Melee/OldLordOathswordProj.cs b/Projectiles/Melee/OldLordOathswordProj.cs index 2fc70c4881..0bcabc89d8 100644 --- a/Projectiles/Melee/OldLordOathswordProj.cs +++ b/Projectiles/Melee/OldLordOathswordProj.cs @@ -14,14 +14,23 @@ namespace CalamityMod.Projectiles.Melee { public class OldLordOathswordProj : BaseIdleHoldoutProjectile { + public enum SwingState + { + Default, + Swinging, + Channeling, + Spinning + } + public int Direction = 1; + public SwingState CurrentState; public ref float ChargeTime => ref projectile.ai[0]; public ref float GeneralTime => ref projectile.ai[1]; public ref float PostSwingRepositionDelay => ref projectile.localAI[0]; public ref bool RMBChannel => ref (Owner.HeldItem.modItem as OldLordOathsword).RMBchannel; public bool LMBUse => Owner.altFunctionUse != 2 && !RMBChannel && Owner.itemAnimation > 0; public ref float ChargePower => ref projectile.localAI[1]; - public float CurrentState; //0 = default, 1 = Swinging, 2 = Channeling, 3 = Spinning + public const int MaxChargeTime = 60; public override string Texture => "CalamityMod/Items/Weapons/Melee/OldLordOathsword"; public override int AssociatedItemID => ModContent.ItemType(); @@ -54,7 +63,7 @@ namespace CalamityMod.Projectiles.Melee writer.Write(Direction); writer.Write(PostSwingRepositionDelay); writer.Write(ChargePower); - writer.Write(CurrentState); + writer.Write((int)CurrentState); } public override void ReceiveExtraAI(BinaryReader reader) @@ -62,63 +71,46 @@ namespace CalamityMod.Projectiles.Melee Direction = reader.ReadInt32(); PostSwingRepositionDelay = reader.ReadSingle(); ChargePower = reader.ReadSingle(); - CurrentState = reader.ReadSingle(); + CurrentState = (SwingState)reader.ReadInt32(); } public override void SafeAI() { - #region RMB Channel setup - CalamityPlayer controlsSync = Owner.GetModPlayer(); + // Handle right click behaviors. if (Main.myPlayer == projectile.owner) - { - controlsSync.rightClickListener = true; - } + Owner.Calamity().rightClickListener = true; - if (!controlsSync.mouseRight) + if (!Owner.Calamity().mouseRight) RMBChannel = false; else RMBChannel = true; - #endregion - // Initialize the animation max time if necessary. if (Owner.itemAnimationMax == 0) Owner.itemAnimationMax = (int)(Owner.ActiveItem().useAnimation * Owner.meleeSpeed); - if (((Owner.itemAnimation <= 0) || (!RMBChannel && CurrentState == 2f)) && CurrentState != 3) //Reset the state of the weapon if the player stops using it. This cannot reset a dash - { - Owner.itemAnimation = 0; - CurrentState = 0f; - } - if (CurrentState == 0f && !RMBChannel && Owner.itemAnimation > 0 && ChargePower < MaxChargeTime) //Allowed to start swinging from the default state. You cannot swing while rotating or channeling. <- Unless we want to let the player interrupt their dashes with a swing - CurrentState = 1f; - if ((CurrentState == 0f || CurrentState == 1f) && RMBChannel) //Allowed to switch from default or swinging state to channeling. You cannot channel from the rotating state - CurrentState = 2f; - if (CurrentState == 0f && Owner.itemAnimation > 0 && ChargePower >= MaxChargeTime) //You can only dash if you're not swinging or channeling (Not like you could swap from the Swinging state to the Dashing one anyways) - { - Owner.fallStart = (int)(Owner.position.Y / 16f); - CurrentState = 3f; - } - + // Decide the current phase state of the blade. + DecideCurrentState(); // Glue the sword to its owner. projectile.position = Owner.RotatedRelativePoint(Owner.MountedCenter, true) - projectile.Size / 2f + Vector2.UnitY * Owner.gfxOffY; - if (CurrentState != 3f) + // Use the direction of the owner when not spinning. + if (CurrentState != SwingState.Spinning) Direction = Owner.direction; float swingCompletion = Owner.itemAnimation / (float)Owner.itemAnimationMax; - float swingSpeedInterpolant = Utils.InverseLerp(1f, 0.8f, swingCompletion, true) * Utils.InverseLerp(-0.05f, 0.2f, swingCompletion, true); - float swingInterpolant = (float)Math.Sin(swingCompletion * MathHelper.TwoPi); + float swingSpeedInterpolant = Utils.InverseLerp(1f, 0.8f, swingCompletion, true) * Utils.InverseLerp(-0.11f, 0.12f, swingCompletion, true); + float swingInterpolant = (float)Math.Sin(Math.Pow(swingCompletion, 1.15) * MathHelper.TwoPi); if (swingInterpolant < 0f) { swingInterpolant = -(float)Math.Pow(-swingInterpolant, 0.9); - swingInterpolant = MathHelper.Lerp(swingInterpolant, -1f, 0.5f); + swingInterpolant = MathHelper.Lerp(swingInterpolant, -1f, 0.7f); } else { swingInterpolant = (float)Math.Pow(swingInterpolant, 0.9); - swingInterpolant = MathHelper.Lerp(swingInterpolant, 1f, 0.5f); + swingInterpolant = MathHelper.Lerp(swingInterpolant, 1f, 0.7f); } float baseRotation = swingInterpolant * Direction * 0.96f; @@ -127,7 +119,7 @@ namespace CalamityMod.Projectiles.Melee Owner.fullRotation = 0f; // Do a spin dash if a swing is done with full power. - if (CurrentState == 3f) + if (CurrentState == SwingState.Spinning) { swingSpeedInterpolant = 1f; baseRotation = MathHelper.WrapAngle(swingCompletion * Direction * MathHelper.Pi * -3f); @@ -185,10 +177,10 @@ namespace CalamityMod.Projectiles.Melee // Raise the blade and do charge effects upwards if channeling. float horizontalBladeOffset = -4f; float chargeInterpolant = Utils.InverseLerp(0f, 35f, ChargeTime, true); - if (CurrentState == 2f) + if (CurrentState == SwingState.Channeling) { baseRotation = MathHelper.PiOver2 * -Direction; - horizontalBladeOffset = MathHelper.Lerp(horizontalBladeOffset, 10f, (float)Math.Pow(chargeInterpolant, 0.3)); + horizontalBladeOffset = MathHelper.Lerp(horizontalBladeOffset, 6f, (float)Math.Pow(chargeInterpolant, 0.3)); if (Owner.itemAnimation < 2) Owner.itemAnimation = 2; PostSwingRepositionDelay = -1f; @@ -215,16 +207,16 @@ namespace CalamityMod.Projectiles.Melee // Decide how far out the blade should go. float bladeOffsetFactor = 0.5f + chargeInterpolant * 0.3f; if (chargeInterpolant <= 0f) - bladeOffsetFactor += Utils.InverseLerp(0.5f, 0.7f, swingCompletion, true) * Utils.InverseLerp(1f, 0.7f, swingCompletion, true) * 0.6f; + bladeOffsetFactor += Utils.InverseLerp(0.5f, 0.7f, swingCompletion, true) * Utils.InverseLerp(1f, 0.7f, swingCompletion, true) * 0.45f; // Offset the blade so that the handle is attached to the owner's hand. Vector2 bladeOffset = (projectile.rotation - MathHelper.PiOver4).ToRotationVector2() * projectile.width * bladeOffsetFactor; if (Owner.itemAnimation <= 0 || chargeInterpolant > 0f) - bladeOffset += new Vector2(Direction * horizontalBladeOffset, 16f).RotatedBy(Owner.fullRotation) * (1f - PostSwingRepositionDelay / 12f); + bladeOffset += new Vector2(Direction * horizontalBladeOffset, 8f).RotatedBy(Owner.fullRotation) * (1f - PostSwingRepositionDelay / 12f); projectile.position += bladeOffset; // Create charge dust. - if (CurrentState == 2f) + if (CurrentState == SwingState.Channeling) { int chargeDustCount = (int)Math.Round(MathHelper.Lerp(1f, 3f, ChargePower / 60f)); if (ChargePower >= MaxChargeTime) @@ -260,19 +252,61 @@ namespace CalamityMod.Projectiles.Melee GeneralTime++; } + public void DecideCurrentState() + { + // Reset the state of the weapon if the player stops using it. This cannot reset a dash. + if ((Owner.itemAnimation <= 0 || (!RMBChannel && CurrentState == SwingState.Channeling)) && CurrentState != SwingState.Spinning) + { + Owner.itemAnimation = 0; + CurrentState = SwingState.Default; + } + + // Switch to the swing state as necessary. This cannot happen while channeling or spinning. + if (CurrentState == 0f && !RMBChannel && Owner.itemAnimation > 0 && ChargePower < MaxChargeTime) + CurrentState = SwingState.Swinging; + + // Switch to the channel state as necessary. This cannot happen while swinging or spinning. + if ((CurrentState == SwingState.Default || CurrentState == SwingState.Swinging) && RMBChannel) + CurrentState = SwingState.Channeling; + + // Switch to the spinning charge state. This can only be done while in the default state. + if (CurrentState == 0f && Owner.itemAnimation > 0 && ChargePower >= MaxChargeTime) + { + Owner.fallStart = (int)(Owner.position.Y / 16f); + + if (CurrentState != SwingState.Spinning) + { + Main.PlaySound(SoundID.DD2_BookStaffCast, Owner.Center); + CurrentState = SwingState.Spinning; + projectile.netUpdate = true; + } + } + } + public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { - CalamityUtils.DrawAfterimagesCentered(projectile, 2, lightColor); - spriteBatch.EnterShaderRegion(); - GameShaders.Misc["CalamityMod:BasicTint"].UseColor(Main.hslToRgb(0.95f, 0.85f, 0.5f)); - GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(0f); - if (ChargePower >= MaxChargeTime) - GameShaders.Misc["CalamityMod:BasicTint"].UseOpacity(0.7f - ((Main.GlobalTime * 30) % 30f / 60f)); - GameShaders.Misc["CalamityMod:BasicTint"].Apply(); + + float tintOpacity = Utils.InverseLerp(0f, MaxChargeTime, ChargePower, true) * 0.6f; + Color tintColor = Main.hslToRgb(0.9f, 0.9f, 0.5f); + + float swingCompletion = Owner.itemAnimation / (float)Owner.itemAnimationMax; + CalamityUtils.CalculatePerspectiveMatricies(out Matrix viewMatrix, out Matrix projectionMatrix); + GameShaders.Misc["CalamityMod:LinearTransformation"].UseColor(tintColor); + GameShaders.Misc["CalamityMod:LinearTransformation"].UseOpacity(tintOpacity); + GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["uWorldViewProjection"].SetValue(viewMatrix * projectionMatrix); + GameShaders.Misc["CalamityMod:LinearTransformation"].Shader.Parameters["localMatrix"].SetValue(new Matrix() + { + M11 = MathHelper.Lerp(1f, 1.3f, (1f - swingCompletion) * Utils.InverseLerp(0f, 0.1f, swingCompletion, true)), + M12 = 0f, + M21 = 0f, + M22 = MathHelper.Lerp(1f, 1.3f, swingCompletion * Utils.InverseLerp(0f, 0.1f, swingCompletion, true)) + }); + GameShaders.Misc["CalamityMod:LinearTransformation"].Apply(); var texture = ModContent.GetTexture("CalamityMod/Items/Weapons/Melee/OldLordOathsword"); + CalamityUtils.DrawAfterimagesCentered(projectile, 2, lightColor); spriteBatch.Draw(texture, projectile.Center - Main.screenPosition, null, lightColor, projectile.rotation, projectile.Size / 2f, projectile.scale, projectile.spriteDirection == -1 ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0f); spriteBatch.ExitShaderRegion();