Added SDK 0.28.0
TextureEncode provides a set of utilities for encoding and decoding normalised floating point values and vectors into integer pixel values for storage in non-floating-point textures.
Analogous functions exist in assets/shaders/particles-common.cgh for GPU side encoding and decoding compatible with this object’s methods.
Note
This is a low-level particle system API.
Summary
Encode an unsigned float value [0,1) into an 8-bit unsigned integer. Values less than 0 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0.5 can be encoded exactly. The largest representable value is 0.99609375 with the absolute difference between any successive invertible input 0.00390625. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeByteUnsignedFloat(value);
Summary
Encode a signed float value [-1,1) into an 8-bit unsigned integer. Values less than -1 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0 can be encoded exactly. The largest representable value is 0.9921875 with the absolute difference between any successive invertible input 0.0068125. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeByteSignedFloat(value);
Summary
Encode an unsigned float value [0,1) into a 16-bit unsigned integer. Values less than 0 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0.5 can be encoded exactly. The largest representable value is 0.9999847412109375 with the absolute difference between any successive invertible input 0.0000152587890625. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeHalfUnsignedFloat(value);
Summary
Encode a signed float value [-1,1) into a 16-bit unsigned integer. Values less than -1 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0 can be encoded exactly. The largest representable value is 0.999969482421875 with the absolute difference between any successive invertible input 0.000030517578125. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeHalfSignedFloat(value);
Summary
Encode an unsigned float value [0,1) into a 32-bit signed integer. Values less than 0 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0.5 can be encoded exactly. The largest representable value is 0.99999999976716935634613037109375 with the absolute difference between any successive invertible input 0.00000000023283064365386962890625. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeUnsignedFloat(value);
Summary
Encode a signed float value [-1,1) into a 32-bit signed integer. Values less than -1 or greater-equal to 1 will be clamped.
Note
1 cannot be encoded in this scheme, but 0 can be encoded exactly. The largest representable value is 0.9999999995343387126922607421875 with the absolute difference between any successive invertible input 0.0000000004656612873077392578125. Non-invertible inputs will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeSignedFloat(value);
Summary
Encode a pair of unsigned float values [0,1) into a 32-bit signed integer. Components less than 0 or greater-equal to 1 will be clamped.
Note
Components equal to 1 cannot be encoded in this scheme, but 0.5 can be encoded exactly. The largest representable value for components is 0.9999847412109375 with the absolute difference between any successive invertible input components 0.0000152587890625. Non-invertible input components will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeUnsignedFloat2([value1, value2]);
Summary
Encode a pair of signed float values [-1,1) into a 32-bit signed integer. Components less than -1 or greater-equal to 1 will be clamped.
Note
Components equal to 1 cannot be encoded in this scheme, but 0.5 can be encoded exactly. The largest representable value for components is 0.999969482421875 with the absolute difference between any successive invertible input components 0.000030517578125. Non-invertible input components will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeSignedFloat2([value1, value2]);
Summary
Encode a quartet of unsigned float values [0,1] into a 32-bit signed integer. Components less than 0 or greater than 1 will be clamped.
Note
Different from the other encoding schemes, components equal to 1 can be encoded exactly in this scheme, but components equal to 0.5 will not be encoded. The absolute difference between any successive invertible input components 0.00392156862745098... Non-invertible input components will be rounded down to the nearest invertible representation.
Syntax
var encoding = TextureEncode.encodeUnsignedFloat4([value1, value2, value3, value4]);
Summary
Decode an 8-bit unsigned integer into an unsigned float value [0,1).
Note
This is an exact inverse (for representable values) of encodeByteUnsignedFloat.
Syntax
var value = TextureEncode.decodeByteUnsignedFloat(encoding);
Summary
Decode an 8-bit unsigned integer into a signed float value [-1,1).
Note
This is an exact inverse (for representable values) of encodeByteSignedFloat.
Syntax
var value = TextureEncode.decodeByteSignedFloat(encoding);
Summary
Decode a 16-bit unsigned integer into an unsigned float value [0,1).
Note
This is an exact inverse (for representable values) of encodeHalfUnsignedFloat.
Syntax
var value = TextureEncode.decodeHalfUnsignedFloat(encoding);
Summary
Decode a 16-bit unsigned integer into a signed float value [-1,1).
Note
This is an exact inverse (for representable values) of encodeHalfSignedFloat.
Syntax
var value = TextureEncode.decodeHalfSignedFloat(encoding);
Summary
Decode a 32-bit signed integer into an unsigned float value [0,1).
Note
This is an exact inverse (for representable values) of encodeUnsignedFloat.
Syntax
var value = TextureEncode.decodeUnsignedFloat(encoding);
Summary
Decode a 32-bit signed integer into a signed float value [-1,1).
Note
This is an exact inverse (for representable values) of encodeSignedFloat.
Syntax
var value = TextureEncode.decodeSignedFloat(encoding);
Summary
Decode a 32-bit signed integer into a pair of unsigned float values [0,1).
Note
This is an exact inverse (for representable values) of encodeUnsignedFloat2.
Syntax
var values = TextureEncode.decodeUnsignedFloat2(encoding);
// or
TextureEncode.decodeUnsignedFloat2(encoding, dst);
Summary
Decode a 32-bit signed integer into a pair of signed float values [-1,1).
Note
This is an exact inverse (for representable values) of encodeSignedFloat2.
Syntax
var values = TextureEncode.decodeSignedFloat2(encoding);
// or
TextureEncode.decodeSignedFloat2(encoding, dst);
Summary
Decode a 32-bit signed integer into a quartet of unsigned float values [0,1).
Note
This is an exact inverse (for representable values) of encodeUnsignedFloat4.
Syntax
var values = TextureEncode.decodeUnsignedFloat4(encoding);
// or
TextureEncode.decodeUnsignedFloat4(encoding, dst);