From 650fb436607c041f6660f3f5ccbe4db11e734095 Mon Sep 17 00:00:00 2001 From: Big E Date: Sun, 4 Jan 2026 18:26:53 -0500 Subject: [PATCH] + Palette Swapping --- Effects/CalamityShaders.cs | 4 ++++ Effects/PaletteSwap.fx | 35 +++++++++++++++++++++++++++++++++++ Effects/PaletteSwap.xnb | Bin 0 -> 2876 bytes 3 files changed, 39 insertions(+) create mode 100644 Effects/PaletteSwap.fx create mode 100644 Effects/PaletteSwap.xnb diff --git a/Effects/CalamityShaders.cs b/Effects/CalamityShaders.cs index 0e06aeef01..c97027ab00 100644 --- a/Effects/CalamityShaders.cs +++ b/Effects/CalamityShaders.cs @@ -261,6 +261,7 @@ namespace CalamityMod.Effects internal static Asset SeaPrismColorBlendingShader; internal static Asset Dissolve; + internal static Asset PaletteSwap; internal static Asset BrainOfCthulhuForcefield; #endregion @@ -525,6 +526,9 @@ namespace CalamityMod.Effects Dissolve = LoadShader("Dissolve"); RegisterMiscShader(Dissolve, "DissolvePass", "Dissolve"); + PaletteSwap = LoadShader("PaletteSwap"); + RegisterMiscShader(PaletteSwap, "PaletteSwapPass", "PaletteSwap"); + BrainOfCthulhuForcefield = LoadShader("ScreenShaders/BrainOfCthulhuForcefield"); RegisterScreenShader(BrainOfCthulhuForcefield, "BoCShieldPass", "BrainOfCthulhuForcefield"); #endregion diff --git a/Effects/PaletteSwap.fx b/Effects/PaletteSwap.fx new file mode 100644 index 0000000000..2de436b8cd --- /dev/null +++ b/Effects/PaletteSwap.fx @@ -0,0 +1,35 @@ +sampler baseTexture : register(s0); + +float4 sourcePalette[16]; +float4 targetPalette[16]; +float matchThreshold = 0.01; +int paletteSize; + +float4 PixelShaderFunction(float4 sampleColor : COLOR0, float2 coords : TEXCOORD0) : COLOR +{ + float4 color = tex2D(baseTexture, coords) * sampleColor; + + // Check each color in the source palette + for (int i = 0; i < paletteSize; i++) + { + float3 diff = color.rgb - sourcePalette[i].rgb; + float distance = sqrt(dot(diff, diff)); + + // If color is close enough to this palette color, swap it + if (distance <= matchThreshold) + { + color.rgb = targetPalette[i].rgb; + break; // Stop checking once we find a match + } + } + + return color; +} + +technique Technique1 +{ + pass PaletteSwapPass + { + PixelShader = compile ps_3_0 PixelShaderFunction(); + } +} \ No newline at end of file diff --git a/Effects/PaletteSwap.xnb b/Effects/PaletteSwap.xnb new file mode 100644 index 0000000000000000000000000000000000000000..742449fa6d836c4acd755fc77f535116ffbf5e95 GIT binary patch literal 2876 zcmeH|&u`pB6vv;vzucr`!|worx=jSFSXOD8pj2wqkO&%yf z1WwC+4nc4PX?v?S{S$gf??@csz@Y~pIQGB+E;Zjb_BPIr_zTMHe(m=@els4wH)C&o zy1HL5u8k8J-y5Ga>%JFwyJ2;!?N&eX-954I`FE;oUON=+u=?TduBeB%gu5gBiv3^F zH+;9#Xx4*@{kiairq^CxsLt`PVy|^uVb>SSZP5*Vw^gw>y4$U0{bTV>&ATJo%S#LM z_1&dyad}59&MhupA#TQxV?@7>KYlQ&+~i=KiJw$*iH*yYho%$v>G3SAZ8s1#alm&a z4mY56KA`b<+%I(*J+o~BPab$(zb-c1mIy-uf0(ZWGfB(;`8ru1oUhRJzY^i;d~wA6 zG+%7<+G36UHgm0v^PU^l8?}Znf`-@HAsU808XB2CFp1Z2C#lG0^IM_D;&FK0W*gTg zoyq3D+u3k~fUv2lChCoL^Xsm-Op^upJQuDj-;T$af`+XEV}0o0`~`v!xI@|`I^E06 z^BDFY8Gkz6kKDz|*gvHG|3d8JG(Iyd#c0EO+$+M$#qpE)XIiU$u*!S-I`;wN`KNo_ zUIObeh73H7#F^VqkV&?B&ik+*K)*nIKi2QipU~eB56gM8aAArCV1h8a2%A~<{gFpC z4D~|*+DI*rcsAMVT=OI{IcDp~cgn^N<9LqTPVdE|BSVdyS941up6%o5y{G4=6WqRX zdybxdqwI^fF4^lhH*eaT4gP%DYu;X`*@AJkI{$w4>f(HLeraKWJ|iler*a>w>zJqy z9Yc?fnO{(x9%9u%HZ=E;`HbQ#@He0@p^oCSN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