I also implemented support for the new vertex formats in Nebula3. N3 always had support for packed vertex components, so all I had to do was to add a few lines to the legacy NVX2 mesh loader and fix a few places in the vertex shaders for unpacking normals and texcoords.
Here's how the vertex components are now packed by default:
- Position: Float3 (just as before)
- Normal, Tangent, Binormal: UByte4N (unsigned byte, normalized)
- TexCoord: Short2 as 4.12 fixed point
- Color: UByte4N
- Skin Weights: UByte4N
- Skin Joint Indices: UByte4
float4 weights = packedWeights / dot(packedWeights, float4(1.0, 1.0, 1.0, 1.0));
This will make sure that the components add up to 1.0. In case you're wondering, the dot product is equivalent with s = (x + y + z + w), it's just much more efficient, because the dot product is a native vertex shader instruction (although I must confess that I didn't check yet whether fxc's optimizer is clever enough to optimize the horizontal sum into a dot product automatically).