Jump to content


Photo

Palette-Based Drawing System v.0.8.7 [26.11.2015]

gm:studio shader

  • Please log in to reply
17 replies to this topic

#1 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 11 July 2015 - 07:54 AM

Palette-Based Drawing System [0.8.7]
 
Important:
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.

 

Marketplace Link
 
Description:
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.
 
Features:

  • 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.

About system:

  • 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.

Screenshots:
Scr1.pngScr2.pngScr3.png
Scr4.png
 
Terms of usage:
It's free for non-commercial usage and playing around.
I'll make a paid marketplace entry later.
 
Download:
Demo EXE
GMZ Demo with Extension included
 

Changelog:

[0.8.7]

  • 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.

[0.8.5]

  • Another typo, that did not allow to use YYC (and possible error when using one advanced function). Only GMZ version updated.

[0.8.4]

  • 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.

[0.8.3]

  • 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.

[0.8]

Initial Release

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.

  • 4

#2 gadgetmawombo

gadgetmawombo

    GMC Member

  • GMC Member
  • 330 posts
  • Version:Unknown

Posted 16 July 2015 - 03:29 AM

It looks pretty good but im already too invested with the way that retro palette swapper works to dig through my code again. Some of this stuff sounds pretty cool, like the multi
multi palette system. But i already implemented something like that in my game by using surfaces to combine multiple palettes into one at the start of the game and using that as the palette sprite. Anyway theres a few other things that look interesting, and i cant argue with better performance! I might change my system to use this once it has a few more updates.
  • 0

Merv%20combo_zpsklyiqgwb.gif

39134.png


#3 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 18 July 2015 - 01:55 PM

Version 0.8.3 released.

 

Changes:

  • 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.

Download:
Demo EXE
GMZ Demo with Extension included


  • 0

#4 gadgetmawombo

gadgetmawombo

    GMC Member

  • GMC Member
  • 330 posts
  • Version:Unknown

Posted 03 August 2015 - 11:53 PM

So I finally got around to playing with the demo. It really seems good so far, the performance is the big deal maker for me, my game is intensive enough so any little boosts to performance I can get are worth the effort. The only problem with this so far is that it crashes with the YYC, on the windows platform. I don't know about the other platforms but the windows one works but windows YYC will not so that's an issue for me since the compiler gives my game almost triple the performance! Here is the error report:

 

In Script pal_map_action at line 41 : using uninitialised variable 'pal_apply_mode_merge_group'

In Script pal_map_action at line 41 : using uninitialised variable 'pal_apply_mode_merge_tag'
Compile Failed - Please check the Compile window for any additional information
    

PS: I really like that scrolling star effect you have in the last demo!


  • 0

Merv%20combo_zpsklyiqgwb.gif

39134.png


#5 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 04 August 2015 - 09:22 AM

It seems I forgot to rename something somewhere. Normal GM does not throw errors about unknown variables till you use them, and YYC version does. Allright. I'll try compliing it for YYC and upload fixed version later.


  • 0

#6 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 07 August 2015 - 02:41 PM

Fixed that YYC error. Yep, another typo. Reuploded GMZ version with fix. But it will be easier to fix that yourself - you just need to rename those variables - they got name beginning changed. Just look at similiar variables used nearby.


  • 0

#7 gadgetmawombo

gadgetmawombo

    GMC Member

  • GMC Member
  • 330 posts
  • Version:Unknown

Posted 08 August 2015 - 09:59 PM

Is Retro Palette Swapper still using your shader? So basically I'm using that system and I recently got the game working on Android, both regular and YYC. But the problem is that this shader makes my sprites (and vector art with the vector version of the shader) a solid white for some reason. If this system you've developed uses the same shader then switching to it probably wouldn't solve the issue, would it?


  • 0

Merv%20combo_zpsklyiqgwb.gif

39134.png


#8 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 09 August 2015 - 05:16 AM

Retro Palette is using my shader, but it's a bit different shader used in this system. Though, it was based on it. Can't say if using this shader will fix your issude - why won't you try compiling the demo under Android? I don't have a device so I can't test it.

 

Anyway, about your game. You can't use this system for vector sprites. Because even if they use actual textures - they still are on separate texture pages, and this system does not supports them yet. And I can't do much about it now. You can use this system for sprite, and Retro Palette Swapper for vector sprite though - they use pretty much same palette image except you can use multiple palettes with my system.


  • 0

#9 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 11 October 2015 - 09:45 AM

Uploaded it on marketplace. Just so if someone is actually going to buy it. Not going to be as cheap as Sprite Analyzer since so few people are actually using it.

 

