diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 1b283d531c..480806437e 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -216,6 +216,9 @@ namespace CalamityMod.Effects #region fryzahh's Shaders // A simple shader which distorts an image using a provided texture of choice. internal static Effect BasicTextureDistortionShader; + + // The underwater rays seen at the top of the Sunken Sea Mod Menu. + internal static Effect UnderwaterRaysShader; #endregion public override void PostSetupContent() @@ -429,6 +432,9 @@ namespace CalamityMod.Effects #region Loading fryzahh's Shaders BasicTextureDistortionShader = LoadShader("BasicTextureDistortionShader"); RegisterMiscShader(BasicTextureDistortionShader, "DistortionPass", "BasicTextureDistortion"); + + UnderwaterRaysShader = LoadShader("UnderwaterRaysShader"); + RegisterMiscShader(UnderwaterRaysShader, "UnderwaterRayPass", "UnderwaterRays"); #endregion } diff --git a/Effects/UnderwaterRaysShader.fx b/Effects/UnderwaterRaysShader.fx new file mode 100644 index 0000000000..652afbcca4 --- /dev/null +++ b/Effects/UnderwaterRaysShader.fx @@ -0,0 +1,48 @@ +sampler baseTexture : register(s0); + +float time; +float fadeOutMargin; +float overallOpacity; +float pixelationAmount; +float scrollSpeedX; +float scrollSpeedY; +float2 noiseScale; +float3 rayColor; + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR0 +{ + // Pixelation. + coords = round(coords * pixelationAmount) / pixelationAmount; + + // Distort the coords into a sine wave. + coords.y += sin(coords.x + time * 0.25) * 0.05; + + // Get the correct scale for our two noise maps. + float2 scaledCoords = coords * noiseScale; + + // Calculate the offsets for each noise map. + float2 noiseOffset1 = float2(time * scrollSpeedX, time * scrollSpeedY); + float2 noiseOffset2 = float2(time * -scrollSpeedX, time * -scrollSpeedY); + + // Calculate the colors of the two noise maps. + float4 noiseTexture1 = tex2D(baseTexture, scaledCoords + noiseOffset1); + float4 noiseTexture2 = tex2D(baseTexture, scaledCoords + noiseOffset2); + + // Add the noise maps together to layer them over each other. + // Ensure to add them at 50% intensity to avoid making a super bright effect. + float combinedNoise = (noiseTexture1.r * 0.5) + (noiseTexture2.r * 0.5); + + // Fade out at a certain margin. + float opacity = (1 - (coords.y * 2 - fadeOutMargin)); + + return (float4(rayColor, 1) * combinedNoise * opacity) * overallOpacity; + +} + +technique Technique1 +{ + pass UnderwaterRayPass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} diff --git a/Effects/UnderwaterRaysShader.xnb b/Effects/UnderwaterRaysShader.xnb new file mode 100644 index 0000000000..9faf1094f5 Binary files /dev/null and b/Effects/UnderwaterRaysShader.xnb differ diff --git a/MainMenu/CalamityMainMenu_Sunken.cs b/MainMenu/CalamityMainMenu_Sunken.cs index d09914e541..8e0f95b5d9 100644 --- a/MainMenu/CalamityMainMenu_Sunken.cs +++ b/MainMenu/CalamityMainMenu_Sunken.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.Graphics.Shaders; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Default; @@ -55,12 +56,12 @@ namespace CalamityMod.MainMenu // Before drawing the logo, draw the entire Calamity background. This way, the typical parallax background is skipped entirely. public override bool PreDrawLogo(SpriteBatch spriteBatch, ref Vector2 logoDrawCenter, ref float logoRotation, ref float logoScale, ref Color drawColor) { - Texture2D texture = ModContent.Request("CalamityMod/MainMenu/SunkenMenuBackground").Value; + Texture2D backgroundTexture = ModContent.Request("CalamityMod/MainMenu/SunkenMenuBackground").Value; // Calculate the draw position offset and scale in the event that someone is using a non-16:9 monitor Vector2 drawOffset = Vector2.Zero; - float xScale = (float)Main.screenWidth / texture.Width; - float yScale = (float)Main.screenHeight / texture.Height; + float xScale = (float)Main.screenWidth / backgroundTexture.Width; + float yScale = (float)Main.screenHeight / backgroundTexture.Height; float scale = xScale; // if someone's monitor isn't in wacky dimensions, no calculations need to be performed at all @@ -71,15 +72,54 @@ namespace CalamityMod.MainMenu if (yScale > xScale) { scale = yScale; - drawOffset.X -= (texture.Width * scale - Main.screenWidth) * 0.5f; + drawOffset.X -= (backgroundTexture.Width * scale - Main.screenWidth) * 0.5f; } else // The opposite is true if someone's monitor is widescreen - drawOffset.Y -= (texture.Height * scale - Main.screenHeight) * 0.5f; + drawOffset.Y -= (backgroundTexture.Height * scale - Main.screenHeight) * 0.5f; } + + // Distort the background slightly to make it appear as if it's properly underwater. + MiscShaderData distortionShader = GameShaders.Misc["CalamityMod:BasicTextureDistortion"]; + Asset distortionTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Swirls"); + spriteBatch.End(); // BLESS THIS. + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + + distortionShader.Shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + distortionShader.Shader.Parameters["distortionXSpeed"].SetValue(-0.012f); + distortionShader.Shader.Parameters["distortionYSpeed"].SetValue(0.015f); + distortionShader.Shader.Parameters["distortionStrength"].SetValue(0.02f); + distortionShader.Shader.Parameters["noiseScale"].SetValue(0.75f); + distortionShader.SetShaderTexture(distortionTexture); + distortionShader.Apply(); + + spriteBatch.Draw(backgroundTexture, drawOffset, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + + // Draw rays shining down from the top of the screen. + MiscShaderData underwaterRaysShader = GameShaders.Misc["CalamityMod:UnderwaterRays"]; + Asset underwaterRayTexture = ModContent.Request("CalamityMod/ExtraTextures/GreyscaleGradients/Pebbles"); + + spriteBatch.End(); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); + + underwaterRaysShader.Shader.Parameters["time"].SetValue(Main.GlobalTimeWrappedHourly); + underwaterRaysShader.Shader.Parameters["fadeOutMargin"].SetValue(0.58f); + underwaterRaysShader.Shader.Parameters["overallOpacity"].SetValue(1f); + underwaterRaysShader.Shader.Parameters["pixelationAmount"].SetValue(Main.screenWidth * 0.5f); + underwaterRaysShader.Shader.Parameters["scrollSpeedX"].SetValue(0.013f); + underwaterRaysShader.Shader.Parameters["scrollSpeedY"].SetValue(0.006f); + underwaterRaysShader.Shader.Parameters["noiseScale"].SetValue(new Vector2(1.25f, 0.25f)); + underwaterRaysShader.Shader.Parameters["rayColor"].SetValue(Color.LightSkyBlue.ToVector3()); + underwaterRaysShader.Apply(); + + spriteBatch.Draw(underwaterRayTexture.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Color.White); + + spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, Main.Rasterizer, null, Main.UIScaleMatrix); - spriteBatch.Draw(texture, drawOffset, null, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0f); static Color selectBubbleColor() {