diff --git a/Effects/Dyes/ExoDyeShader.fx b/Effects/Dyes/ExoDyeShader.fx new file mode 100644 index 0000000000..763efe3d25 --- /dev/null +++ b/Effects/Dyes/ExoDyeShader.fx @@ -0,0 +1,69 @@ +sampler uImage0 : register(s0); +sampler uImage1 : register(s1); +float3 uColor; +float3 uSecondaryColor; +float uOpacity; +float uSaturation; +float uRotation; +float uTime; +float4 uSourceRect; +float2 uWorldPosition; +float uDirection; +float3 uLightSource; +float2 uImageSize0; +float2 uImageSize1; +float3 specialPalette[9] = +{ + float3(250, 255, 112) / 255.0, + float3(211, 235, 108) / 255.0, + float3(166, 240, 105) / 255.0, + float3(105, 240, 220) / 255.0, + float3(64, 130, 145) / 255.0, + float3(145, 96, 145) / 255.0, + float3(242, 112, 73) / 255.0, + float3(199, 62, 62) / 255.0, + float3(250, 255, 112) / 255.0, +}; + +float InverseLerp(float from, float to, float x) +{ + return saturate((x - from) / (to - from)); +} + +// Multi-color lerp which uses the palette. +float3 PaletteLerp(float interpolant) +{ + float startingIndex = floor(interpolant * 8); + float squashedInterpolant = frac(interpolant * 8); + return lerp(specialPalette[startingIndex], specialPalette[startingIndex + 1], squashedInterpolant); +} + +// (Co)sines use a lot of instructions. As such, a more linear wave constructed by moduli is used instead. +// Is this kind of ridiculous? Probably. But there's basically nothing I can do until 1.4 rolls around +// and the pathetically low instruction count cap is increased significantly. -Dominic +float FastPeriodicFunction(float x) +{ + if (x % 2 < 1) + return x % 2; + return -(x % 2) + 2; +} + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float4 noiseColor = tex2D(uImage1, float2(coords.x, frameY - uTime * 0.45) * 0.1); + float4 color = tex2D(uImage0, coords); + float3 blendColor = PaletteLerp(frac(frameY + uTime * 1.3)); + float blendFactor = (FastPeriodicFunction(uTime * 9 + coords.x * 2 - frameY * 2.1) * 0.5 + 0.5) * 0.5; + float brightness = (blendFactor * 0.4 + noiseColor.r * 0.9) * 1.2; + + float4 colorBlendMultiplier = lerp(float4(blendColor, 1), float4(1, 1, 1, 1), saturate(blendFactor * 1.5)); + return (lerp(color, float4(blendColor, 1), blendFactor * 0.5 + 0.2) * color.a) * colorBlendMultiplier * (1 + brightness); +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/ExoDyeShader.xnb b/Effects/Dyes/ExoDyeShader.xnb new file mode 100644 index 0000000000..87e8fad776 Binary files /dev/null and b/Effects/Dyes/ExoDyeShader.xnb differ diff --git a/Items/Dyes/ExoDye.cs b/Items/Dyes/ExoDye.cs new file mode 100644 index 0000000000..1e2f58d72c --- /dev/null +++ b/Items/Dyes/ExoDye.cs @@ -0,0 +1,39 @@ +using CalamityMod.Items.Materials; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Dyes +{ + public class ExoDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind + { + get => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/ExoDyeShader")), "DyePass").UseImage("Images/Misc/Perlin"); + } + + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Exo Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.value = Item.sellPrice(0, 10, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater, 3); + recipe.AddIngredient(ModContent.ItemType()); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this, 3); + recipe.AddRecipe(); + } + } +} diff --git a/Items/Dyes/ExoDye.png b/Items/Dyes/ExoDye.png new file mode 100644 index 0000000000..6cc8ebfeec Binary files /dev/null and b/Items/Dyes/ExoDye.png differ