+ Palette Swapping
This commit is contained in:
1 parent
368cc6cdda
commit
650fb43660
3 files changed
+39
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
Reference in new issue
Block a user