Setting the Data Type for Tangents and Binormals

 
 
 

When you create a Tangent or Binormal property from the Get Property menu, data is written as unclamped floating-point color values. This means that true (unbiased) tangent and binormal data is being encoded in the color at vertices property. However, you can change the data type to use a short integer to store the color values. This is useful, for example, if your shader is expecting "shorts" and is already applying an inverse-offset to reconstruct the tangents and binormals.

To set the data type

  1. In an explorer, click the icon for the Tangents or Binormals CAV property to open its property editor.

  2. Click the Change button next to the DataType parameter, and specify how tangents or binormals are to be written to the color at vertices property. You can choose Float (4 bytes) or Short (2 bytes).

    Note

    Short (2 bytes) stores data in biased form. Colors values usually range from 0 to 1, but normal, tangent, and binormal vectors range from -1 to 1. To solve this issue, when these vector values are written as a texture or stored in a CAV property, 1 is added to the values (to get them in the range 0 to 2) and then the values are divided by 2 (to get them in the range 0 to 1).

    Tangent (x), binormal (y) and normal (z) values are stored as:

    (x+1)/2,(y+1)/2,(z+1)/2

    Therefore, when you read out the pixel values, you will need to multiply them by 2 (to get them back in the range 0 to 2) and then subtract 1 from them (to get them back in the range -1 to 1).

    To get the original values, use:

    r*2-1,g*2-1,b*2-1

    Tangents and binormals stored as Float (4 bytes) are not biased and represent the value directly.

  3. A Vertex Color Change Datatype parameter is added to the property editor and it displays your new data type setting (DesiredDatatype).

    An operator of the same name is also added under the TangentOp2 operator in the Tangents or Binormals operator stack.

  4. If you want to modify the data type again, do so directly in the Vertex Color Change Datatype parameter. Clicking the Change button again will add the modified value as another Vertex Color Change Datatype parameter in the property editor and also in the operator stack. The top-most operator in the stack holds the data type that will be used, but now the operator stack is storing unnecessary data that could reduce performance when tangents and binormals need to be recalculated.

    NoteFor backward compatibility with realtime shaders used in existing scenes, a check is done for the data type being used in the color at vertices property on which TangentOp2 operates. If the data type is using "shorts" then TangentOp2 will write biased values. However, if the color at vertices property is using "floats", then TangentOp2 will not bias the values. At any point you can set the Vertex Color Change Datatype parameter to get the behavior you need.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License