Home Unity

Shader Forge: Multiple masks packed into single channel

overhira
polycounter lvl 3
Offline / Send Message
overhira polycounter lvl 3
Hey all,

I've been thinking of a way to pack multiple splat maps into a single RGB channel. My thought is that given the full range of 256 values, we can pack multiple masks into a certain value range. For example, for a 3 mask set up in 1 channel: Mask A would exist between 0 and 85, B would exist between 86 and 170, and C would exist between 171 and 255. This would allow for an RGB texture to contain more than 3 masks (1 for each channel), the only limiter being the granularity/transition between masks (ie: range allocated for each mask).

Has anyone attempted something similar? Or even better, got something hooked up in Shader Forge or another node based shader editor?

Replies

  • Eric Chadwick
    Options
    Offline / Send Message
    Yep, I have. This only shows the shader I created in Shader FX, but it was very similar in Shader Forge.

    http://ericchadwick.com/img/robot_rising.html#utility_shader
  • overhira
    Options
    Offline / Send Message
    overhira polycounter lvl 3
    Man, awesome stuff @Eric Chadwick - every Unity related question I've had so far here you've had an answer!

    The shader graph is hard to read. Would you mind posting a higher res of the screenshot or just briefly running down the setup so I can get a conceptual outline?

    Regardless, thanks a ton
  • Eric Chadwick
    Options
    Offline / Send Message
    The bottom right has the math to extract my two masks. 

    I subtract .5 to pull the 127 to 255 range (really .5 to 1) down to 0-127 (0-.5). Then I multiply that by two to stretch it to 0-255 (0-1), then clamp it in case any values were greater than 1.

    For the other mask in 0-127, I simply multiply by 2 to expand it 0-255, then clamp.

    Going off memory here. Looks like some extra stuff in there maybe. Good luck!
  • kodde
    Options
    Offline / Send Message
    kodde polycounter lvl 18
    Stuff like this is usually hassle. I'd try to avoid if possible.

    You might need to account for DDS compression precision errors depending on what you're doing.
    Consider if this is a gamma or linear space texture. If this is purely a mask then linear is given.
    Also, is anyone else going to be working with this? Will they understand how to work with this? Potential for them to get it wrong?
  • Popeye9
    Options
    Offline / Send Message
    Popeye9 polycounter lvl 15
    I have a question about this. How do you pack the channel with 2 maps. Any help or links to tutorials would be greatly appreciated.
  • Eric Chadwick
    Options
    Offline / Send Message
    Popeye9 said:
    I have a question about this. How do you pack the channel with 2 maps. Any help or links to tutorials would be greatly appreciated.
    We didn't overlap the two masks. We used them for something similar to team colors, where we masked different parts of the model to assign different colors to them. For example, the front of a shirt was masked to have one color, while the back of the shirt was masked to assign a 2nd color.

    No tutorials AFAIK.
  • Popeye9
    Options
    Offline / Send Message
    Popeye9 polycounter lvl 15
    Thanks Eric I appreciate the reply. 
Sign In or Register to comment.