Complete vertex Compression

Source: Internet
Author: User
Reprinted please indicate the source for the klayge game engine, the permanent link of this article is http://www.klayge.org /? P = 2116

In the article compressing the tangent frame, we see the method of compressing the tangent frame to four bytes. Now let's take a look at how to compress other attributes to reduce vertex data.

Vertex attributes

First, let's take a look at the attributes of the complete vertex:

Attribute Type Size (bytes) Remarks
Position Float3 12
Texcoord Float2 8
Tangent Float3 12
Binormal Float3 12
Normal Float3 12
Blend_index Uint4 16 Only bone Animation models are available
Blend_weight Float4 16 Only bone Animation models are available
Total 88

After tangent frame compression, generally the engine stores blend_index and blend_weight in uint32, And the vertex format becomes:

Attribute Type Size (bytes) Remarks
Position Float3 12
Texcoord Float2 8
Tangent_quat Uint32 4
Blend_index Uint32 4 Only bone Animation models are available
Blend_weight Uint32 4 Only bone Animation models are available
Total 32

This is also a common vertex layout for general engines.

Target

The above shows that all the attributes except position and texcoord are useless. Therefore, our goal is to compress Postion and texcoord to 16-bit for each component, that is:

Attribute Type Size (bytes) Remarks
Position Short4 8
Texcoord Short2 4
Tangent_quat Uint32 4
Blend_index Uint32 4 Only bone Animation models are available
Blend_weight Uint32 4 Only bone Animation models are available
Total 24

Fortunately, the current video card supports the vertex attribute formats of short4 and short2, providing the possibility for this target. Unfortunately, short1 is not supported. Otherwise, the position can be split into short2 + short1, saving one more short.

Method

The short stored in the vertex attribute reads the value in the range [-1, 1] On the GPU end. Obviously, it is impossible to directly put the position and texcoord components into the short. Here, the position and texcoord bounding boxes must be saved in the model, while the vertex attributes store the normalized parts of the bounding box. In vs, use both to reconstruct the float component and continue the subsequent calculation. Another good thing is that modern graphics cards support mad, so position * bounding_box_extent + bounding_box_center only needs one command. The computation results in almost no loss of performance, while passing properties can save almost normal bandwidth.

That is, the simple and direct compression reduces the vertex size by 1/4 compared with that of only compressing the tangent frame. In terms of precision, short can provide 65536 different values, which is more than enough in general.

Summary
Size (bytes) Compression rate Remarks
Original format 88 100%
Klayge 4.1 and earlier 48 55% Tangent frame is compressed to 8 bytes, and blend_index is compressed to 4 bytes.
Klay Ge 4.2 24 28% Tangent frame is compressed to 4 bytes, blend_weight is compressed to 4 bytes, position is compressed to 8 bytes, and texcoord is compressed to 4 bytes.

After such compression, the new format only occupies 28% of the original format. In examples such as causticsmap and deferredrendering, the neutral performance can be improved by 10%.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.