janekb04
janekb04

Reputation: 4915

Use more than four components in OpenGL texture

I know it is simply not possible to have more than the four built-in texture components. At least directly. Generally, the proposed solution is simple - use multiple textures. However, I think that it is not optimal. Let's look at an example.

Let's say there is a basic material format that has the following properties:

  1. albedo - 3 components
  2. normal - 3 components
  3. roughness - 1 component
  4. metallness - 1 component

The simplest way to store this data would be to use 4 diffrent textures with respectively 3, 3, 1, and 1 components. This is inefficient for at least two reasons:

  1. Most probably the GPU does not actually store the first two textures with only 3 components, but with four, as most GPUs align 3 component vectors, matrices, textures to four components.
  2. Getting all the data in the shader requires 4 texture samples

The common way to deal with this would be to pack the data in the least amount if textures possible that also nicely align. In this case it could be put in two textures with 4 components each. This solves the first issue of wasted memory, but the second one still exists as it is still required to do 2 texture samples to read the data. 2 samples is not really a lot, but what if it could be reduced to just one?

My idea is to pack all 6 components in one texture. How? GL_RGB16_SNORM. It is a texture internal format that albeit having only 3 components, could actually fit 6 because each pixel is 6 bytes.

So my question is:

  1. Would it be possible to upload the data as 6 components to such a texture and somehow read it in the shader.
  2. Would it be faster to use this packing or just stick to using two separate textures.
  3. Is there a different, better approach to this?

Upvotes: 0

Views: 404

Answers (1)

genpfault
genpfault

Reputation: 52083

Use an array texture & sample at the same (u,v) location in the other layers to retrieve your extra texture channel data.

Upvotes: 1

Related Questions