# Figuring out a packed normal format

This topic is 1376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi again everyone,

I posted the other day about DEC3N normal format. Either i am doing something wrong or the normals are packed using a different method. All i know is the normals are stored in 4 bytes. Originally i thought they may have been stored as 8 bit normals but i don't think so, than I thought it must have been DEC3N/UDEC3 but that seems wrong too.

If anyone has a bit of spare time and wouldn't mind taking a look i have attached a simple console project (vs 2008) that parses a few very simple models. I have put a few screenshots in the download that show the models rendered in wireframe.

Any help figuring this out would be very very much appreciated.

Note there are two different vertex formats. One has position,normal,tex coord (xyznuv) the other position,normal,tex coord,tangent,binormal (xyznuvtb). If you see the source code you will see what i mean. The tagent/binormal are stored in 4 bytes too.

[attachment=6836:test.rar]

##### Share on other sites
   Public Function unpackNormal(ByVal packed As UInt32)
Dim pkz, pky, pkx As Int32
pkz = packed And &HFFC00000
pky = packed And &H4FF800
pkx = packed And &H7FF

Dim z As Int32 = pkz >> 22
Dim y As Int32 = (pky << 10L) >> 21
Dim x As Int32 = (pkx << 21L) >> 21
Dim p As New vect3

p.x = CSng(x) / 1023.0!
p.y = CSng(y) / 1023.0!
p.z = CSng(z) / 511.0!
Dim len As Single = Sqrt((p.x ^ 2) + (p.y ^ 2) + (p.z ^ 2))

'avoid division by 0
If len = 0.0F Then len = 1.0F

'reduce to unit length
p.x = (p.x / len)
p.y = (p.y / len)
p.z = (p.z / len)
Return p
End Function


This will unpack the normals, tangents and binormals used in that game ;)

Its in VB.net but should be easy to translate to what ever you want.
I know this is a old post but this will be useful to some one at some point.
Also.. some of the vertex formats actually have 3 floats for the normal.

"xyznuv" is one of them with 3 floats

Edited by Coffee_

##### Share on other sites

I am now having problems unpacking the new 8_8_8 format.

I have tried a lot of things but nothing works so far.

This is the new format:

<xyznuviiiwwtbpc.xml>
<elements>
<POSITION>
</POSITION>
<NORMAL>
<type>UBYTE4_NORMAL_8_8_8</type>
</NORMAL>
<TEXCOORD>
<type>FLOAT2</type>
</TEXCOORD>
<BLENDINDICES>
</BLENDINDICES>
<BLENDWEIGHT>
</BLENDWEIGHT>
<TANGENT>
<type>UBYTE4_NORMAL_8_8_8</type>
</TANGENT>
<BINORMAL>
<type>UBYTE4_NORMAL_8_8_8</type>
</BINORMAL>
</elements>
</xyznuviiiwwtbpc.xml>



and this is the old format that works with the code I posted.

<xyznuvtb.xml>
<elements>
<POSITION>
</POSITION>
<NORMAL>
<type>UBYTE4</type>
</NORMAL>
<TEXCOORD>
<type>FLOAT2</type>
</TEXCOORD>
<TANGENT>
<type>UBYTE4</type>
</TANGENT>
<BINORMAL>
<type>UBYTE4</type>
</BINORMAL>
</elements>
<targets>
<target>
<name>D3D9</name>
<format>xyznuvtbpc</format>
</target>
</targets>
</xyznuvtb.xml>


I could really use some help sorting out how these 8_8_8 values are converted.

Thanks.

##### Share on other sites

This topic is 1376 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 9
• 24
• 44