   Sprite tinting
  I am creating bitmap character models, and I would like to be able to change the hair and clothing colors in-game.  However, I do not want to create 100 different character bitmaps with all possible color combinations, so I am hoping DirectX has some sort of sprite tinting function that will only tint certain portions of an image (based on a color key).  I looked at some of the bitmap character models from Baldur's Gate 2, and it looks like they were all made with bright green hair, bright purple shirts, etc.  This leads me to believe that it is possible to tell DirectX to color blue over bright purple but not over other colors.I have considered the following solution:  Make bright purple a transparent color and draw a colored layer (with a bitmap image, or perhaps some code) behind the sprite.  This has logistical problems, however, since the colored layer would spill over into the background layer unless I make it form perfectly to the sprite.Another problem I imagined is shading.  I would like to shade the clothing, but how could I use transparencies if I have a whole bunch of different color keys in the clothing?  If anyone can think of a solution, please let me know.   
  If you are using ID3DXSprite than the last parameter in the ::Draw function will help you.http://msdn2.microsoft.com/en-us/library/bb174251.aspx;  I already tried working with that...all it does it change the color of the entire sprite.  I am interested in changing the color of certain PARTS of the sprite, however.  Any ideas?   ;  if you run a cheap pixel shader over the sprites and the texture has an alpha channel, then use that to mask the tinting.   ;Quote:Original post by TrashpilepunkerI am creating bitmap character models, and I would like to be able to change the hair and clothing colors in-game.  However, I do not want to create 100 different character bitmaps with all possible color combinations, [...]What you want to do is treat the character as a composite of images instead of as a single image.  You can either composite them when the character information is set (the hair and clothing isn't changing dynamically during game play, is it?) and then use this composite rendering as the sprite, or you can divide the character up into a number of different sprites (clothing, hair, non-{hair+clothing}) and render the different chunks for each character.It sounds to me like the player goes into a menu and configures the character and then plays with that character.  So just dynamically compose textures and whatnot into a render target when the character is configured and then copy that render target to the sprite level and use it throughout gameplay.   ;  I am interested in what urgrund said, but I'm not sure I completely understand it.  Thanks for the help so far.   ;Quote:Original post by TrashpilepunkerI am interested in what urgrund said, but I'm not sure I completely understand it.  Thanks for the help so far.I think he misunderstood your problem; it sounds to me like your problem is that all parts of the sprite that are visible are tinted, when you only want SOME of the visible parts to be tinted.  (As opposed to you having trouble with tinting the entire quad, revealing the square outline of your triangles.)You pretty much have to follow legalize's advice to composite your sprites either at render time (marginally slower, perhaps, but uses less memory) or at character-decision-time (using render targets) if you want to do this properly.  You'll have to isolate the parts of the images you want to change color, draw/render/etc them in grayscale, and composite them with the base (non-changing) part of the character using whatever tinting you prefer.  You can use additive blending on the second layer (on top of a base image that is dark at these places except for specular highlights) to achieve some very high quality results.   ;  Alright, this will definitely take some time considering all of the different sprites and animation frames I'll have to do, but I guess if it's the only way then I'll go for it!  Thanks a bunch.   ;Quote:Original post by MasterWorksQuote:Original post by TrashpilepunkerI am interested in what urgrund said, but I'm not sure I completely understand it.  Thanks for the help so far.I think he misunderstood your problem;I probably did :)   ...I've done very little graphics programming, but when working with sprites (at least on engines I've used that support them) I've been able to apply HLSL shaders to get effects like frame buffer distortion for 'water' particles...  etcso, I assumed that you could do this here, but use an alpha mask on the sprite to mask out the tinting, it would also allow you to keep a percentage of the original... for example, brown hair that only ever gets tinted 20% because the alpha mask has a value of 50 (0-255)...   though as you said, I've probably mis-understood the context the sprites are being used in! :DIn this case here, what is stopping the use of pixel shaders?;Quote:Original post by urgrundI probably did :)   ...I've done very little graphics programming, but when working with sprites (at least on engines I've used that support them) I've been able to apply HLSL shaders to get effects like frame buffer distortion for 'water' particles...  etcYour idea is actually quite valid, it just sounded to me like you were suggesting a solution to a problem where the entire *quad* was being tinted instead of just the "sprite" (whose visibility, I'm assuming, is determined by an alpha channel.)  There are definitely uses for pixel shaders for this type of problem; it just seemed likely to me that the alpha channel was probably already being used for transparency information.  Are you suggesting using an ADDITIONAL alpha channel to mask off areas for tinting?  I don't understand how you could use one alpha channel for both "tint-masking" AND transparency, so maybe this is the source of confusion.  I am definitely not an expert at this but it seems inescapable that the OP will have to (somehow) manually define the areas of the sprite to be recolored, either thru the use of multiple sprites or at least an additional alpha channel and some sort of pixel shader.Quote:for example, brown hair that only ever gets tinted 20% because the alpha mask has a value of 50 (0-255)...   though as you said, I've probably mis-understood the context the sprites are being used in! :DOr maybe I have misunderstood... but again, without trickery I don't understand how this can be done; isn't the alpha channel already being used to define where the hair is visible and where it is transparent (or translucent)?I suggested the composite sprites idea because it gives you flexibility that you can't get with a basic replace-color type operation.  For instance, if you have a character with a shirt that needs to be a variety of colors, you can use dual corresponding sprites to make the shirt any color you choose while still preserving the (wrinkles/highlights/texture) detail.  If you use a more basic 'find all hot pink pixels and replace them with X color' approach you'll end up with a boring, flat color in these areas.But, just for clarity: you definitely don't have to pre-create all the possible color combinations in advance, that would be ridiculous.  All you need is one additional grayscale texture per character to mask off which areas have dynamic colors.   