Skip to main content

Function: classifyMaterialChannels()

classifyMaterialChannels(material, channels?): object

Splits a material's channels into the ones worth training (driven by a node graph - texture or procedural, so potentially spatially-varying) and the ones that are just a flat constant (a plain scalar/color property, with no node at all) - so the network's output width, and the cost of every training sample, scale with how much of the material actually varies rather than always paying for the full channel vocabulary. Constant channels are applied directly as ordinary material properties at reconstruction time, bypassing the network entirely (see NTCNodeMaterial.js).

This is a node-presence heuristic, not a pixel-level analysis: a channel is "active" (trained) iff at least one of its nodeKeys is set on the material, regardless of whether that node's output actually varies once evaluated - a texture-driven channel that happens to be uniform everywhere still gets trained (harmlessly - a constant target is trivially fit, see the flat-velvet-color regression test in NTCTrainer). An earlier version of this function baked and read back each candidate channel to measure its real variance and reclassify accordingly; that added real complexity and failure surface (a GPU readback round trip per material load) without a clear net win, so it's been backed out in favor of this simpler, synchronous check.

A channel descriptor may instead set alwaysConstant: true with a fixed constantValue baked in at spec-construction time, to declare a value that's never trained and never even checks nodeKeys - e.g. a value a caller's custom channel array wants surfaced through constantValues (and applied via applyConstant) for every material, without offering any node-driven path to vary it at all.

channels defaults to the built-in CHANNELS vocabulary, but accepts any caller-supplied channel array (built-in descriptors, custom ones, or a mix)

  • this function has no hardcoded knowledge of any particular channel key.

Parameters​

material​

any

channels?​

any[] = CHANNELS

Returns​

object

activeChannels​

activeChannels: NTCLayoutChannel[]

constantValues​

constantValues: Record<string, unknown>

packCount​

packCount: number

renderFlags​

renderFlags: object

renderFlags.side​

side: unknown

renderFlags.transparent​

transparent: boolean | undefined

totalChannels​

totalChannels: number