Custom mesh vertex formats

I am rendering a mesh with custom vertex/pixel shaders; part of the per-vertex calculation I am performing depends only on the vertex data and constants, and therefore I would like to perform this calculation at mesh import time and store the results in the mesh data.

The calculation I am offloading is only a few multiplies / additions, and so I do not want to introduce extra vertex elements to store the intermediate results as the cost of an extra element will eat up most of the savings. A number of the existing vertex components are not currently in use; the normal’s w component, and uvs’ y and z components. I would therefore like to reuse these. Is there a way of attaching a custom vertex format to a mesh (e.g. one that uses 4-component uvs instead of the default 3-component or 2-component ones)?

(I do realise Unity has to support devices with fixed function pipelines, however we have already chosen to sacrifice fixed function pipeline support; moreover, the vertex structure declarations in the shaderlab docs have 4-component normals etc. so surely there must be some way of feeding the data in?)

Unfortunately as far as i know you are limited to:

  • 1x position
  • 1x normal
  • 1x tangent
  • 1x color
  • 3x 2d uvs. (The docs just talk about 2 but there are actually 3)

The bottleneck is the Mesh-class