Skip to content

Commit

Permalink
Document dequantization a little better
Browse files Browse the repository at this point in the history
meshopt_quantizeFloat does not require dequantization;
meshopt_quantizeHalf now has a dequantize function; Snorm/Unorm variants
have a trivial (divide-by-scale) dequantizer.
  • Loading branch information
zeux committed Aug 24, 2023
1 parent 282153e commit b4486e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ unsigned short py = meshopt_quantizeHalf(v.y);
unsigned short pz = meshopt_quantizeHalf(v.z);
```

Since quantized vertex attributes often need to remain in their compact representations for efficient transfer and storage, they are usually dequantized during vertex processing by configuring the GPU vertex input correctly to expect normalized integers or half precision floats, which often needs no or minimal changes to the shader code. When CPU dequantization is required instead, `meshopt_dequantizeHalf` can be used to convert half precision values back to single precision; for normalized integer formats, the dequantization just requires dividing by 2^N-1 for unorm and 2^(N-1)-1 for snorm variants, for example manually reversing `meshopt_quantizeUnorm(v, 10)` can be done by dividing by 1023.

## Vertex/index buffer compression

In case storage size or transmission bandwidth is of importance, you might want to additionally compress vertex and index data. While several mesh compression libraries, like Google Draco, are available, they typically are designed to maximize the compression ratio at the cost of disturbing the vertex/index order (which makes the meshes inefficient to render on GPU) or decompression performance. They also frequently don't support custom game-ready quantized vertex formats and thus require to re-quantize the data after loading it, introducing extra quantization errors and making decoding slower.
Expand Down
2 changes: 1 addition & 1 deletion src/meshoptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ inline int meshopt_quantizeSnorm(float v, int N);
MESHOPTIMIZER_API unsigned short meshopt_quantizeHalf(float v);

/**
* Quantize a float into a floating point value with a limited number of significant mantissa bits
* Quantize a float into a floating point value with a limited number of significant mantissa bits, preserving the IEEE-754 fp32 binary representation
* Generates +-inf for overflow, preserves NaN, flushes denormals to zero, rounds to nearest
* Assumes N is in a valid mantissa precision range, which is 1..23
*/
Expand Down

0 comments on commit b4486e1

Please sign in to comment.