如何打开DEC3N& amp; UDEC3格式?

时间:2012-01-20 00:41:48

标签: 3d unpack normals

我有一个小工具,用于转换一些网格文件。网格文件具有以DEC3N或UDEC3格式存储的法线。如何解压缩到三个常规浮动cpu端?

1 个答案:

答案 0 :(得分:1)

这里解释: http://www.khronos.org/registry/gles/extensions/OES/OES_vertex_type_10_10_10_2.txt

Modifications to table 2.9 (Component conversions)

    Add the following entries:

        GLType                     Conversion of (x, y, z)  Conversion of w
        -------                    ----------------------   ===============
        INT_10_10_10_2_OES        (2c + 1)/(2^10 - 1)       (2c + 1)/(2^2 - 1)
        UNSIGNED_10_10_10_2_OES    c / (2^10 - 1)            c / (2^2 - 1)

因此,如果您使用UDEC3格式的32位变量N正常,那么

x = (float)( (N>>22) / ((1<<10) - 1);
y = (float)( ((N>>12) & ((1<<10)-1)) / ((1<<10) - 1);
z = (float)( ((N>>2)  & ((1<<10)-1)) / ((1<<10) - 1);

最有可能你也要解压w,并将xyz除以w。