Bfres: Difference between revisions

From EPD Wiki
Jump to navigation Jump to search
(Add header (unsure of what I'm doing))
 
(Add partial section order. Meshlet correction.)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''Bfres''' is a model archive file format. A Bfres file can contain models with shapes, materials, and a skeleton as well as skeletal, material, shape, bone visibility, and scene animations.
A bfres file collects a number of 3d-graphics related resources. This article details bfres version 10.0.0 and 10.2.0.


=== Header (nn::g3d::ResFile or nn::g3d2::ResFile) ===
=== File Structure ===
An nn::util::BinaryFileHeader derived file header featuring arrays and dictionaries of each model resource type, as well.
Note this omits optional sections not currently found in at least one file. Such as the placement of user data in animations.
 
==== Section Order ====
 
* fres header
* fmdl header array
* fska header array
* fmaa header array
* fvbs header array
* fsha header array
* fscn header array
* memory pool info
* embed file array
* fmdl dictionary
* fska dictionary
* fmaa dictionary
* fvbs dictionary
* fsha dictionary
* fscn dictionary
* embed file dictionary
* fmdl data array:
** fvtx header array
** fmat header array
** reflection header array
** fshp header array
** fskl header
** fskl data:
*** bone header array
*** skin bone index table
*** inverse transform matrix array
*** mirror bone index table
*** bone dictionary
*** bone data array:
**** user data array
**** user data dictionary
**** user data
** shape dictionary
** material dictionary
** fshp data array:
*** mesh array
*** skin bone index array
*** bounding box array
*** bounding sphere array
*** mesh data array:
**** sub mesh array
**** runtime index buffer memory
**** index buffer info
** fvtx data array:
*** vertex attribute array
*** runtime vertex buffer memory array
*** vertex buffer info array
*** vertex buffer stride info array
*** runtime user vertex buffer pointer array
*** vertex attribute dictionary
** fmat data array:
*** render info value string array
*** render info value s32 array
*** render info value float array
*** render info value count array
*** render info value offset array
*** runtime texture view pointer array
*** sampler info array
*** runtime sampler array
*** shader param value array
*** runtime shader param uniform buffer offset array
*** shader param convert flag array
*** user data array
*** runtime sampler descriptor slot array
*** runtime texture view descriptor slot array
*** texture name array
*** static shader variation header
*** static shader variation data:
**** vertex attribute name array
**** vertex attribute variation to reflection array (only if different)
**** vertex attribute reflection to variation array (only if different)
**** sampler name array
**** sampler variation to reflection array (only if different)
**** sampler reflection to variation array (only if different)
**** static shader bool array
**** static shader string array
**** static shader option variation to reflection index array (only if different)
**** static shader option reflection to variation index array (only if different)
*** user data
*** sampler dictionary
*** user data dictionary
** reflection data array:
*** render info array
*** shader param array
*** shader param dictionary (deduplicated between reflections)
*** render info dictionary (deduplicated between reflections)
*** vertex attribute dictionary (deduplicated between reflections)
*** sampler dictionary (deduplicated between reflections)
*** static shader option dictionary (deduplicated between reflections)
* fska data array:
** fast bind table
** bone anim header array
** bone anim data array:
*** default result
*** anim curve header array
*** anim curve frame and value data array
* fvba data array:
** default result array
** fast bind array
** bone name array
** anim curve header array
** anim curve frame and value data array
* fmaa data array:
** fast bind array
** per material anim header array
** runtime texture view descriptor slot array
** runtime texture view pointer array
** texture name array
** per material anim data array:
*** shader param anim array
*** texture pattern anim array
*** constant array
*** anim curve header array
*** anim curve frame and value data array
* fsha data array:
** fast bind table
** vertex shape anim header array
** vertex shape anim data array:
*** key shape anim array
*** anim curve header array
*** default result array
*** anim curve frame and value data array
* fscn data array:
** fcam header array
** flit header array
** ffog header array
** fcam dictionary
** flit dictionary
** ffog dictionary
** fcam data array:
*** anim curve header array
*** default result
*** anim curve frame and value data array
** flit data array:
*** anim curve header array
*** default result
*** anim curve frame and value data array
** ffog data array:
*** anim curve header array
*** default result
*** anim curve frame and value data array
* string pool
* gpu region:
** index buffer data
** vertex buffer data
* runtime memory pool
* embed file region
* relocation table
 
=== Header (nn::g3d2::ResFile) ===
A bfres file header collects a number of optional resources that can be iterated through by array or looked up by name through dictionary. Resources include 3d model data, model animation data, scene animation data, and embedded files. A Bfres can contain a "GPU region", a block of memory meant to be made GPU visible, or reference an external GPU region.
{| class="wikitable"
{| class="wikitable"
|+Version 10.0.0
|+
!Offset
!Offset
!Size
!Size
Line 12: Line 166:
|0x0
|0x0
|0x20
|0x20
|nn::util::BinaryFileHeader
|[[Common nn::util#nn::util::BinaryFileHeader|nn::util::BinaryFileHeader]]
|Base header
|Base header with magic of "FRES  ".
|-
|-
|0x20
|0x20
Line 27: Line 181:
|0x30
|0x30
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Model dictionary
|Model dictionary
|-
|-
|0x38
|0x38
|0x8
|0x8
|reserved
|void*[4]
|Only 4 unused null pointers so far
|
|-
|-
|0x58
|0x58
Line 42: Line 196:
|0x60
|0x60
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Skeletal animation dictionary
|Skeletal animation dictionary
|-
|-
Line 52: Line 206:
|0x70
|0x70
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Material animation dictionary
|Material animation dictionary
|-
|-
Line 62: Line 216:
|0x80
|0x80
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Bone visibility animation dictionary
|Bone visibility animation dictionary
|-
|-
Line 72: Line 226:
|0x90
|0x90
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Shape animation dictionary
|Shape animation dictionary
|-
|-
Line 82: Line 236:
|0xa0
|0xa0
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Scene animation dictionary
|Scene animation dictionary
|-
|-
Line 92: Line 246:
|0xb0
|0xb0
|0x8
|0x8
|nn::gfx::MemoryPoolInfo
|[[Common nn::gfx#nn::gfx::MemoryPoolInfo|nn::gfx::MemoryPoolInfo]]
|Pre-initialized MemoryPool info pointing to GPU region
|Pre-initialized MemoryPool info pointing to GPU region
|-
|-
|0xb8
|0xb8
|0x8
|0x8
|nn::gfx::ResEmbedFile *
|[[Common nn::gfx#nn::gfx::ResEmbedFile|nn::gfx::ResEmbedFile]] *
|Embed file array
|Embed file array
|-
|-
|0xc0
|0xc0
|0x8
|0x8
|nn::util::ResDic *
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]] *
|Embed file dictionary
|Embed file dictionary
|-
|-
Line 112: Line 266:
|0xd0
|0xd0
|0x8
|0x8
|const char *
|const char * (NW)
|Reserved
|
|-
|-
|0xd8
|0xd8
|0x4
|0x4
|u32
|u32
|Reserved
|
|-
|-
|0xdc
|0xdc
Line 128: Line 282:
|0x2
|0x2
|u16
|u16
|Reserved
|
|-
|-
|0xe0
|0xe0
|0x2
|0x2
|u16
|u16
|Reserved
|
|-
|-
|0xe2
|0xe2
Line 168: Line 322:
|0x2
|0x2
|u16
|u16
|Reserved
|
|}
 
=== Model (nn::g3d2::ResModel) ===
A model represents a collection of 3d shape data, material data, and a skeleton.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Magic, always "FMDL"
|-
|0x4
|0x4
|u32
|
|-
|0x8
|0x8
|const char* (NW)
|Model name
|-
|0x10
|0x8
|const char* (NW)
|
|-
|0x18
|0x8
|ResSkeleton*
|Skeleton
|-
|0x20
|0x8
|ResVertex*
|Vertex array
|-
|0x28
|0x8
|ResShape*
|Shape array
|-
|0x30
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Shape dictionary
|-
|0x38
|0x8
|ResMaterial*
|Material array
|-
|0x40
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Material dictionary
|-
|0x48
|0x8
|ResShaderReflection*
|Shader reflection array
|-
|0x50
|0x8
|Gfx User Data*
|User data array
|-
|0x58
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|User data dictionary
|-
|0x60
|0x8
|void *
|Runtime user pointer
|-
|0x68
|0x2
|u16
|Vertex count
|-
|0x6a
|0x2
|u16
|Shape count
|-
|0x6c
|0x2
|u16
|Material count
|-
|0x6e
|0x2
|u16
|Shader reflection count
|-
|0x70
|0x2
|u16
|User data count
|-
|0x72
|0x6
|
|
|}
 
==== Vertex (nn::g3d2::ResVertex) ====
A ResVertex references a collection of vertex buffers in the GPU region. Reflection and settings are provided for the vertex buffers and attributes. Runtime object memory is provided to initialize graphics api objects for the vertex buffers.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Magic "FVTX"
|-
|0x4
|0x4
|u32
|
|-
|0x8
|0x8
|ResVertexAttribute*
|Vertex atribute array
|-
|0x10
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Vertex attribute dictionary
|-
|0x18
|0x8
|void *
|Runtime memory pool pointer
|-
|0x20
|0x8
|void *
|Runtime vertex buffer array (0x48 bytes of zeroed memory per vertex buffer)
|-
|0x28
|0x8
|void **
|Runtime user vertex buffer array
|-
|0x30
|0x8
|nn::gfx::BufferInfo*
|Vertex buffer info array
|-
|0x38
|0x8
|ResVertexBufferStride*
|Vertex buffer stride array
|-
|0x40
|0x8
|void *
|Runtime user pointer
|-
|0x48
|0x4
|u32
|Base offset of vertex data in GPU region, relative to start of GPU region
|-
|0x4c
|0x1
|u8
|Vertex attribute count
|-
|0x4d
|0x1
|u8
|Vertex buffer count
|-
|0x4e
|0x2
|u16
|Index of this section in parent ResModel
|-
|0x50
|0x4
|u32
|Vertex count
|-
|0x54
|0x2
|u16
|
|-
|0x56
|0x2
|u16
|Alignment of vertex buffer data in GPU region
|}
 
===== ResVertexAttribute =====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|const char* (NW)
|Attribute name
|-
|0x8
|0x4
|u32, nn::gfx::AttributeFormat
|Attribute format
|-
|0xc
|0x2
|u16
|Buffer offset
|-
|0xe
|0x1
|u8
|Buffer index
|-
|0xf
|0x1
|u8
|Indicates whether this is a dynamic vertex attribute for shape blending
|}
 
===== ResVertexBufferStride =====
Unused bytes might indicate nn::gfx::VertexBufferInfo.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Stride
|-
|0x4
|0x4
|u32
|Divisor
|-
|0x8
|0x4
|u32
|
|-
|0xc
|0x4
|u32
|
|}
 
==== Shape (nn::g3d2::ResShape) ====
A shape represents 3d mesh data. Either via a set of level-of-detail meshes into the vertex buffers of a ResVertex, or alternatively in v10.2.0 onwards, a set of meshlet buffers.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Magic "FSHP"
|-
|0x4
|0x4
|u32
|Flags
|-
|0x8
|0x8
|const char* (NW)
|Shape name
|-
|0x10
|0x8
|ResVertex*
|Referenced vertex
|-
|0x18
|0x8
|ResMesh* or ResMeshlet*
|Level-of-detail mesh array, or if flags bit 4 is set, a ResMeshlet
|-
|0x20
|0x8
|u16*
|Skinning bone index array
|-
|0x28
|0x8
|ResKeyShape*
|Key shape array
|-
|0x30
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Key shape dictionary
|-
|0x38
|0x8
|ResBounding*
|Bounding box array
|-
|0x40
|0x8
|ResBoundingSphere*
|Bounding sphere array
|-
|0x48
|0x8
|void *
|Runtime user pointer
|-
|0x50
|0x2
|u16
|Index of this section in parent ResModel
|-
|0x52
|0x2
|u16
|Material index
|-
|0x54
|0x2
|u16
|Base bone index
|-
|0x56
|0x2
|u16
|Vertex index
|-
|0x58
|0x2
|u16
|Skin bone index count
|-
|0x5a
|0x1
|u8
|Vertex skin weight count
|-
|0x5b
|0x1
|u8
|Mesh count
|-
|0x5c
|0x1
|u8
|Key shape count
|-
|0x5d
|0x1
|u8
|Target attribute count
|-
|0x5e
|0x2
|u16
|
|}
 
===== ResMesh =====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|ResSubMeshRange*
|Array of sub mesh ranges
|-
|0x8
|0x8
|void *
|Runtime memory pool pointer
|-
|0x10
|0x8
|void *
|Runtime index buffer memory (0x48 bytes of zeroed memory)
|-
|0x18
|0x8
|nn::gfx::BufferInfo*
|Index buffer info
|-
|0x20
|0x4
|u32
|Offset of index buffer in GPU region relative to start of GPU region
|-
|0x24
|0x4
|u32, nn::gfx::PrimitiveTopology
|Primitive topology to use for drawing commands
|-
|0x28
|0x4
|u32, nn::gfx::IndexFormat
|Index format to use in drawing commands
|-
|0x2c
|0x4
|u32
|Index count
|-
|0x30
|0x4
|u32
|Base vertex
|-
|0x34
|0x2
|u16
|Sub mesh count
|-
|0x36
|0x2
|u16
|
|}
 
====== ResSubMeshRange ======
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Offset of sub mesh relative to start of index buffer
|-
|0x4
|0x4
|u32
|Index count of sub mesh
|}
 
===== ResKeyShape =====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x12
|u8[18]
|Relative key shape attribute location array
|-
|0x12
|0x2
|u8[2]
|
|}
 
===== ResBounding =====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0xc
|Float3
|Position
|-
|0xc
|0xc
|Float3
|Extent
|}
 
===== ResBoundingSphere =====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0xc
|Float3
|Position
|-
|0xc
|0x4
|float
|Radius
|}
 
===== ResMeshlet =====
Currently only observed unused in Nintendo Switch Online: Playtest Program.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|...
|
|-
|0x8
|0x8
|void *
|Runtime meshlet buffer array (0x48 bytes of zeroed memory per meshlet buffer)
|-
|0x10
|0x8
|nn::gfx::BufferInfo*
|Meshlet buffer info array
|-
|0x18
|0x8
|s64 *
|Meshlet buffer memory offset array, each entry relative to start of GPU region
|-
|0x20
|0x24
|...
|
|-
|0x44
|0x1
|u8
|Meshlet buffer count
|-
|0x45
|0x3
|...
|
|}
 
==== Shader Reflection ====
A ResShaderReflection provides reflection for resolving material parameter data for a shader inside a bfsha shader archive.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|const char* (NW)
|Shader archive name
|-
|0x8
|0x8
|const char* (NW)
|Shader name
|-
|0x10
|0x8
|ResRenderInfo*
|Render info array
|-
|0x18
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Render info dictionary
|-
|0x20
|0x8
|ResShaderParam*
|Material shader parameter array
|-
|0x28
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Material shader parameter dictionary
|-
|0x30
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Vertex attribute dictionary
|-
|0x38
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Sampler dictionary
|-
|0x40
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Static shader option dictionary
|-
|0x48
|0x2
|u16
|Render info count
|-
|0x4a
|0x2
|u16
|Shader parameter count
|-
|0x4c
|0x2
|u16
|Shader parameter data size
|-
|0x4e
|0xa
|u8[10]
|
|}
 
===== ResRenderInfo =====
Render info provides reflection for CPU-side rendering parameters.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|const char* (NW)
|Render info name
|-
|0x8
|0x1
|u8
|Render info data type
|-
|0x9
|0x7
|u8[7]
|
|}
 
====== Render info data type ======
{| class="wikitable"
|+
!Name
!Value
!Description
|-
|Int
|0
|Value is a 32-bit integer
|-
|Float
|1
|Value is a 32-bit float
|-
|String
|2
|Value is an NW string pointer
|}
 
===== ResShaderParam =====
ResShaderParam's compose a user generated structure layout for a material uniform buffer. Shader parameters can be animated through material animations.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|u32(*)(void*,const void*,ResShaderParam*, void*)
|Runtime conversion function for data types requiring runtime conversion of a CPU representation to a GPU representation
|-
|0x8
|0x8
|const char* (NW)
|Shader parameter name
|-
|0x10
|0x2
|u16
|Shader parameter offset
|-
|0x12
|0x1
|u8
|Shader parameter data type
|-
|0x13
|0x5
|u8[5]
|
|}
 
====== Shader parameter data type ======
{| class="wikitable"
|+
!Name
!Value
!Description
|-
|Bool
|0
|
|-
|Bool2
|1
|
|-
|Bool3
|2
|
|-
|Bool4
|3
|
|-
|Int
|4
|
|-
|Int2
|5
|
|-
|Int3
|6
|
|-
|Int4
|7
|
|-
|UInt
|8
|
|-
|UInt2
|9
|
|-
|UInt3
|10
|
|-
|UInt4
|11
|
|-
|Float
|12
|
|-
|Float2
|13
|
|-
|Float3
|14
|
|-
|Float4
|15
|
|-
|Matrix2x2
|17
|
|-
|Matrix2x3
|18
|
|-
|Matrix2x4
|19
|
|-
|Matrix3x2
|20
|
|-
|Matrix3x3
|21
|
|-
|Matrix3x4
|22
|
|-
|Matrix4x2
|23
|
|-
|Matrix4x3
|24
|
|-
|Matrix4x4
|25
|
|-
|Srt2d
|26
|
|-
|Srt3d
|27
|
|-
|SrtTexture
|28
|
|}
 
==== Material (nn::g3d2::ResMaterial) ====
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x4
|u32
|Magic "FMAT"
|-
|0x4
|0x4
|u32
|Flags (bit 0 = is visible)
|-
|0x8
|0x8
|const char* (NW)
|Material name
|-
|0x10
|0x8
|ResStaticShaderVariation*
|Static shader variation
|-
|0x18
|0x8
|void**
|Runtime texture view pointer array
|-
|0x20
|0x8
|const char** (NW)
|Texture name array
|-
|0x28
|0x8
|void*
|Runtime sampler array (0x78 bytes of zeroed memory per sampler)
|-
|0x30
|0x8
|nn::gfx::SamplerInfo*
|Sampler info array
|-
|0x38
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|Sampler dictionary
|-
|0x40
|0x8
|void*
|Render info value array
|-
|0x48
|0x8
|u16*
|Render info value count array
|-
|0x50
|0x8
|u16*
|Render info value offset array
|-
|0x58
|0x8
|void*
|Shader parameter value array
|-
|0x60
|0x8
|s32*
|Runtime shader parameter material uniform buffer offset array
|-
|0x68
|0x8
|u64
|
|-
|0x70
|0x8
|Gfx user data*
|User data array
|-
|0x78
|0x8
|[[Common nn::util#nn::util::ResDic|nn::util::ResDic]]*
|User data dictionary
|-
|0x80
|0x8
|u32 *
|Shader parameter runtime convert bit array
|-
|0x88
|0x8
|void*
|Runtime user pointer
|-
|0x90
|0x8
|u64*
|Runtime sampler descriptor slot array
|-
|0x98
|0x8
|u64*
|Runtime texture view descriptor slot array
|-
|0xa0
|0x2
|u16
|Index of this section in parent ResModel
|-
|0xa2
|0x1
|u8
|Sampler count
|-
|0xa3
|0x1
|u8
|Texture count
|-
|0xa4
|0x2
|u16
|Is force calculate material
|-
|0xa6
|0x2
|u16
|User data count
|-
|0xa8
|0x2
|u16
|Render info value size
|-
|0xaa
|0x2
|u16
|Runtime material uniform buffer size
|-
|0xac
|0x4
|u32
|
|}
 
===== ResStaticShaderVariation =====
A material references a ResStaticShaderVariation which selects the material's static shader variation out of the shader referenced by a ResShaderReflection.
{| class="wikitable"
|+
!Offset
!Size
!Type
!Description
|-
|0x0
|0x8
|ResShaderReflection*
|Shader reflection
|-
|0x8
|0x8
|const char** (NW)
|Vertex attribute name array, of those used in this specific static shader variation
|-
|0x10
|0x8
|u8*
|Vertex attribute index array
|-
|0x18
|0x8
|const char** (NW)
|Sampler name array, of those used in this specific static shader variation
|-
|0x20
|0x8
|u8*
|Sampler index array
|-
|0x28
|0x8
|u32*
|Static shader option choice packed bool array
|-
|0x30
|0x8
|const char** (NW)
|Static shader option choice string array
|-
|0x38
|0x8
|u16*
|Static shader option index array
|-
|0x40
|0x4
|u32
|
|-
|0x44
|0x1
|u8
|Vertex attribute count
|-
|0x45
|0x1
|u8
|Sampler count
|-
|0x46
|0x2
|u16
|Static shader option bool count
|-
|0x48
|0x2
|u16
|Total static shader option count
|-
|0x4a
|0x6
|u8[6]
|
|}
|}
[[Category:File formats]]

Latest revision as of 21:56, 21 February 2025

A bfres file collects a number of 3d-graphics related resources. This article details bfres version 10.0.0 and 10.2.0.

File Structure

Note this omits optional sections not currently found in at least one file. Such as the placement of user data in animations.

Section Order

  • fres header
  • fmdl header array
  • fska header array
  • fmaa header array
  • fvbs header array
  • fsha header array
  • fscn header array
  • memory pool info
  • embed file array
  • fmdl dictionary
  • fska dictionary
  • fmaa dictionary
  • fvbs dictionary
  • fsha dictionary
  • fscn dictionary
  • embed file dictionary
  • fmdl data array:
    • fvtx header array
    • fmat header array
    • reflection header array
    • fshp header array
    • fskl header
    • fskl data:
      • bone header array
      • skin bone index table
      • inverse transform matrix array
      • mirror bone index table
      • bone dictionary
      • bone data array:
        • user data array
        • user data dictionary
        • user data
    • shape dictionary
    • material dictionary
    • fshp data array:
      • mesh array
      • skin bone index array
      • bounding box array
      • bounding sphere array
      • mesh data array:
        • sub mesh array
        • runtime index buffer memory
        • index buffer info
    • fvtx data array:
      • vertex attribute array
      • runtime vertex buffer memory array
      • vertex buffer info array
      • vertex buffer stride info array
      • runtime user vertex buffer pointer array
      • vertex attribute dictionary
    • fmat data array:
      • render info value string array
      • render info value s32 array
      • render info value float array
      • render info value count array
      • render info value offset array
      • runtime texture view pointer array
      • sampler info array
      • runtime sampler array
      • shader param value array
      • runtime shader param uniform buffer offset array
      • shader param convert flag array
      • user data array
      • runtime sampler descriptor slot array
      • runtime texture view descriptor slot array
      • texture name array
      • static shader variation header
      • static shader variation data:
        • vertex attribute name array
        • vertex attribute variation to reflection array (only if different)
        • vertex attribute reflection to variation array (only if different)
        • sampler name array
        • sampler variation to reflection array (only if different)
        • sampler reflection to variation array (only if different)
        • static shader bool array
        • static shader string array
        • static shader option variation to reflection index array (only if different)
        • static shader option reflection to variation index array (only if different)
      • user data
      • sampler dictionary
      • user data dictionary
    • reflection data array:
      • render info array
      • shader param array
      • shader param dictionary (deduplicated between reflections)
      • render info dictionary (deduplicated between reflections)
      • vertex attribute dictionary (deduplicated between reflections)
      • sampler dictionary (deduplicated between reflections)
      • static shader option dictionary (deduplicated between reflections)
  • fska data array:
    • fast bind table
    • bone anim header array
    • bone anim data array:
      • default result
      • anim curve header array
      • anim curve frame and value data array
  • fvba data array:
    • default result array
    • fast bind array
    • bone name array
    • anim curve header array
    • anim curve frame and value data array
  • fmaa data array:
    • fast bind array
    • per material anim header array
    • runtime texture view descriptor slot array
    • runtime texture view pointer array
    • texture name array
    • per material anim data array:
      • shader param anim array
      • texture pattern anim array
      • constant array
      • anim curve header array
      • anim curve frame and value data array
  • fsha data array:
    • fast bind table
    • vertex shape anim header array
    • vertex shape anim data array:
      • key shape anim array
      • anim curve header array
      • default result array
      • anim curve frame and value data array
  • fscn data array:
    • fcam header array
    • flit header array
    • ffog header array
    • fcam dictionary
    • flit dictionary
    • ffog dictionary
    • fcam data array:
      • anim curve header array
      • default result
      • anim curve frame and value data array
    • flit data array:
      • anim curve header array
      • default result
      • anim curve frame and value data array
    • ffog data array:
      • anim curve header array
      • default result
      • anim curve frame and value data array
  • string pool
  • gpu region:
    • index buffer data
    • vertex buffer data
  • runtime memory pool
  • embed file region
  • relocation table

Header (nn::g3d2::ResFile)

A bfres file header collects a number of optional resources that can be iterated through by array or looked up by name through dictionary. Resources include 3d model data, model animation data, scene animation data, and embedded files. A Bfres can contain a "GPU region", a block of memory meant to be made GPU visible, or reference an external GPU region.

Offset Size Type Description
0x0 0x20 nn::util::BinaryFileHeader Base header with magic of "FRES ".
0x20 0x8 const char * (NW) File name
0x28 0x8 ResModel * Model array
0x30 0x8 nn::util::ResDic * Model dictionary
0x38 0x8 void*[4]
0x58 0x8 ResSkeletalAnim * Skeletal animation array
0x60 0x8 nn::util::ResDic * Skeletal animation dictionary
0x68 0x8 ResMaterialAnim * Material animation array
0x70 0x8 nn::util::ResDic * Material animation dictionary
0x78 0x8 ResBoneVisibilityAnim * Bone visibility animation array
0x80 0x8 nn::util::ResDic * Bone visibility animation dictionary
0x88 0x8 ResShapeAnim * Shape animation array
0x90 0x8 nn::util::ResDic * Shape animation dictionary
0x98 0x8 ResSceneAnim * Scene animation array
0xa0 0x8 nn::util::ResDic * Scene animation dictionary
0xa8 0x8 nn::gfx::TMemoryPool * Runtime MemoryPool (set by g3d)
0xb0 0x8 nn::gfx::MemoryPoolInfo Pre-initialized MemoryPool info pointing to GPU region
0xb8 0x8 nn::gfx::ResEmbedFile * Embed file array
0xc0 0x8 nn::util::ResDic * Embed file dictionary
0xc8 0x8 void * User pointer in EPD software. (possibly a UI tree in nn::ui?)
0xd0 0x8 const char * (NW)
0xd8 0x4 u32
0xdc 0x2 u16 Model array count
0xde 0x2 u16
0xe0 0x2 u16
0xe2 0x2 u16 Skeletal animation array count
0xe4 0x2 u16 Material animation array count
0xe6 0x2 u16 Bone visibility animation count
0xe8 0x2 u16 Shape animation count
0xea 0x2 u16 Scene animation count
0xec 0x2 u16 Embed file count
0xee 0x2 u16

Model (nn::g3d2::ResModel)

A model represents a collection of 3d shape data, material data, and a skeleton.

Offset Size Type Description
0x0 0x4 u32 Magic, always "FMDL"
0x4 0x4 u32
0x8 0x8 const char* (NW) Model name
0x10 0x8 const char* (NW)
0x18 0x8 ResSkeleton* Skeleton
0x20 0x8 ResVertex* Vertex array
0x28 0x8 ResShape* Shape array
0x30 0x8 nn::util::ResDic* Shape dictionary
0x38 0x8 ResMaterial* Material array
0x40 0x8 nn::util::ResDic* Material dictionary
0x48 0x8 ResShaderReflection* Shader reflection array
0x50 0x8 Gfx User Data* User data array
0x58 0x8 nn::util::ResDic* User data dictionary
0x60 0x8 void * Runtime user pointer
0x68 0x2 u16 Vertex count
0x6a 0x2 u16 Shape count
0x6c 0x2 u16 Material count
0x6e 0x2 u16 Shader reflection count
0x70 0x2 u16 User data count
0x72 0x6

Vertex (nn::g3d2::ResVertex)

A ResVertex references a collection of vertex buffers in the GPU region. Reflection and settings are provided for the vertex buffers and attributes. Runtime object memory is provided to initialize graphics api objects for the vertex buffers.

Offset Size Type Description
0x0 0x4 u32 Magic "FVTX"
0x4 0x4 u32
0x8 0x8 ResVertexAttribute* Vertex atribute array
0x10 0x8 nn::util::ResDic* Vertex attribute dictionary
0x18 0x8 void * Runtime memory pool pointer
0x20 0x8 void * Runtime vertex buffer array (0x48 bytes of zeroed memory per vertex buffer)
0x28 0x8 void ** Runtime user vertex buffer array
0x30 0x8 nn::gfx::BufferInfo* Vertex buffer info array
0x38 0x8 ResVertexBufferStride* Vertex buffer stride array
0x40 0x8 void * Runtime user pointer
0x48 0x4 u32 Base offset of vertex data in GPU region, relative to start of GPU region
0x4c 0x1 u8 Vertex attribute count
0x4d 0x1 u8 Vertex buffer count
0x4e 0x2 u16 Index of this section in parent ResModel
0x50 0x4 u32 Vertex count
0x54 0x2 u16
0x56 0x2 u16 Alignment of vertex buffer data in GPU region
ResVertexAttribute
Offset Size Type Description
0x0 0x8 const char* (NW) Attribute name
0x8 0x4 u32, nn::gfx::AttributeFormat Attribute format
0xc 0x2 u16 Buffer offset
0xe 0x1 u8 Buffer index
0xf 0x1 u8 Indicates whether this is a dynamic vertex attribute for shape blending
ResVertexBufferStride

Unused bytes might indicate nn::gfx::VertexBufferInfo.

Offset Size Type Description
0x0 0x4 u32 Stride
0x4 0x4 u32 Divisor
0x8 0x4 u32
0xc 0x4 u32

Shape (nn::g3d2::ResShape)

A shape represents 3d mesh data. Either via a set of level-of-detail meshes into the vertex buffers of a ResVertex, or alternatively in v10.2.0 onwards, a set of meshlet buffers.

Offset Size Type Description
0x0 0x4 u32 Magic "FSHP"
0x4 0x4 u32 Flags
0x8 0x8 const char* (NW) Shape name
0x10 0x8 ResVertex* Referenced vertex
0x18 0x8 ResMesh* or ResMeshlet* Level-of-detail mesh array, or if flags bit 4 is set, a ResMeshlet
0x20 0x8 u16* Skinning bone index array
0x28 0x8 ResKeyShape* Key shape array
0x30 0x8 nn::util::ResDic* Key shape dictionary
0x38 0x8 ResBounding* Bounding box array
0x40 0x8 ResBoundingSphere* Bounding sphere array
0x48 0x8 void * Runtime user pointer
0x50 0x2 u16 Index of this section in parent ResModel
0x52 0x2 u16 Material index
0x54 0x2 u16 Base bone index
0x56 0x2 u16 Vertex index
0x58 0x2 u16 Skin bone index count
0x5a 0x1 u8 Vertex skin weight count
0x5b 0x1 u8 Mesh count
0x5c 0x1 u8 Key shape count
0x5d 0x1 u8 Target attribute count
0x5e 0x2 u16
ResMesh
Offset Size Type Description
0x0 0x8 ResSubMeshRange* Array of sub mesh ranges
0x8 0x8 void * Runtime memory pool pointer
0x10 0x8 void * Runtime index buffer memory (0x48 bytes of zeroed memory)
0x18 0x8 nn::gfx::BufferInfo* Index buffer info
0x20 0x4 u32 Offset of index buffer in GPU region relative to start of GPU region
0x24 0x4 u32, nn::gfx::PrimitiveTopology Primitive topology to use for drawing commands
0x28 0x4 u32, nn::gfx::IndexFormat Index format to use in drawing commands
0x2c 0x4 u32 Index count
0x30 0x4 u32 Base vertex
0x34 0x2 u16 Sub mesh count
0x36 0x2 u16
ResSubMeshRange
Offset Size Type Description
0x0 0x4 u32 Offset of sub mesh relative to start of index buffer
0x4 0x4 u32 Index count of sub mesh
ResKeyShape
Offset Size Type Description
0x0 0x12 u8[18] Relative key shape attribute location array
0x12 0x2 u8[2]
ResBounding
Offset Size Type Description
0x0 0xc Float3 Position
0xc 0xc Float3 Extent
ResBoundingSphere
Offset Size Type Description
0x0 0xc Float3 Position
0xc 0x4 float Radius
ResMeshlet

Currently only observed unused in Nintendo Switch Online: Playtest Program.

Offset Size Type Description
0x0 0x8 ...
0x8 0x8 void * Runtime meshlet buffer array (0x48 bytes of zeroed memory per meshlet buffer)
0x10 0x8 nn::gfx::BufferInfo* Meshlet buffer info array
0x18 0x8 s64 * Meshlet buffer memory offset array, each entry relative to start of GPU region
0x20 0x24 ...
0x44 0x1 u8 Meshlet buffer count
0x45 0x3 ...

Shader Reflection

A ResShaderReflection provides reflection for resolving material parameter data for a shader inside a bfsha shader archive.

Offset Size Type Description
0x0 0x8 const char* (NW) Shader archive name
0x8 0x8 const char* (NW) Shader name
0x10 0x8 ResRenderInfo* Render info array
0x18 0x8 nn::util::ResDic* Render info dictionary
0x20 0x8 ResShaderParam* Material shader parameter array
0x28 0x8 nn::util::ResDic* Material shader parameter dictionary
0x30 0x8 nn::util::ResDic* Vertex attribute dictionary
0x38 0x8 nn::util::ResDic* Sampler dictionary
0x40 0x8 nn::util::ResDic* Static shader option dictionary
0x48 0x2 u16 Render info count
0x4a 0x2 u16 Shader parameter count
0x4c 0x2 u16 Shader parameter data size
0x4e 0xa u8[10]
ResRenderInfo

Render info provides reflection for CPU-side rendering parameters.

Offset Size Type Description
0x0 0x8 const char* (NW) Render info name
0x8 0x1 u8 Render info data type
0x9 0x7 u8[7]
Render info data type
Name Value Description
Int 0 Value is a 32-bit integer
Float 1 Value is a 32-bit float
String 2 Value is an NW string pointer
ResShaderParam

ResShaderParam's compose a user generated structure layout for a material uniform buffer. Shader parameters can be animated through material animations.

Offset Size Type Description
0x0 0x8 u32(*)(void*,const void*,ResShaderParam*, void*) Runtime conversion function for data types requiring runtime conversion of a CPU representation to a GPU representation
0x8 0x8 const char* (NW) Shader parameter name
0x10 0x2 u16 Shader parameter offset
0x12 0x1 u8 Shader parameter data type
0x13 0x5 u8[5]
Shader parameter data type
Name Value Description
Bool 0
Bool2 1
Bool3 2
Bool4 3
Int 4
Int2 5
Int3 6
Int4 7
UInt 8
UInt2 9
UInt3 10
UInt4 11
Float 12
Float2 13
Float3 14
Float4 15
Matrix2x2 17
Matrix2x3 18
Matrix2x4 19
Matrix3x2 20
Matrix3x3 21
Matrix3x4 22
Matrix4x2 23
Matrix4x3 24
Matrix4x4 25
Srt2d 26
Srt3d 27
SrtTexture 28

Material (nn::g3d2::ResMaterial)

Offset Size Type Description
0x0 0x4 u32 Magic "FMAT"
0x4 0x4 u32 Flags (bit 0 = is visible)
0x8 0x8 const char* (NW) Material name
0x10 0x8 ResStaticShaderVariation* Static shader variation
0x18 0x8 void** Runtime texture view pointer array
0x20 0x8 const char** (NW) Texture name array
0x28 0x8 void* Runtime sampler array (0x78 bytes of zeroed memory per sampler)
0x30 0x8 nn::gfx::SamplerInfo* Sampler info array
0x38 0x8 nn::util::ResDic* Sampler dictionary
0x40 0x8 void* Render info value array
0x48 0x8 u16* Render info value count array
0x50 0x8 u16* Render info value offset array
0x58 0x8 void* Shader parameter value array
0x60 0x8 s32* Runtime shader parameter material uniform buffer offset array
0x68 0x8 u64
0x70 0x8 Gfx user data* User data array
0x78 0x8 nn::util::ResDic* User data dictionary
0x80 0x8 u32 * Shader parameter runtime convert bit array
0x88 0x8 void* Runtime user pointer
0x90 0x8 u64* Runtime sampler descriptor slot array
0x98 0x8 u64* Runtime texture view descriptor slot array
0xa0 0x2 u16 Index of this section in parent ResModel
0xa2 0x1 u8 Sampler count
0xa3 0x1 u8 Texture count
0xa4 0x2 u16 Is force calculate material
0xa6 0x2 u16 User data count
0xa8 0x2 u16 Render info value size
0xaa 0x2 u16 Runtime material uniform buffer size
0xac 0x4 u32
ResStaticShaderVariation

A material references a ResStaticShaderVariation which selects the material's static shader variation out of the shader referenced by a ResShaderReflection.

Offset Size Type Description
0x0 0x8 ResShaderReflection* Shader reflection
0x8 0x8 const char** (NW) Vertex attribute name array, of those used in this specific static shader variation
0x10 0x8 u8* Vertex attribute index array
0x18 0x8 const char** (NW) Sampler name array, of those used in this specific static shader variation
0x20 0x8 u8* Sampler index array
0x28 0x8 u32* Static shader option choice packed bool array
0x30 0x8 const char** (NW) Static shader option choice string array
0x38 0x8 u16* Static shader option index array
0x40 0x4 u32
0x44 0x1 u8 Vertex attribute count
0x45 0x1 u8 Sampler count
0x46 0x2 u16 Static shader option bool count
0x48 0x2 u16 Total static shader option count
0x4a 0x6 u8[6]