+ Palette Swapping

This commit is contained in:
Big E authored and doze-zoze committed 2026-04-07 18:11:48 -05:00
1 parent 368cc6cdda
commit 650fb43660
3 files changed
+39

No files matched your search

+4
View File
@@ -261,6 +261,7 @@ namespace CalamityMod.Effects
internal static Asset<Effect> SeaPrismColorBlendingShader;
internal static Asset<Effect> Dissolve;
internal static Asset<Effect> PaletteSwap;
internal static Asset<Effect> 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
+35
View File
@@ -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();
}
}
Binary file not shown.