Jump to content
  • Advertisement
Sign in to follow this  
reducer

Figuring out a packed normal format

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
   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 this post


Link to post
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>
   <type>SC_REVERSE_PADDED_III_</type>
  </BLENDINDICES>
  <BLENDWEIGHT>
   <type>SC_REVERSE_PADDED__WW_</type>
  </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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!