Palette-Based Drawing System [0.8.7]
IT REQUIRES GM VERSION AFTER 11.07.2015 TO WORK PROPERLY. (That was beta release, but there are few stable releases already)
OR AT LEAST YOU MUST DISABLE CROOPING FOR TEXTURE PAGES. I was wating for stable release so non-pro users can try it as well.
This system allows you to draw pixel art images using palettes.
If you're interested in this, you probably already saw Retro Palette Swap Shader - I wrote latest version of shader for it, and it got some disadvantages:
- You need to change shader's uniforms each time you draw sprite, so it won't allow you to take advantage of vertex batching (that mean poor pefrormance with large number of pal-swapped sprites).
- Shader itself loops though the whole palette for every pixel it draw - that's pretty slow.
That's why I made this system.
- High drawing performance - drawing shader is just a bit slower than normal GM's shader.
- No need to call other functions for drawing - you need only to set proper image_blend value for draw functions.
- Vertex batching - using palettes won't increase draw calls as long as you don't reset the shader (you don't need to set/reset it to use different palette)
- Multiple palette support - allows you to draw sprite using few different palettes. For example, different palettes for skin, clothes and hairs. You can change them separately and take advantage in some other systems as well.
- Palette effects - allows you to apply effects to palettes. Both static and animated effects are supported. Also, it allows you to use palette sprite's image indexes in effects, so you can do some interesting stuff there like lighting effect that applied only to some colors.
- Allows to pretty easily apply effects to tiles.
- Possibly speaking, it can be used with custom drawing systems like lighting engines - one palette can store additional info on shader palette, that can be used in drawing shader (specular map for example).
- Layout system, that allows to do some advanced stuff like placing palettes from different sprites to one palette.
- This system works by indexing your sprites and backgrounds. You know what indexing is? GIFs for example? No? Simply speaking, it replaces colors with their order number from a palette. So, when drawing, you first read index from the image, and then appropriate color from palette image.
- It puts all palettes to shared palette surface so you won't have to change shader's uniforms when drawing. Surface's size is limited, but you can configurate it and it will even automatically expand if you use more palettes then it can store.
- IT DOES NOT SUPPORT MULTIPLE TEXTURE PAGES YET. I can't do anything about it. I reported a bug 2 month ago, but they ignore it.
- As I wrote above, it requires latest stable version to work properly. Why? Because of another old bug I reported finally got fixed - sprite_get_uvs. It lacked information about sprite crooping in older versions, so I could not make a duplicates of existing texture pages. It got a "workaround" by disabling crooping for texture pages, but it was avaiable only to PRO users (at least docs said so) and was a really bad workaround anyway.
- It's not foolproof yet - be careful, since something may break if you use it in a way I did not planned.
- Animated palette effects are relatively heavy yet - use them with care. I got plans on impoving performance, but it won't be so much faster.
- It's slow on startup since it needs to map all sprites/backgrounds in needs. It will be neat to implement some caching system there, but it's hard to make since there are not ways to check if asset is changed or not. I totally want something like asset_get_hash for GM.
- Fixed a rare crash on init when you have some rare symbol in asset filename.
- Fixed a crash when generating palette in latest GM release - there was a type, that created an undefined variable when generating palette. Looks like YYG changed how it behaves - so it crashed.
- Another typo, that did not allow to use YYC (and possible error when using one advanced function). Only GMZ version updated.
- Just noticed I made a really nasty typo in pal_draw_begin function. I don't know why demo worked fine before, lol. That fact it worked was a bug. Well, accodring to download counter, almost noone encountered that bug... sob.
- Support for custom shaders added - you need to register then within system so it will set system's uniforms automatically.
- Added new demo that shows how to use custom shaders.
- Turned on interpolation for palette texture (and also fixed default shader so it will work fine - there were slight offsets everywhere, invisible dues to lack of interpolation)
- Added function, that allows you to switch between subpalettes for drawing. With interpolation support and without any performance hit. Showed usage in advanced demo.
FAQ (At least I predict so):
Q: All sprites are messed up!
A: Update to the latest GM version or turn off crooping in texture pages settings.
Q: Sprites are not drawn!
A: There are few possible reasons:
- You did not mapped/indexed them.
- You did not call pal_update that actually does all the mapping stuff.
- If it were sprites you did not want to be pal-swapped - you probably forgot to call pal_drawing_end when you finished with pal-swapped images.
- You used sprites/background from different texture pages. It's not supported yet. If you want it to be supported - go spam YYG so they make a way to check on which texture page image is.
Q: Sprites are not palette swapped!
A: Did you enable shader with pal_drawing_begin? Maybe you used shader_set somewhere inbetween? If you want to use custom shader along with this system - you must look at how system's shader works first. I think I'll add support to custom shaders later - so you won't have to send system's uniforms to it manually.
Edited by GamerXP, 05 December 2015 - 04:08 PM.