I haven't found too many resources on the topic of diffuse tinting( so I figured I'd open up a discussion about it. So what am I talking about? You might think of this as something similar to team color in an RTS. Where based on a player color you need to color change objects or parts of objects.
I'm curious to see how others have implemented this functionality in their shaders.
Usually the area being filled is just a flat color. I'm looking for a way to keep some detail from the diffuse map either using shader magic(math), or masks, or any combination there of. (if at all possible)
I realize the easiest way is probably just to paint your variations and swap between textures. But when I sit down to implement this in my project I'll need the ability to define the color based on an RGB value so I can change it depending on the player. Usually this is hard to do while making it look good.
So there you have it! Lets make this a great reference thread on the subject.
![:D :D](https://polycount.com/plugins/emojiextender/emoji/twitter/grin.png)
How do you handle shader based diffuse tinting?
/discuss
Replies
Paint your usual diffuse, with the bits you want completely changed the most being pure white. Any bits were you want it to be slightly brighter, paint them so they appear good as if the team colour was white.
Then in your alpha channel, make it all black, except the bits where you want it completely the team colour (paint those solid white) and slightly tinted the team colour (paint those gray - change this).
In your shader, define an changeable RGB for your team colour, then use the A channel to mask it onto the diffuse. Depending on your engine there are going to be different ways of doing said masking, but it shouldn't be too hard to figure that bit out.
http://georgesokol.blogspot.com/2012/03/jet-bike.html
I used an RGB texture, and used the values for different parts of the paint. I just made a couple different textures for different paint jobs, so I could pick the paint style, then change each color. I don't really have much damage on here though, but I did a few light scratches, I just did what Brendan said to do, and left that part black it retained the color of the original diffuse.
Looks nice! If you had more damage/scratches would it have become a problem using this method?
Just curios... has anyone had any experience using gradient maps for texture variation? I.e what sort of limitations they have and how difficult they are to write into a shader?
I think it would have been difficult. If I were wanting to add more damage, I had toyed with the idea of making a separate "damage" map, and different masks for damage, then just lerping that onto the shader after the color mixing is done. That would open up the possibility of having different damage masks as well, and if you wanted to get all crazy, maybe some way to increase the lerp over time or based on specific events...so you can have things get more damaged over time
Once you've got the masks settled, you can go about the actual color tinting in a number of ways. A straight color multiply could work, though that would restrict you to a more or less grayscale diffuse for best results. You could add some instructions to desaturate and alter brightness/contrast before applying the color multiply, though.
Another way would be to use the mask(s) to define hue shift areas. This would let you retain some nice color variations in the diffuse after tinting.
Gradient ramps are another nice one, but the actual hows and whys of the implementation is a discussion unto itself. Valve took an interesting approach, though it does require the asset creation to be somewhat restrictive. I discussed some approach alternatives here, but really, your imagination can come up with plenty of approaches.
[edit with silly hueshift+mask example]
I dropped it when I saw it was pointless, because that meant ANYTHING that was blue would change... Amazing when most of your textures contain blood. That meant anything red would get wiped off...
So in other words, masking and doing it in post will always provide the best result for what you need, and you have direct control over anything that way.
The MINIMUM amount of gradient cuts you should aim for in 9, since anything less you will give a more old school Quake-y graphics.
Also, you'll need a good cavity/displacement/AO setup, with each one controlling something different to get the result you're looking for.
Example: http://www.polycount.com/forum/showthread.php?t=85807
(if anyone else here happens to have the beta :P)
This sounds like a pretty good method. When you have multiple masks though, this means a new texture I would assume? Hows the memory usage with that?