From 60bf61de482fdaeda7da07c772e87919acbfbcbd Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 13 Oct 2022 18:24:42 -0500 Subject: [PATCH] Various visual improvements as requested --- Effects/BlueStaticShader.fx | 22 ++++-- Effects/BlueStaticShader.xnb | Bin 2624 -> 3276 bytes UI/DraedonSummoning/CodebreakerUI.cs | 113 ++++++++++++++++++++++++--- 3 files changed, 116 insertions(+), 19 deletions(-) diff --git a/Effects/BlueStaticShader.fx b/Effects/BlueStaticShader.fx index eede8887ee..41bb90d15b 100644 --- a/Effects/BlueStaticShader.fx +++ b/Effects/BlueStaticShader.fx @@ -13,24 +13,32 @@ float3 uLightSource; float2 uImageSize0; float2 uImageSize1; float4 uShaderSpecificData; +float coordinateZoomFactor; +bool useStaticLine; +bool useTrueNoise; -float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +float Random(float2 coords) +{ + return abs(frac(sin(dot(coords, float2(17.8342, 74.8819))) * 53648)); +} + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 { // Calculate a noise value that very, very rapidly descends downward. // So fast that it gives the appearance of TV static. This as an overall effect on the entire texture. - float noiseOffset = tex2D(uImage1, coords * 0.2).r * 0.02; - float noise = tex2D(uImage1, coords * 0.9 + float2(noiseOffset, uTime * -97.3)).r; - + float noise = Random(coords * coordinateZoomFactor * 0.3 + float2(0, frac(uTime * -97.3))); + // Calculate a base noise value that makes a bright line scroll down the screen. This is achieved by using a strongly squished sinusoid that scrolls downward and // taking its resulting value as a 0-1 interpolant. - float brightLineInterpolant = pow(sin(uTime * 3.1 - coords.y * 5.4) * 0.5 + 0.5, 4.96); + float brightLineInterpolant = useStaticLine ? pow(sin(uTime * 3.1 - coords.y * 5.4) * 0.5 + 0.5, 4.96) : 0; // After the initial bright line value is calculated, incorporate the X axis to weaker extent. This allows the line to have bends and look less unnaturally simple. brightLineInterpolant += pow(sin(uTime * 1.9 - coords.x * 2.4) * 0.5 + 0.5, 2.51) * 0.55; // Lastly, apply the noise from above, and clamp the entire interpolant between 0-1 before passing it in as a color multiplier. - brightLineInterpolant += noise * 0.16; - return float4(0.3, 0.8, 1, 1) * lerp(1, 6, saturate(brightLineInterpolant)) * 0.2; + brightLineInterpolant += noise * (useStaticLine ? 0.16 : 0.91); + + return float4(0.3, 0.8, 1, 1) * lerp(1, 6, saturate(brightLineInterpolant)) * sampleColor * 0.2; } technique Technique1 { diff --git a/Effects/BlueStaticShader.xnb b/Effects/BlueStaticShader.xnb index 88988c13a734ae9cc50529c4278336adf9be734f..1fc89b09dd2c83603ff4f63b97647a1b04a034a4 100644 GIT binary patch literal 3276 zcmbtVU2GIp6uz_2cH1r%6%$PwnII-;noV0;QX-`bTUr}eEZwed2ni0;TXw>Br_9cT zA9)yJOdugrBR)V38G{eFC8iIkJT#^eUr5?We1QZW)bJ)6UVYi|J9GDLZw)1ir@cGp zoco=7zH{!qGx@!{k2PqE3C6Tfw6`tOvCH8LE-$&sJ(H8% zbjP?c!JQ6$HT1A!OcyM(+@ZhAow8+@`g@X{^w*)My`t+myuZXf*D;D6`lxrPXqj*E z6XW&~Uh41b={6_(4)LxD-rL#RyOoh>o5Aj<)<^T}BUAin&0+PIH9~K}V=YFzFzdf@ zXx_+_ahP{9iAmLGg|dw4Vziuw;VKyEQ(UYGhL^UBw!=a>e^miUpW*Sxe(HU`tAJyGDkf`#?Y(C^#fee7 zY(?e#DfuM`Toa0sajnq3LCZl7DnF`+<^~nKH|Ym6!{w#6)L#lBtBiPD0ie_E^W8hlq3zpOiiNc}op^jH{H!)+`* zzH4_o%quhrA5kM4qElZ7F=E&i%69;xh;b_NHAKF1HQ!^;-|Xxx-83!w1Mo4j^6U{_ zpk>Ra%Lls;cCz}nNZ&H{n*L@co6*HZ(bM+Sv{mGezCGE!ExEn7JK5dW)5EIaS8Q}_ zPgaZNhpJ&$z0ULCK)!mN8q=u;QKvYI8Q8McSdBZ?Og`~`{Qq^i$DgLA1Zv8TfJR;D zzDSWhQ+?HN6H8}C#?^1D#Q)dlR+4OfVQG;ho|=rLIw05C_|fnCZoK@*zy}+?9{%;@ zk9EJCuZC$hl+UE;_-Sl3kk>#y2}d>1H=BgM!z3C@t(Ub)ANggSPg;wFinbu<=>=3B9DLRnj5IpA{9Iyzo1cw0ocX2cSg7;E;MfX~;s zG%)r>jDcHKp?UmY# zXTc%ogLD8czR0V=$53M>XapD92aTN(3hJ&xZN?UBi}9;A5D*2C)^=e)B)IHU!JTM$ zn<}Cs-Nh^dZd_C;?t}#0NEdaZu?WsKxk(6=6rGCPHFZ8Jxr=sRy26jjP(VUzHNKeE-QgqYSZpN z_sargL{Tdmpz)d0V|_SYWEL=;&3mHsBp%0cn#wh*{YJer%eVvFThD+W`b0sN z3o)Jm{`f=b6vw#EA6x<#U7uCP>%Qh<|GH9HMeKb$H`^Z%Ai!j6?fnxWk)v@hFsT`$ z3;YE*`5IBQgxEHW0t7=#mA!q77F7_5!a-yRGLS)mgo3+GMNl3YdGPXK8fEc5HP40$ zSLHlg$EjVFYRFl_dqU0@7U-(rrLf-!pc5P z_-xkjO@w3moD2jt10kCs$6<~8SOkHa;{gZ|2qUb7M3o@MxDbyq&*U9Kaf97D4<8Zo o^mqa51_KA$4)o%J3DyV_7;Zc`J|BQ1Jw=H_Mej+*PNRtEH!Tv&`Tzg` diff --git a/UI/DraedonSummoning/CodebreakerUI.cs b/UI/DraedonSummoning/CodebreakerUI.cs index eb5ab7577f..c31c0b76ff 100644 --- a/UI/DraedonSummoning/CodebreakerUI.cs +++ b/UI/DraedonSummoning/CodebreakerUI.cs @@ -95,6 +95,12 @@ namespace CalamityMod.UI.DraedonSummoning set; } = string.Empty; + public static float DraedonScreenStaticInterpolant + { + get; + set; + } = 1f; + // The text that Draedon should attempt to spell out. public static string DraedonTextComplete { @@ -110,7 +116,19 @@ namespace CalamityMod.UI.DraedonSummoning public static readonly SoundStyle SummonSound = new("CalamityMod/Sounds/Custom/CodebreakerBeam"); - public const int DraedonTextCreationRate = 3; + public static char PreviousTextCharacter => DraedonText.Length >= 1 ? DraedonTextComplete[DraedonText.Length - 1] : ' '; + + public static char NextTextCharacter => DraedonText.Length < DraedonTextComplete.Length ? DraedonTextComplete[DraedonText.Length] : ' '; + + public static int DraedonTextCreationRate + { + get + { + if (PreviousTextCharacter is '.' or '?') + return 9; + return 1; + } + } public static void Draw(SpriteBatch spriteBatch) { @@ -135,14 +153,25 @@ namespace CalamityMod.UI.DraedonSummoning spriteBatch.Draw(backgroundTexture, BackgroundCenter, null, Color.White, 0f, backgroundTexture.Size() * 0.5f, GeneralScale * (1f - CommunicationPanelScale), 0, 0f); Rectangle backgroundArea = Utils.CenteredRectangle(BackgroundCenter, backgroundTexture.Size() * GeneralScale); - if (MouseScreenArea.Intersects(backgroundArea)) + if (MouseScreenArea.Intersects(backgroundArea) && !DisplayingCommunicationText) Main.blockMouse = Main.LocalPlayer.mouseInterface = true; // Display communication stuff as necessary. - CommunicationPanelScale = MathHelper.Clamp(CommunicationPanelScale + (DisplayingCommunicationText ? 0.026f : -0.08f), 0f, 1f); + if (DisplayingCommunicationText && CommunicationPanelScale == 0f) + { + CommunicationPanelScale = 1f; + DraedonScreenStaticInterpolant = 1f; + } + if (!DisplayingCommunicationText && CommunicationPanelScale != 0f) + { + CommunicationPanelScale = 0f; + DraedonScreenStaticInterpolant = 0f; + } + if (DisplayingCommunicationText) { DisplayCommunicationPanel(); + DraedonScreenStaticInterpolant = MathHelper.Clamp(DraedonScreenStaticInterpolant - 0.014f, 0f, 1f); return; } @@ -634,10 +663,34 @@ namespace CalamityMod.UI.DraedonSummoning Main.spriteBatch.Draw(panelTexture, panelCenter, null, Color.White, 0f, panelTexture.Size() * 0.5f, panelScale, 0, 0f); + // Draw static if the static interpolant is sufficiently high. + if (DraedonScreenStaticInterpolant > 0f) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + + // Apply a glitch shader. + GameShaders.Misc["CalamityMod:BlueStatic"].SetShaderTexture(ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/SharpNoise")); + GameShaders.Misc["CalamityMod:BlueStatic"].Shader.Parameters["useStaticLine"].SetValue(false); + GameShaders.Misc["CalamityMod:BlueStatic"].Shader.Parameters["coordinateZoomFactor"].SetValue(0.5f); + GameShaders.Misc["CalamityMod:BlueStatic"].Shader.Parameters["useTrueNoise"].SetValue(true); + GameShaders.Misc["CalamityMod:BlueStatic"].Apply(); + + float readjustedInterpolant = Utils.GetLerpValue(0.42f, 1f, DraedonScreenStaticInterpolant, true); + Color staticColor = Color.White * (float)Math.Pow(CalamityUtils.AperiodicSin(readjustedInterpolant * 2.94f) * 0.5f + 0.5f, 0.54) * (float)Math.Pow(readjustedInterpolant, 0.51D); + Main.spriteBatch.Draw(panelTexture, panelCenter, null, staticColor, 0f, panelTexture.Size() * 0.5f, panelScale, 0, 0f); + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.Rasterizer, null, Matrix.Identity); + } + + // Disable clicks if hovering over the panel. + if (Utils.CenteredRectangle(panelCenter, panelTexture.Size() * panelScale).Intersects(MouseScreenArea)) + Main.blockMouse = Main.LocalPlayer.mouseInterface = true; + // Draw a panel that has Draedon's face. - float draedonIconDrawInterpolant = Utils.GetLerpValue(0.67f, 1f, CommunicationPanelScale, true); + float draedonIconDrawInterpolant = Utils.GetLerpValue(0.51f, 0.36f, DraedonScreenStaticInterpolant, true); Vector2 draedonIconDrawTopRight = panelCenter + panelTexture.Size() * new Vector2(-0.5f, -0.5f) * panelScale + new Vector2(2f, 4f) * panelScale; - Vector2 draedonIconScale = panelScale * draedonIconDrawInterpolant * 0.2f; + Vector2 draedonIconScale = panelScale * 0.2f; Vector2 draedonIconCenter = draedonIconDrawTopRight + panelTexture.Size() * new Vector2(0.5f, 0.5f) * draedonIconScale; Vector2 draedonIconRight = new(draedonIconDrawTopRight.X, draedonIconCenter.Y); Rectangle draedonIconArea = Utils.CenteredRectangle(draedonIconCenter, panelTexture.Size() * draedonIconScale * 0.95f); @@ -654,7 +707,7 @@ namespace CalamityMod.UI.DraedonSummoning GameShaders.Misc["CalamityMod:TeleportDisplacement"].Shader.Parameters["frameCount"].SetValue(Vector2.One); GameShaders.Misc["CalamityMod:TeleportDisplacement"].Apply(); - Vector2 draedonScale = new Vector2(1f, draedonIconDrawInterpolant) * 1.6f; + Vector2 draedonScale = new Vector2(draedonIconDrawInterpolant, 1f) * 1.6f; SpriteEffects draedonDirection = SpriteEffects.FlipHorizontally; Texture2D draedonFaceTexture = ModContent.Request("CalamityMod/NPCs/ExoMechs/HologramDraedon").Value; @@ -663,10 +716,12 @@ namespace CalamityMod.UI.DraedonSummoning // Draw a glitch effect over the panel and Draedon's icon. GameShaders.Misc["CalamityMod:BlueStatic"].UseImage1("Images/Misc/noise"); + GameShaders.Misc["CalamityMod:BlueStatic"].Shader.Parameters["useStaticLine"].SetValue(true); + GameShaders.Misc["CalamityMod:BlueStatic"].Shader.Parameters["coordinateZoomFactor"].SetValue(1f); GameShaders.Misc["CalamityMod:BlueStatic"].Apply(); Main.spriteBatch.Draw(panelTexture, draedonIconDrawTopRight, null, Color.White * draedonIconDrawInterpolant, 0f, Vector2.Zero, draedonIconScale, 0, 0f); Main.spriteBatch.End(); - Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Matrix.Identity); + Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Matrix.Identity); // Draw Draedon text. if (string.IsNullOrEmpty(DraedonTextComplete)) @@ -696,13 +751,31 @@ namespace CalamityMod.UI.DraedonSummoning return; // Draw inquiry buttons. + float buttonOpacity = Utils.GetLerpValue(0.25f, 0.04f, DraedonScreenStaticInterpolant, true); Texture2D buttonTexture = ModContent.Request("CalamityMod/UI/DraedonSummoning/DraedonInquiryButton").Value; Dictionary inquiries = new() { - ["Mrrp"] = "Mrrp is cringe." + ["Astral"] = "That pernicious blemish? I do not know of its exact origin, nor the full extent of its capabilities. " + + "Through some process that I do not understand, it appears to be able to 'infect' virtually any matter it comes into contact with, organic or not, and manipulate it into a form deemed suitable " + + "for its objective of spreading to the ends of the cosmos.\n" + + "Some time ago, I dispatched one of my machines to collect some samples of the material near the crash site. However, attempts at contact with it abruptly ceased one day.\n" + + "I can only imagine what has happened to it since." }; + + if (buttonOpacity < 1f) + { + GameShaders.Misc["CalamityMod:TeleportDisplacement"].UseOpacity((1f - buttonOpacity) * 0.04f); + GameShaders.Misc["CalamityMod:TeleportDisplacement"].UseSecondaryColor(Color.White * buttonOpacity); + GameShaders.Misc["CalamityMod:TeleportDisplacement"].UseSaturation(buttonOpacity); + GameShaders.Misc["CalamityMod:TeleportDisplacement"].Shader.Parameters["frameCount"].SetValue(Vector2.One); + GameShaders.Misc["CalamityMod:TeleportDisplacement"].Apply(); + } + for (int i = 0; i < inquiries.Count; i++) { + if (buttonOpacity <= 0f) + break; + Vector2 buttonPosition = panelCenter + Vector2.UnitY * panelScale * (panelTexture.Height * 0.5f - 32f); // Spread out buttons horizontally if there are more than one. @@ -710,9 +783,19 @@ namespace CalamityMod.UI.DraedonSummoning buttonPosition.X = MathHelper.Lerp(panelCenter.X - panelScale.X * 270f, panelCenter.X + panelScale.X * 270f, i / (float)(inquiries.Count - 1f)); string inquiryText = inquiries.Keys.ElementAt(i); + float flickerInterpolant = CalamityUtils.AperiodicSin(Main.GlobalTimeWrappedHourly * 9.74f + i) * 0.5f + 0.5f; bool hoveringOverIcon = Utils.CenteredRectangle(buttonPosition, buttonTexture.Size() * draedonIconDrawInterpolant * GeneralScale).Intersects(MouseScreenArea); - Color buttonColor = (hoveringOverIcon ? Color.Yellow : Color.White) * draedonIconDrawInterpolant; - Main.spriteBatch.Draw(buttonTexture, buttonPosition, null, buttonColor, 0f, buttonTexture.Size() * 0.5f, draedonIconDrawInterpolant * GeneralScale, 0, 0f); + Color buttonColor = (hoveringOverIcon ? Color.Yellow : Color.White) * draedonIconDrawInterpolant * buttonOpacity; + + // Have the button flicker. + buttonColor *= MathHelper.Lerp(0.55f, 1f, flickerInterpolant); + + Main.spriteBatch.Draw(buttonTexture, buttonPosition, null, buttonColor, 0f, buttonTexture.Size() * 0.5f, GeneralScale, 0, 0f); + for (int j = 0; j < 4; j++) + { + Vector2 drawOffset = -Vector2.UnitY.RotatedBy(MathHelper.TwoPi * j / 4f) * flickerInterpolant * 4f; + Main.spriteBatch.Draw(buttonTexture, buttonPosition + drawOffset, null, buttonColor * 0.3f, 0f, buttonTexture.Size() * 0.5f, GeneralScale, 0, 0f); + } if (hoveringOverIcon) { @@ -727,8 +810,14 @@ namespace CalamityMod.UI.DraedonSummoning } } - Vector2 textPosition = buttonPosition - Vector2.UnitX * FontAssets.MouseText.Value.MeasureString(inquiryText) * 0.75f; - ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, FontAssets.MouseText.Value, inquiryText, textPosition, Draedon.TextColor, 0f, Vector2.Zero, Vector2.One * GeneralScale); + Vector2 textPosition = buttonPosition - FontAssets.MouseText.Value.MeasureString(inquiryText) * new Vector2(0.75f, 0.5f); + ChatManager.DrawColorCodedStringWithShadow(Main.spriteBatch, FontAssets.MouseText.Value, inquiryText, textPosition, Draedon.TextColor * draedonIconDrawInterpolant * buttonOpacity, 0f, Vector2.Zero, Vector2.One * GeneralScale); + } + + if (buttonOpacity < 1f) + { + Main.spriteBatch.End(); + Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Matrix.Identity); } } }