Home Technical Talk

Shader Fill per channel vs per pixel

polycounter lvl 14
Offline / Send Message
pixeldamage polycounter lvl 14
I've currently made a shader for customizing a player's kit that uses patterns packed into the R G & B channels. One of our coders also made a shader but his one uses pixel values to pick value ranges. That method has the benefit of packing more pattens etc into one texture. However I avoided it as I had thought that it would require per-pixel colour lookups rather than per channel. As we're targeting mobile we need to be very careful with shader instructions / perf costs.

So I'd like to know if it's indeed more expensive to tint areas of a texture by using specific pixel values of a mask texture (versus tinting a channel) OR if it makes little difference? I'd need to use more textures lookups in my method (maybe 1-2 extra)

Thanks.

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    Not sure if it's more or less, perf wise, depends how the shaders are written I think.

    But one thing to be aware of, the pixel-range method means you can't overlap any tints on the model. We used this technique (if I understand you correctly) to pack 3 tints into 1 channel. Was a bit limiting at times, but not too hard.
  • Ashaman73
    Options
    Offline / Send Message
    Ashaman73 polycounter lvl 6
    There are really many important factors to consider. Eg more texture lookups press on the bandwidth usage, one of the most limiting factors on modern (desktop) GPUs.

    On the other hand, if you lookup a small texture, which could be completely cached. In the latter case it would not be that important.

    Then it comes down to how complex the operations are. It is sometimes better to use a lookup texture if you have really complex stuff going on.

    Then it depends on the hardware. Desktop GPU have other limits then laptop GPUs which have other limits then mobile GPUs.

    And eventually it depends on the implementation, if the coder version needs to looksup in one of three different textures (depending on range), it could performe much differently then if the version only needs to look up in a single texture.

    As coder I would try to limit the number of texture accesses first, if you only need a handful of additional instructions to process the data.
  • Eric Chadwick
    Options
    Offline / Send Message
    fwiw, here's a shot of a 3ds Max preview shader, using 2 tint ranges in the alpha channel. Our shader programmer wrote the actual engine shader (had to be shader model 2), so mine was just for artists to work with in Max.
    http://ericchadwick.com/img/robotrising_utility_shader.jpg
  • pixeldamage
    Options
    Offline / Send Message
    pixeldamage polycounter lvl 14
    Thanks guys. Sounds like there's not really a definitive answer. Just to clarify further - my method has the shirt UV area in the red channel and the shorts UV in the green and then socks in the alpha. I'd need another texture for horizontal stripes of the shirt in the red etc etc

    The other method would have say magenta for the stripes, yellow for the shirt etc etc (so would require the per pixel changes).

    This is only for Android and iOS (mobile only). Probably targeting Mali 400 (Samsung S3) and ipad 2 / iphone 4s as the lowest end. Desktop doesn't matter.
  • Ace-Angel
    Options
    Offline / Send Message
    Ace-Angel polycounter lvl 12
    You could always try and divide the channels into quadrants. I know UT3 did this, like each armor piece was put into it's own island on a texture sheet, divided 4 way.

    Some other games use the same technique, and do some shader stuff where they blow up the section back to 1:1 space, and tint from there.
  • Eric Chadwick
    Options
    Offline / Send Message
    The way we did it was to use different ranges of greys within a single channel.

    On one project we divided the alpha into three ranges, 0-85, 86-171, 172-255. So any pixels in 86-171 range would get tint color 2.

    A nice benefit of this is you're not stuck with 1 single solid color, you can have a range of 86 greys, which get expanded back up to the black-white range and colored.

    The drawback was you couldn't have any overlaps, since they all shared the same channel. But not that much of an issue, in practice.

    In another project we limited it to two ranges, just to fit within the SM2 limits. Still worked great though.

    Many ways to skin this beast!
  • pixeldamage
    Options
    Offline / Send Message
    pixeldamage polycounter lvl 14
    Thought I'd give a quick update to this. It turned out great - managed to make a full Kit customizer using just two textures (masks packed into the 8 channels and using pixel sub ranges (as Eric explains above)). Performance was great, even on older phones. Those masks were used for full tints and stripes etc. The user selection was/is baked to a final texture for use as the albedo (and a smaller copy used for our menu where players are much smaller).

    A couple of issues to look out for-pixel ranges are very easy to break. Just copy pasting between channels can add noise (think changing to 16 bit didn't help-though I can't remember). Also variance between applications and col or spaces have to be accounted for.

Sign In or Register to comment.