Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Dynamic palette?
- - By lol_o2 Date 2012-02-26 09:30
Is it possible to make in Gosu some dynamic palette swapping? I know now there's no method for it, but is it doable in future? I mean loading a new palette to a Gosu::Image object from a .pal file or another image. I think it can be done with indexed images and would be very useful for me. So?
Parent - - By jlnr (dev) Date 2012-02-26 14:08
This is not a common feature in OpenGL-based libraries because OpenGL does not work with palettes in its textures. I think the best way to achieve this would be via shaders. Shader support is definitely something I'd love to support more in Gosu, but I am not an expert on them. :/
But is this the use case you would be going for? Having a few images where you vary the color spectrum in real-time? If you just need to load the same image with different palettes, this could be done in the file-to-bitmap loading phase, and even in an external library.

Oh, hacky idea: You can probably also use Image#to_blob and regexps to achieve the same thing relateively efficiently in Ruby, then Image#insert the blob back in...
Parent - - By lol_o2 Date 2012-02-26 14:33
Oh, I'd need it to be fast enough to not lag too much when used per few frames.
Well, it could just speed up loading time of my game, because I have 121 images in 8 different color schemes. I don't need it so much.
Parent - - By jlnr (dev) Date 2012-02-26 15:10
Can you separate the colored portion from the "constant" porton and draw the colorful parts with a color modifier? That would probably be faster than using shaders for lots of images (and work already :) ). I think we've had this topic on IRC recently.
Parent - By lol_o2 Date 2012-02-26 18:24
I could do this, but it's much work for separating it and it wouldn't look as good. Well, if it's impossible to make it fast, I can live with that :)
Parent - By Spooner Date 2012-02-26 18:23
TexPlay could do the same thing massively faster; it still wouldn't be good speed for per-frame manipulation though.
- - By lol_o2 Date 2013-11-22 14:54
It's been a long time, but yesterday I tried to make some reasonable solution and I managed to make it with Ashton (isn't it a great library? :)
The method duplicates an image in a recolored version by using another image as a 'palette definition'. Previously I used Texplay, but this one is about 20 times faster and can make a recolored copy with no lag.
I achieved this by making a proper shader. Editing Ashton's shader.rb was required to make it work.

I'm attaching an example, which includes the method, shader and modified shader.rb
Maybe someone will find it useful
Attachment: Re-Palette.zip (9k)
Parent - - By Spooner Date 2013-11-23 00:58
Is it something that should be in shader.rb or something that breaks normal shader usage? If so, do you want to submit a pull request?
Parent - By lol_o2 Date 2013-11-23 09:37 Edited 2013-11-23 09:56
I removed the 4-element limit for arrays and defined ones for Gosu::Color. Basically it allows to use array of vec4 as uniform.
Maybe I'll submit a pull request.
EDIT: Done.
Up Topic Gosu / Gosu Exchange / Dynamic palette?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill