diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 9325d64cfd..285d9cc62f 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -227,13 +227,16 @@ namespace CalamityMod.Effects internal static Effect UnderwaterRaysShader; #endregion + internal static Asset SunkenSeaMenuLogoWater; + public override void PostSetupContent() { AssetRepository calAss = CalamityMod.Instance.Assets; // Shorthand to load shaders immediately. // Strings provided to LoadShader are the .xnb file paths. - Effect LoadShader(string path) => calAss.Request($"{ShaderPath}{path}", AssetRequestMode.ImmediateLoad).Value; + Effect LoadShader(string path) => LoadShaderAsset(path).Value; + Asset LoadShaderAsset(string path) => calAss.Request($"{ShaderPath}{path}", AssetRequestMode.ImmediateLoad); // // Loading and registering each individual compiled shader for use. @@ -448,6 +451,8 @@ namespace CalamityMod.Effects UnderwaterRaysShader = LoadShader("UnderwaterRaysShader"); RegisterMiscShader(UnderwaterRaysShader, "UnderwaterRayPass", "UnderwaterRays"); #endregion + + SunkenSeaMenuLogoWater = LoadShaderAsset("UI/SunkenSeaMenuLogoWater"); } // Shorthand to register a loaded shader in Terraria's graphics engine diff --git a/Effects/UI/SunkenSeaMenuLogoWater.fxc b/Effects/UI/SunkenSeaMenuLogoWater.fxc new file mode 100644 index 0000000000..917617be13 Binary files /dev/null and b/Effects/UI/SunkenSeaMenuLogoWater.fxc differ diff --git a/Effects/UI/SunkenSeaMenuLogoWater.hlsl b/Effects/UI/SunkenSeaMenuLogoWater.hlsl new file mode 100644 index 0000000000..234d3e0f49 --- /dev/null +++ b/Effects/UI/SunkenSeaMenuLogoWater.hlsl @@ -0,0 +1,76 @@ +/* Originally written for NIGHTSHADE for use as the liquid shader in the orb + * health and mana UIs: + * https://github.com/gold-meridian/nightshade-mod/blob/df037a103cb25dac8d36622515b3793f2b10ac3f/src/Nightshade/Assets/Shaders/UI/OrbFluidFillShader.hlsl + * + * Originally authored by Blockaroz and adapted by Tomat. + */ + +#include "../pixelation.h" + +sampler uImage0 : register(s0); + +texture uTexture0; +sampler tex0 = sampler_state +{ + texture = ; + magfilter = POINT; + minfilter = POINT; + mipfilter = POINT; + AddressU = wrap; + AddressV = wrap; +}; + +texture uBubbleTexture; +sampler bubbleTex = sampler_state +{ + texture = ; + magfilter = POINT; + minfilter = POINT; + mipfilter = POINT; + AddressU = wrap; + AddressV = wrap; +}; + +float2 uImageSize; +float uTime; +float uFillAmount; +float4 uFillColor; +float4 uEdgeColor; +float4 uLineColor; +float uWaveStrength; +float uWaveOffset; +float uSubtract; + +float4 main(float2 uv : TEXCOORD0, float4 baseColor : COLOR0) : COLOR0 +{ + float4 image = tex2D(uImage0, uv); + + uv = normalize_with_pixelation(uv * uImageSize, 2, uImageSize); + float2 center = uv * 2 - 1; + float distFromCenter = length(center); + + float2 uvForNoise = uv * uImageSize / 128; + + float4 bubbles = tex2D(bubbleTex, uvForNoise + float2(uTime / 10, uTime / 6)); + float4 bubbles2 = tex2D(bubbleTex, uvForNoise + float2((bubbles.r - 0.5) * 0.5, uTime / 10)); + float4 noise = tex2D(tex0, uvForNoise + float2(uTime / 6 + (bubbles.r - 0.5) * 0.05, (bubbles2.r - 0.5) * 0.1)); + uv.y = lerp(uv.y, uv.y, 0.15); + + float fillAmount = 1.0f - uFillAmount; + float bumpLine = 0.2f * (smoothstep(0.9f, 1.0f, uFillAmount) - smoothstep(0.1f, 0.0f, uFillAmount)); + float height = uv.y + (sin(3.1415 * ((uv.x * uImageSize.x / 100 + uWaveOffset) * 1.5 - uTime)) + length(bubbles.rgb)) * uWaveStrength / uImageSize.y + bumpLine - (fillAmount + 2.0f / uImageSize.y); + float edgeGlow = pow(distFromCenter * 0.8 + (uv.y + height - 0.33f) * 0.2, (1 + length(noise.rgb)) * uSubtract) * (distFromCenter * 1.5 + 1 - length(noise.rgb)); + + float topCut = smoothstep(-1.5 / uImageSize.y, 0.5 / uImageSize.y, height); + float topLine = smoothstep(1.8 / uImageSize.y, 0, height) * 1.5 * sqrt(1 - distFromCenter) - (bubbles2 - bubbles) * (1 - height) * 0.2; + + return ((lerp(uFillColor - 0.3 * topCut * uSubtract, uEdgeColor * 0.9, clamp(edgeGlow * length(image.rgb) / 2, 0, 1.3)) + topLine * 2 * uLineColor) * topCut) * image; +} + +technique Technique1 +{ + pass WaterShader + { + PixelShader = compile ps_3_0 main(); + } +} \ No newline at end of file diff --git a/Effects/pixelation.h b/Effects/pixelation.h new file mode 100644 index 0000000000..60dae6f5fc --- /dev/null +++ b/Effects/pixelation.h @@ -0,0 +1,40 @@ +#ifndef PIXELATION_HLSL +#define PIXELATION_HLSL + +/** + * Applies pixelation to the given coordinates based on a defined pixel size and + * outputs the normalized coordinates. + * + * @param coords The coordinates within the resolution space. + * @param pixel_size The size of each pixel block. + * @param resolution The resolution with which to normalize the coords by. + * @return The normalized, pixelated texture coordinates. + */ +float2 normalize_with_pixelation(float2 coords, float pixel_size, float2 resolution) +{ + return floor(coords / pixel_size) / (resolution / pixel_size); +} + +float2 pixelate(float2 coords, float pixel_size) +{ + return floor(coords / pixel_size) * pixel_size; +} + +/** + * Quantizes the input color to a given resolution. + * + * @param color The input color. + * @param color_resolution The resolution of quantization. + * @return The quantized color. + */ +float3 quantize_color(float3 color, float3 color_resolution) +{ + return floor(color * color_resolution) / (color_resolution - 1.0f); +} + +float4 quantize_color_with_alpha(float4 color, float4 color_resolution) +{ + return floor(color * color_resolution) / (color_resolution - 1.0f); +} + +#endif // PIXELATION_HLSL \ No newline at end of file diff --git a/MainMenu/CalamityMainMenu_Sunken.cs b/MainMenu/CalamityMainMenu_Sunken.cs index 984ae491b6..9df3a95724 100644 --- a/MainMenu/CalamityMainMenu_Sunken.cs +++ b/MainMenu/CalamityMainMenu_Sunken.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using CalamityMod.Effects; using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -74,6 +75,15 @@ namespace CalamityMod.MainMenu public static List Fishes { get; private set; } = []; public static Asset LogoWater => ModContent.Request("CalamityMod/MainMenu/LogoSunken_Water"); + + public static Asset LogoWaterFill => ModContent.Request("CalamityMod/MainMenu/LogoSunken_Water_Fill"); + + public static Asset Perlin => ModContent.Request("CalamityMod/MainMenu/Perlin"); + + public static Asset WorleyInverted => ModContent.Request("CalamityMod/MainMenu/WorleyInverted"); + + private static RenderTarget2D logoWaterFillTarget; + private static RenderTarget2D logoTarget; public int MaxBoids = 120; @@ -96,6 +106,20 @@ namespace CalamityMod.MainMenu public override ModSurfaceBackgroundStyle MenuBackgroundStyle => ModContent.GetInstance(); + public override void SetStaticDefaults() + { + base.SetStaticDefaults(); + + LogoWaterFill.Wait(); + Logo.Wait(); + + Main.QueueMainThreadAction(() => + { + logoWaterFillTarget = new RenderTarget2D(Main.instance.GraphicsDevice, LogoWaterFill.Width(), LogoWaterFill.Height()); + logoTarget = new RenderTarget2D(Main.instance.GraphicsDevice, Logo.Width(), Logo.Height()); + }); + } + public static void ForceMenuStyle() { // Forcefully open this ModMenu if it's the player's first time opening the Sunken Sea Overhaul update. @@ -122,6 +146,8 @@ namespace CalamityMod.MainMenu public override bool PreDrawLogo(SpriteBatch spriteBatch, ref Vector2 logoDrawCenter, ref float logoRotation, ref float logoScale, ref Color drawColor) { + DrawLogoWaterShader(spriteBatch); + // Draw the main background for the menu. DrawMenuBackground(spriteBatch); @@ -140,6 +166,47 @@ namespace CalamityMod.MainMenu return false; } + private static void DrawLogoWaterShader(SpriteBatch sb) + { + sb.End(); + + Main.instance.GraphicsDevice.SetRenderTarget(logoWaterFillTarget); + Main.instance.GraphicsDevice.Clear(Color.Transparent); + + sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity); + + var fillShader = CalamityShaders.SunkenSeaMenuLogoWater.Value; + fillShader.Parameters["uImageSize"]?.SetValue(LogoWaterFill.Size()); + fillShader.Parameters["uTexture0"]?.SetValue(WorleyInverted.Value); + fillShader.Parameters["uBubbleTexture"]?.SetValue(Perlin.Value); + //fillShader.Parameters["uFillAmount"]?.SetValue(0.75f + (MathF.Sin(Main.GlobalTimeWrappedHourly) / 2f) * 0.25f); + fillShader.Parameters["uFillAmount"]?.SetValue(0.75f); + fillShader.Parameters["uWaveStrength"]?.SetValue(2.5f); + fillShader.Parameters["uWaveOffset"]?.SetValue(0.6f); + fillShader.Parameters["uSubtract"]?.SetValue(0.4f); + fillShader.Parameters["uTime"]?.SetValue(Main.GlobalTimeWrappedHourly); + fillShader.Parameters["uFillColor"]?.SetValue(new Color(67, 187, 204, 255 / 2).ToVector4() * 0.7f); + fillShader.Parameters["uEdgeColor"]?.SetValue(new Color(16, 99, 112, 255 / 2).ToVector4() * 0.7f); + fillShader.Parameters["uLineColor"]?.SetValue(new Color(179, 255, 255, 255 / 2).ToVector4() * 0.7f); + fillShader.CurrentTechnique.Passes[0].Apply(); + + sb.Draw(LogoWaterFill.Value, Vector2.Zero, Color.White); + + sb.End(); + + Main.pixelShader.CurrentTechnique.Passes[0].Apply(); + + Main.instance.GraphicsDevice.SetRenderTarget(logoTarget); + Main.instance.GraphicsDevice.Clear(Color.Transparent); + sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Matrix.Identity); + + sb.Draw(logoWaterFillTarget, new Vector2(406, 48), Color.White); + + sb.End(); + Main.instance.GraphicsDevice.SetRenderTarget(null); + sb.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise, null, Main.UIScaleMatrix); + } + private void DrawMenuBackground(SpriteBatch spriteBatch) { Texture2D backgroundTexture = ModContent.Request("CalamityMod/MainMenu/SunkenMenuBackground").Value; @@ -239,6 +306,7 @@ namespace CalamityMod.MainMenu Vector2 drawPos = new Vector2(Main.screenWidth / 2f, 100f); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + spriteBatch.Draw(logoTarget, drawPos, null, drawColor, rotationSecretSeedAdjusted, logoTarget.Size() * 0.5f, WorldGen.drunkWorldGen ? logoScale : 1f, SpriteEffects.None, 0f); spriteBatch.Draw(Logo.Value, drawPos, null, drawColor, rotationSecretSeedAdjusted, Logo.Value.Size() * 0.5f, WorldGen.drunkWorldGen ? logoScale : 1f, SpriteEffects.None, 0f); spriteBatch.Draw(LogoWater.Value, drawPos, null, new Color(255, 255, 255, 0.5f) * 0.7f, rotationSecretSeedAdjusted, Logo.Value.Size() * 0.5f, WorldGen.drunkWorldGen ? logoScale : 1f, SpriteEffects.None, 0f); spriteBatch.End(); diff --git a/MainMenu/LogoSunken_Water.png b/MainMenu/LogoSunken_Water.png index 670fffe66b..12c60ac53f 100644 Binary files a/MainMenu/LogoSunken_Water.png and b/MainMenu/LogoSunken_Water.png differ diff --git a/MainMenu/LogoSunken_Water_Fill.png b/MainMenu/LogoSunken_Water_Fill.png new file mode 100644 index 0000000000..e3a57cf193 Binary files /dev/null and b/MainMenu/LogoSunken_Water_Fill.png differ diff --git a/MainMenu/Perlin.png b/MainMenu/Perlin.png new file mode 100644 index 0000000000..45b02c6b29 Binary files /dev/null and b/MainMenu/Perlin.png differ diff --git a/MainMenu/WorleyInverted.png b/MainMenu/WorleyInverted.png new file mode 100644 index 0000000000..48b63f46aa Binary files /dev/null and b/MainMenu/WorleyInverted.png differ