And, no changes this time. Latest 0.8.5 version is on marketplace now. Is someone got suggestions though...


  • 0

#10 poshu

poshu

    GMC Member

  • New Member
  • 9 posts
  • Version:GM:Studio

Posted 13 October 2015 - 10:24 PM

Btw, the marketplace version is lacking all the extention macro, otherwise, it's a great ressource :D


  • 0

#11 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 14 October 2015 - 04:17 AM

Oops. Sorry for inconvinience. Reuploded it on marketplace.

 

Thanks you for buying it by the way.


  • 0

#12 goresoft

goresoft

    GMC Member

  • GMC Member
  • 161 posts
  • Version:GM:Studio

Posted 02 November 2015 - 02:09 PM

how about tiles?

Can i use your shaders for them?


  • 0

Portfolio :  ASTRO n. z. o. (HTML5)--||||--Fly Chris Fly!!(Android)--|||--ICY BERG (Windows) 

Facebook page : Blue Vessel Games 
 
Twitter : @bluevesselgames


#13 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 02 November 2015 - 03:06 PM

Yep. Should have made it more clear in the demo.

See that room with tiles of demo's screenshots? If you press Space in it - palette effects are applied to those tiles.


  • 0

#14 ahlisen93

ahlisen93

    GMC Member

  • New Member
  • 12 posts
  • Version:GM:Studio

Posted 17 November 2015 - 02:41 PM

Hello!

 

I have a quick question about: pal_fx_blink();

 

When I use it to create a flash on a character all the other characters in the area become white aswell but never change back to their original palette.

It seems to be random, sometimes its all of them and sometimes only a few.

 

Have you encountered this? Maybe I need to specify something?

 

Thanks in advance!


  • 0

#15 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 17 November 2015 - 02:47 PM

Well, that sounds weird. Especially never returning part. Can you show the code you used?

pal_palette_select(palette_index);
pal_fx_blink( c_white, 1, 40, 20);

It should be used this way once when effect is applied. pal_palette_select is usually unnecessary though, but I put it just in case


  • 0

#16 jangsy76

jangsy76

    GMC Member

  • GMC Member
  • 4 posts
  • Version:GM:Studio

Posted 23 November 2015 - 08:37 AM

Hello.

I just bought your drawing system and copied some setup from your demo but I got this kind of fatal error.

With Destroy event I got this.

 

############################################################################################
FATAL ERROR in
action number 1
of Destroy Event
for object obj_hero:

Push :: Execution Error - Variable Get 100002.palette_index(100473, -2147483648)
 at gml_Object_obj_hero_DestroyEvent_1 (line 2) - pal_palette_destroy( palette_index );

 

############################################################################################

 

 so I removed it then got this.

 

 

############################################################################################
FATAL ERROR in
action number 3
of Create Event
for object obj_hero:

Push :: Execution Error - Variable Get -5.sPal_maps(100359, -2147483648)
 at gml_Script__pal_map_get (line 3) - var map = ds_list_find_value(sPal_maps, argument[0]);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script__pal_map_get (line 3)
called from - gml_Script__pal_get_group (line 1) - ///_pal_get_group(group/sprite_index)
called from - gml_Script_pal_palette_create (line 7) - var group = _pal_get_group(argument0);
called from - gml_Object_obj_hero_CreateEvent_3 (line 3) - palette_index = pal_palette_create(sprite_index);

############################################################################################

 

Could you tell me what shoud I do ?

Thanks.


  • 0

#17 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 23 November 2015 - 09:08 AM

First error. Probably palette_index variable does not exists? It's not built-in variable.

 

Second one... hmm... it seems it can't find global variable sPal_maps. Did you initiated system properly? This variable is declared in pal_init function, which should be used from some global controller object.

Problem may be in Create events order - your Hero object could be created before controller object. You should try to edit Room Creation order and move controller object at the beginning. OR do like I do - make a preload room, where you create all controller objects, and then move to the next room right after that - this way you're always sure to init everything before play.

 

If you can't find the problem - I can look at it. Just PM me your project or example.


  • 0

#18 GamerXP

GamerXP

    GMC Member?

  • GMC Member
  • 443 posts
  • Version:GM:Studio

Posted 26 November 2015 - 02:36 PM

When checking jangsy76's problem - found 2 bugs. One is rare one with asset names, and one is certain-kill one that appeares only in latest GM version. Updates both marketplace asset and GMZ link.


  • 0





Also tagged with one or more of these keywords: gm:studio, shader