[Solved] Coloring a gray image

I tought this was turned down :o Thanks anyway :slight_smile:

Can you describe in what way you want to colorize the image? Do you want to programmatically assign predefined colors to specific gray colors (something you would do in Gimp/Photoshop by replacing color by color with the “fill-all-occurences-of-color-xy-Tool”)?

Obwohl viele im Forum Java nicht unbedingt wohlgesonnen gegenĂŒberstehen, findest du gerade bezĂŒglich Shader-Programmierung auf http://zfx.info sehr kompetente deutschsprachige Hilfe :). Auf englisch profitieren aber natĂŒrlich ggf. mehr Leute von deinen Problemstellungen :).

Here’s cylab’s solution in a shader
untested and in Cg rather than GLSL:


float4 
main(float2            uv  : TEXCOORD,
     uniform sampler2D map : TEXUNIT0,
     uniform float3 refColor): COLOR
{
  float4 c = tex2D(map, uv);
  
  c.rgb *= refColor.rgb;

  return c;
}


Actually, for the moment forget everything we’ve all said and see if the easiest solution is good enough. Just render the grayscale texture, set the vertex colors to the target and set the combine mode to modulate. If it’s close, you can stick with that unless you have free time still available.

@Chromanoid
Let try it in german:
Was ich möchte ist das ich nur bestimmte Grauwerte fĂ€rben kann. Ich hab ja eine Palette mit 16 Graustufen und alle Bilder werden damit gemacht, so das die RGB-Werte immer gleich sind. Wie im Bild von OP. Dort 2 von den Frauwerte mit anderne farben gezeichnet. Ich nahm jetzt an, dass man das mit Shader zu machen hat
 Aber mein Erfahrung ist da wohl noch ziemlich gering. Bisher schaffe ich es nur mit dem FragmentShader eine Farbe mit einer anderen zu interpolieren (mit einem Ratio halt). Aber wie das direkt auf eine textur geht oder so
 kA :frowning: Aber danke fĂŒr den Link. Ich werde das auf jeden Fall versuchen wenn ich mal Zeit habe! Wenn ich Erfolg habe poste ich das natĂŒrlich auf englisch hier! Bis dahin muss ich wohl oder ĂŒbel das nehmen was Slick mit bietet (ganzes Bild einfĂ€rben)!

@Roquen
Thanks a lot, but I’m don’t even understand this code x_X For now I just do it as you said :slight_smile: I set the vertex colors and have at least the whole texture colored :slight_smile:

Ok. You have a fixed 16 colors palette with gray colors and want to replace these colors with specific other colors that are selected by you (I assume on a per sprite basis). What I don’t understand is why you want to colorize in the pixelshader. Do you need automatic colorization? You will want to know how it looks like anyway, you might even try the coloring in an image editor before you put it in the game. Why you don’t want to provide multiple versions of the sprite and just render the colorized over the gray one with a certain transparency?

Was ich nicht verstehe ist, warum du das ganze ĂŒberhaupt so aufwendig lösen willst. Benötigst du soviele Grafiken, dass du nicht einfach jeden Sprite in Farbe und in Grauwerten anbieten kannst? Oder willst du eine automatische EinfĂ€rbung? Du wirst doch sowieso wissen wollen wie es dann am Ende aussieht und probierst das ganze dann vielleicht sogar vorher noch in einem Malprogramm aus, oder nicht? Du könntest doch einfach ĂŒber den grauen Sprite den Farbigen mit einer gewissen Transparenz zeichnen. Je transparenter du den farbigen Sprite zeichnest desto grauer erscheint das ganze.

You know what? I’m SO stupid to not think of this -____- Of course it’s a perfekt idea! Duh~ I used this so often back in the old days with the RPG-Maker. Thanks a lot, I think I can go with this idea just perfect and it’s not even hard to implement.

So this one ist solved and made me addicted to shaders too (I just tested some stuff in ja Shader IDE, really impressing).

Are you the person who made “Shades” for RPG maker XP?

Haha no, I’m not the one :wink: (I had to google that game :D) I made some games for RPG Maker 2000 but I never touched the XP (don’t like that engine much :/)

I worked in 2000 for a loooooong time before XP came out, but I’ve always been a fan of the next big thing
 once I realized how easy it was to do custom systems with ruby instead of through painstakingly making common events, the door just blew wide open for me. If you can find an archived copy of Shades by ccoa somewhere, I recommend it, it’s a very artistic game that your idea reminds me of. Keep up the good work

If you really want to KISS, Why not just have a base version of each image and a “tint” version of each image? Then just glColor4f(color) before drawing the image on top that represents his clothes or whatever. And make whatever pixels you want to be colored white in the overlay. Easy peasy. Not too expensive if you’re not doing this with too many sprites.

@Rejechted
Okay this is offtopic but
 The Problem with the XP for me is, that it has HUGE RAM leaks. Even a standard game using only the build in scripts is affected by this. Don’t get me wrong, I worked with the XP for a short time and I also help people with some technical stuff but I would never telle anyone to use XP if someone wants to make a game :confused: Because in the end
 I want to be able to play this game xD And as a developer it’s just anoying to see a simple Battlesystem lacking like hell :frowning: (even on good PC’s)

@Eli Delventhal
Something like that was what I did :slight_smile: But havaing a second image over the gray one gives me mor freedom, e.g. tinting different colors on one image and just blend them as Chromanoid suggested.

You could think about generating the grayscale images programatically; it will mean reduced distribution size and perhaps a faster startup (less PNG decoding). Here’s a start:
http://slick.javaunlimited.net/viewtopic.php?f=3&t=4541

The downside is that you’ll have less control over the aesthetic of the grayscale image.

You might also consider packing the color and RGB versions into the same texture for reduced texture binds. :slight_smile: