

This means that on your source sprite, the background color needs to be transparent. The outline is determined by sampling the alpha values of the pixels surrounding each pixel, which is then passed through some functions that make the outline pixels the desired color, and set their alpha to 1.
GODOT PALETTE SWAP CODE
(Also, disable 'alpha border fix' when importing your sprites) A Godot shader to replace one colour in a palette with another (with a mask support for additional colours) Raw Godot Palette Replacement Shader.md You must create a palette of colours and set them to the shader's parameters before use in the manner used by the Sprite script source code palette.gd Raw palette-replace.
GODOT PALETTE SWAP MANUAL
This can take some manual tweaking, but it works fine for me with 16 colors. So, the leftmost palette color would have a red value of 0, the rightmost a red value of 1, and values in the middle would be at other arbitrary red values. Your actual sprite should have a palette consisting of shades of red, with each red value corresponding to a UV position on the palette texture. At least one pixel needs to be completely transparent, assuming you need your sprite to have a transparent bg. Using found alpha value, determine the opacity of the outlineĬol.rgb = mix(outline_col.xyz, col.rgb, col.a) įirst, the palette should be a texture 1 pixel tall, and as many pixels wide as colors you need. Vec4 col = texture(palette_tex,vec2(pal_sample,0)) įloat a = texture(TEXTURE,UV+vec2(p.x,0)).a Get red value and sample palette based on itįloat pal_sample = texture(TEXTURE,UV).r Uniform vec4 outline_col : hint_color //Outline color Uniform sampler2D palette_tex //Palette to reference, this should be a 1-pixel tall texture containing your palette info I figured other people could find this useful, so here's the source code and a brief explanation shader_type canvas_item In this example, the feet of the dragon are semi-transparent where they meet the leg so that whichever color I make the body or feet, they'll blend together naturally.This is a shader I wrote for my platform fighting game, which lets me outline sprites and apply a palette to them. Some of my sprite sheets have semi-transparent pixels. (btw, there's also a tool to help make palettes for use with this shader found here: ! Not related to my issue but its been very useful on this project) New_color.a *= a //if BG is transparent, then alpha is multiplied by 0ĬOLOR = new_color //set new color from palette Vec4 new_collor = texture(palette, vec2(color.r, y)) //get color from palette textureįloat a = step(0.00392, color.a) //check if transparent color is less than 1/255 for backgrounds Vec4 color = texture(TEXTURE, UV) //Original graysscale color used as collumn index Uniform float palette_index = 0.0 //Telss the shader which palette to chooseįloat increment = 1.0/palette_count //Value for getting palette indexįloat y = increment * palette_index + increment * 0.5 // + safety measure for floating point imprecision Uniform float palette_count = 1.0 //Tells the shader how many palettes you have

Uniform sampler2D palette //Uses palletes with colors in rows Render_mode unshaded, blend_disabled // no bells and wistles I'm currently using NeZvers Studio's sprite palette swap shader, found here shader_type canvas_item //2D shader Very little experience with shaders here and also no expert in Godot in general.
