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?