![]() Var palette_size = 0 setget _set_palette_size Here the piece of code which does that: extends AnimatedSpriteĮxport(SpriteFrames) var color_mask = nullĮxport(int) var palette_index = 0 setget _set_palette_index With this you already loaded the required textures so no more disk read. Also the script does the same for palettes. Palette_size = 4 (This value needs to be normalized for match the godot color values between 0.0 and 1.0, that is the /255 on the formula)Ġ,007843137254902/(4/255) = 0,5000000000000007 ~ 0,5 which results on the color two of our palette (look at the image on top is cyan)Īll this looks good now, but what about the implications of change textures on the fly from disk on the shader, for example an animation player directly change textures?įor that I created a simple script to automatically update the animation frames with animation frame mask using a SpriteFrames, so is the same process as loading the frames for animated sprite, a requirement is those needs to match, so if one of your animations has 5 frames, you need the 5 same frames masked. Mask_color.r = 0,007843137254902 (remember godot shaders return normalized (0.0-1.0) colors, this number here is the "2" from current_color normalized automatically by godot (2/255)) Note: I only use the red channel for my calculations because on a greyscale images the three channels are the same value.Īnd for the translation basically the formula (mask_color.r/(palette_size/255)) is transform 0.0/1.0 values to palette UV.x ones, also remember UV values are between 0.0 and 1.0 too. Then for each non white pixel (255,255,255) on the image I apply the mask vs palette translation The total size of the palette (image width) Then the shader where the magic happens: uniform texture palette Megaman cyan color is 2,2,2 which is index 2 on paletteĪnd then the palettes, because I need only 3 colors I created my palette of 4x1 pixels, more colors to map, the bigger the palette. Megaman blue color is 1,1,1 which is index 1 on palette Megaman black color is 0,0,0 which is index 0 on palette They are greyscale images without alpha where each color is represented by a correlative number and then this number represents the color index on the palette: This solution only requires a greyscale mask for each frame and the palette textures which saved on the correct format are a minimal memory overheadįirst you need a mask which represent the areas that change color for map on the palette, on my example these are like this: UPDATE, Now this work perfect on Intel GPUS, blame bad precision on intel gpus for uniform float vars.Īlso use ASEPRITE for generate the greyscale mask, Photoshop alters the palette on saveĪfter playing a bit with godot I found maybe the best solution for this problem without using if for each color or a loop: To everyone finding this post useful and willing to use this code, feel free to do so as you wish! answered by Alex\doc ( 109 points) I'm mot sure if you can actually use this shader per-instance, but might be useful anyway. ![]() Where test_col is a mask color that you use only for mask-testing, for instance (1.0,0.0,1.0) and new_col is the color you will replace the mask with. the new texture color is now new_color * diff if the difference is less than our threshold calculate the difference between our color and test color Uniform color test_col //the color to test against ![]() To obtain the 2-bit value, the bits must be extracted as shown in the following table (where -H is the high bit and -L is the low bit, for each colour.The only way I have in mind is by doing a shader like this: uniform texture in_tex //input texture To convert from an EGA palette to RGB values, each 2-bit EGA red, green or blue value should be multiplied by 85, to produce the values 0, 85, 170 and 255. In this case, the palette file is only 16 bytes long. Setting palette entry #6 to the in-sequence value of 6 ( #AAAA00) instead of 20 reveals the "dark yellow" colour found in cheaper clone CGA monitors lacking the additional circuitry.Īs there are 16 colours to change, it is easiest to write these values out as 16 bytes. This is because the CGA had additional circuitry to make this colour appear "more visually pleasing." The introduction of the EGA palette meant this adjustment no longer required additional hardware. Notice that colour entry #6 (brown) doesn't fit in sequence with the other entries. This is set up to be backwards-compatible with the 16 colours available in text mode on the original CGA. The default EGA palette found in most DOS games is shown on the right. Default Palette Default EGA 16-Color Palette ![]()
0 Comments
Leave a Reply. |