3
\$\begingroup\$

I have a Texture with 6 channels. Each channel store a mask that is used to change a color of a part of my player's sprite.

When the texture only had 3 channels it was easy to implement this color change using a shader, but the only way I can think of how to do it with 6 channels is using 2 textures (which seems pretty annoying to me).

It's possible to use a 6 channel texture nativity in GLSL?

\$\endgroup\$
1

2 Answers 2

3
\$\begingroup\$

Using multiple textures is the standard way this is done, and GPUs are well adapted to that use. We store all sorts of things in textures, not just colours and masks.

That doesn't mean you have to work with multiple textures, of course. If it makes sense to you, just add some middle-ware that converts the multi-channelled texture into an appropriate set of textures, so you can author the textures in a way that's convenient for you. Though again, the tooling also tends to work with one- or four-channel textures for the most part.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Two-channel textures are also fairly common, most often used for normal maps. \$\endgroup\$ Commented Jan 29 at 20:07
8
\$\begingroup\$

The maximum for a single texture is four channels in every GPU rendering API that I know.

While it's technically possible to encode more data into those four channels (e.g. storing eight 4-bit values, instead of four 8-bit values), you'll run into two main problems with that:

  1. The standard hardware texture filtering won't work with your encoded data. This means you'll have to use point sampling, decode the data in the shader, and do manual texture filtering on top of that, if you need it.
  2. The standard texture compression formats (ASTC, ETC2, PVRTC etc.) won't understand the encoded data either, so you'll probably end up using more memory than two separate compressed textures because it'll need to be stored uncompressed.

Using two textures is probably your best solution here.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .