Diffuse tinting for varations: how do YOU do it?

polycounter lvl 6
Offline / Send Message
artquest polycounter lvl 6
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

How do you handle shader based diffuse tinting?

/discuss

Replies

  • Brendan
    Offline / Send Message
    Brendan polycounter lvl 6
    For opaque objects it's easy (assuming you aren't using the A channel).

    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.
  • gsokol
    Offline / Send Message
    gsokol Polycount Sponsor
    I recently toyed with diffuse tinting on my Jet Bike:

    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.
  • artquest
    Offline / Send Message
    artquest polycounter lvl 6
    gsokol wrote: »
    I recently toyed with diffuse tinting on my Jet Bike:

    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?
  • gsokol
    Offline / Send Message
    gsokol Polycount Sponsor
    Looks nice! If you had more damage/scratches would it have become a problem using this method?

    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 :).
  • LoTekK
    Offline / Send Message
    LoTekK polycounter lvl 11
    There are quite a number of ways you can approach color variations, with varying degrees of control and results, but a combination of masks and shader math (eg. gsokol's bike, or have a look at Jesse Sosa's Mutant League entry) will generally be the way to go.

    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]
    hueshift.jpg
  • odium
    Offline / Send Message
    odium polycounter lvl 11
    I toyed with using a LUT file straight out of photoshop on our diffuse textures ingame. So rather than it being a screen space effect, I simply used a specific LUT on a texture before it was rendered but after it was passed into memory. It allowed me to control anything on the colour, so if a texture had blue, I could make the blue any colour I wanted.

    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.
  • Ace-Angel
    Offline / Send Message
    Ace-Angel polycounter lvl 6
    Gradient map approach are pretty well off in many regards, but they do cost a pretty instruction count when you want to do procedurally.

    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
  • chronic
    Offline / Send Message
    chronic polycounter lvl 7
    at my workplace we keep the diffuse texture desaturated/lighter in the areas you want to dye, there is a user select-able color that gets masked by the 'dye map' and multiplied over the diffuse texture. you can easily have multiple color-able regions by using multiple masks. this is very inexpensive.
  • artquest
    Offline / Send Message
    artquest polycounter lvl 6
    Sooo a co worker of mine was showing off his guild wars 2 beta... gotta say the color customizing in that game looks great. Anyone know if they're swapping textures or defining a color that's multiplied over the diffuse?

    (if anyone else here happens to have the beta :P)
    chronic wrote: »
    at my workplace we keep the diffuse texture desaturated/lighter in the areas you want to dye, there is a user select-able color that gets masked by the 'dye map' and multiplied over the diffuse texture. you can easily have multiple color-able regions by using multiple masks. this is very inexpensive.

    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?
Sign In or Register to comment.