diff --git a/Effects/Dyes/AuricDyeShader.fx b/Effects/Dyes/AuricDyeShader.fx new file mode 100644 index 0000000000..b960fcdab1 --- /dev/null +++ b/Effects/Dyes/AuricDyeShader.fx @@ -0,0 +1,39 @@ +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; + +float4 PixelShaderFunction(float4 sampleColor : TEXCOORD, float2 coords : TEXCOORD0) : COLOR0 +{ + // Gets a 0-1 representation of the y position on a given frame, with 0 being the top, and 1 being the bottom. + float frameY = (coords.y * uImageSize0.y - uSourceRect.y) / uSourceRect.w; + float twinkleOffset = frac(uTime * 0.51); + + float3 goldColor = float3(228 / 255.0, 175 / 255.0, 72 / 255.0); + float4 noiseColor = tex2D(uImage1, float2(coords.x, sin(3.141 * frac(frameY + twinkleOffset))) * 0.067); + float4 color = tex2D(uImage0, coords); + float shineFactor = pow(noiseColor.r, 0.8); + color *= lerp(0.7, 5, shineFactor); + float3 metalColor = lerp(uColor, uSecondaryColor, shineFactor); + + color.rgb = lerp(color.rgb, metalColor, lerp(0.35, 0.8, shineFactor)); + color.rgb = (length(color.rgb) <= 0.5) ? 2 * color.rgb * goldColor : 1 - 2 * (1 - color.rgb) * (1 - goldColor); + return (color + noiseColor * 0.45) * color.a; +} +technique Technique1 +{ + pass DyePass + { + PixelShader = compile ps_2_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/Dyes/AuricDyeShader.xnb b/Effects/Dyes/AuricDyeShader.xnb new file mode 100644 index 0000000000..043a2aa01f Binary files /dev/null and b/Effects/Dyes/AuricDyeShader.xnb differ diff --git a/ExtraTextures/SharpNoise.png b/ExtraTextures/SharpNoise.png new file mode 100644 index 0000000000..e57ada51fd Binary files /dev/null and b/ExtraTextures/SharpNoise.png differ diff --git a/Items/Dyes/AuricDye.cs b/Items/Dyes/AuricDye.cs new file mode 100644 index 0000000000..09776eaa7f --- /dev/null +++ b/Items/Dyes/AuricDye.cs @@ -0,0 +1,38 @@ +using CalamityMod.Items.Materials; +using CalamityMod.Items.Placeables.Ores; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.Graphics.Shaders; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Items.Dyes +{ + public class AuricDye : BaseDye + { + public override ArmorShaderData ShaderDataToBind => new ArmorShaderData(new Ref(mod.GetEffect("Effects/Dyes/AuricDyeShader")), "DyePass"). + UseColor(new Color(170, 96, 60)).UseSecondaryColor(new Color(226, 196, 106)).SetShaderTexture(ModContent.GetTexture("CalamityMod/ExtraTextures/SharpNoise")); + public override void SafeSetStaticDefaults() + { + DisplayName.SetDefault("Auric Dye"); + } + + public override void SafeSetDefaults() + { + item.rare = ItemRarityID.Purple; + item.Calamity().customRarity = CalamityRarity.Violet; + item.value = Item.sellPrice(0, 9, 0, 0); + } + + public override void AddRecipes() + { + ModRecipe recipe = new ModRecipe(mod); + recipe.AddIngredient(ItemID.BottledWater); + recipe.AddIngredient(ModContent.ItemType(), 5); + recipe.AddTile(TileID.DyeVat); + recipe.SetResult(this); + recipe.AddRecipe(); + } + } +} \ No newline at end of file diff --git a/Items/Dyes/AuricDye.png b/Items/Dyes/AuricDye.png new file mode 100644 index 0000000000..fc17ae5066 Binary files /dev/null and b/Items/Dyes/AuricDye.png differ diff --git a/Utilities/DrawingUtils.cs b/Utilities/DrawingUtils.cs index 4d362d58e2..e9cc64ecde 100644 --- a/Utilities/DrawingUtils.cs +++ b/Utilities/DrawingUtils.cs @@ -469,14 +469,30 @@ namespace CalamityMod } // Cached for efficiency purposes. - internal static readonly FieldInfo UImageField = typeof(MiscShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); + internal static readonly FieldInfo UImageFieldMisc = typeof(MiscShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); + internal static readonly FieldInfo UImageFieldArmor = typeof(ArmorShaderData).GetField("_uImage", BindingFlags.NonPublic | BindingFlags.Instance); /// /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. /// /// The shader to bind the texture to. /// The texture to bind. - public static void SetShaderTexture(this MiscShaderData shader, Texture2D texture) => UImageField.SetValue(shader, new Ref(texture)); + public static MiscShaderData SetShaderTexture(this MiscShaderData shader, Texture2D texture) + { + UImageFieldMisc.SetValue(shader, new Ref(texture)); + return shader; + } + + /// + /// Manually sets the texture of a instance, since vanilla's implementation only supports strings that access vanilla textures. + /// + /// The shader to bind the texture to. + /// The texture to bind. + public static ArmorShaderData SetShaderTexture(this ArmorShaderData shader, Texture2D texture) + { + UImageFieldArmor.SetValue(shader, new Ref(texture)); + return shader; + } public static void EnterShaderRegion(this SpriteBatch spriteBatch) {