Documentation: What exactly is texture.channel for?

The Texture.channel docs say:

Lets you select the uv attribute to map the texture to. 0 for uv, 1 for uv1, 2 for uv2 and 3 for uv3.

But what are those? Why would you want to use those? Any working examples to look at?

There appears to be no documentation on this. I’d like to get this documented more clearly.

This may be related to the material’s .lightMap and .aoMap properties.

.aoMap : Texture
The red channel of this texture is used as the ambient occlusion map. Default is null. The aoMap requires a second set of UVs.

1 Like

Ah yes, that’s what it is for.

After digging into the source a bit (and seeing some git blames), I found what it is for, but the name “Texture.channel” really did not make this intuitive considering that textures already have “color channels”.

To explain it simply, in WebGLProgram.js we have this:

			'attribute vec2 uv;',

			'#ifdef USE_UV1',

			'	attribute vec2 uv1;',

			'#endif',

			'#ifdef USE_UV2',

			'	attribute vec2 uv2;',

			'#endif',

			'#ifdef USE_UV3',

			'	attribute vec2 uv3;',

			'#endif',

and simply put, if we set texture.channel = 1, then the uv1 attribute will be used instead of the uv attribute for the uv attributes that maps the texture to the mesh geometry.

With a geometry, then we can do this:

const geometry = new BufferGeometry()
geometry.attributes.position = ...vertex positions...
geometry.attributes.uv2 = new Float32BufferAttribute([...uv values...], 2)
geometry.attributes.uv3 = new Float32BufferAttribute([...other uv values...], 2)

const texture = new TextureLoad().load('some-texture.jpg')
texture.channel = 2

const texture2 = new TextureLoad().load('some-texture.jpg')
texture2.channel = 3

const mat = new MeshPhysicalMaterial({
  map: texture,
  normalMap: texture2
})

then the map and the normalMap textures in the materials will use the two separate UVs instead one shared UV as usual.

This is interesting because, for example (I’m theorizing), up to four separate artists could map 4 textures (or 4 sets of textures) to a mesh using 4 different UVs without worrying about having coordinate on a single UV format.

Searching for “texture channel” doesn’t work well because, as you can see from that very example, the word “channel” is being used for the color channel. The property “texture.channel” would seem to be related to a color channel or similar.

Maybe something like texture.uvId or just texture.uv are better names?

Add channel packing to the mix, and things get even more confusing. To be fair, everything about computer graphics is confusing, that’s part of what makes us special :unicorn:. (That is, until AI bumps in and suddenly we’re not that special :skull:)

3 Likes

Specifically in the case of light mapping, lightmaps often don’t require nearly as high pixel density as diffuse textures since its generally lower frequency data. Additionally lightmaps are rarely tiled, whereas diffuse/etc are often tiled to cover large areas. Using separate channels for these kinds of data goes back to Quake1 days and earlier.

3 Likes