feat: experimental animated water in Y in logo

Co-authored-by: Blockaroz <lbpk.123fan@gmail.com>
This commit is contained in:
Stephen TandBlockaroz authored and Cameron Ewell committed 2025-08-08 19:05:23 -04:00
1 parent 74490aa70f
commit d553111b8e
9 files changed
+190 -1

No files matched your search

+6 -1
View File
@@ -227,13 +227,16 @@ namespace CalamityMod.Effects
internal static Effect UnderwaterRaysShader;
#endregion
internal static Asset<Effect> 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<Effect>($"{ShaderPath}{path}", AssetRequestMode.ImmediateLoad).Value;
Effect LoadShader(string path) => LoadShaderAsset(path).Value;
Asset<Effect> LoadShaderAsset(string path) => calAss.Request<Effect>($"{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
Binary file not shown.
+76
View File
@@ -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 = <uTexture0>;
magfilter = POINT;
minfilter = POINT;
mipfilter = POINT;
AddressU = wrap;
AddressV = wrap;
};
texture uBubbleTexture;
sampler bubbleTex = sampler_state
{
texture = <uBubbleTexture>;
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();
}
}
+40
View File
@@ -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
+68
View File
@@ -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<SunkenFishBoid> Fishes { get; private set; } = [];
public static Asset<Texture2D> LogoWater => ModContent.Request<Texture2D>("CalamityMod/MainMenu/LogoSunken_Water");
public static Asset<Texture2D> LogoWaterFill => ModContent.Request<Texture2D>("CalamityMod/MainMenu/LogoSunken_Water_Fill");
public static Asset<Texture2D> Perlin => ModContent.Request<Texture2D>("CalamityMod/MainMenu/Perlin");
public static Asset<Texture2D> WorleyInverted => ModContent.Request<Texture2D>("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<NullSurfaceBackground>();
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<Texture2D>("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();
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB