TXTR (Tropical Freeze): Difference between revisions

From Retro Modding Wiki
Jump to navigation Jump to search
>Aruki
(Created page with "''See TXTR (File Format) for the other revisions of this format.'' The '''TXTR''' format is Tropical Freeze's texture format. The image data in the GPU buffer is compress...")
 
>Aruki
 
(16 intermediate revisions by the same user not shown)
Line 3: Line 3:
The '''TXTR''' format is Tropical Freeze's texture format. The image data in the GPU buffer is compressed using [[LZSS Compression|LZSS compression]].
The '''TXTR''' format is Tropical Freeze's texture format. The image data in the GPU buffer is compressed using [[LZSS Compression|LZSS compression]].


{{research|major|Most everything in the header + image compression formats needs to be cracked + documented.}}
{{research|moderate|There are a couple unknowns in the header. It would also be good to have some documentation on how to deswizzle/decompress different texture formats.}}


__TOC__
__TOC__
Line 9: Line 9:
== Format ==
== Format ==


The format starts with the typical [[RFRM Header]] found in every Tropical Freeze format. Following that, there's a HEAD header section that contains most of the texture parameters, then the GPU section containing the actual compressed image data. This is the structure of the HEAD section:
The format starts with the typical [[Form Descriptor (Tropical Freeze)|form descriptor]] found in every Tropical Freeze format. Following that, there's a HEAD header section that contains most of the texture parameters, then the GPU section containing the actual compressed image data. This is the structure of the HEAD section:


{| class="wikitable"
{| class="wikitable"
! Offset
! Offset
! Type
! style="width:110px;"|Type
! Size
! style="width:100px;"|Count
! Description
! style="width:170px;"|Name
! Notes
! Notes
|-
|-
| 0x0
| 0x0
| [[Section Header]]
| [[Chunk Descriptor (Tropical Freeze)|Chunk Descriptor]]
| 0x18
| 1
| '''"HEAD" section header'''
| '''HEAD Chunk Descriptor'''
|  
|  
|-
|-
| 0x18
| 0x18
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| [[#Texture Type|'''Texture Type''']]
|  
| Describes the type/dimensionality of the texture (2D texture, 3D texture, cubemap, array of 2D images, etc).
|-
|-
| 0x1C
| 0x1C
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| [[#Texture Format|'''Texture Format''']]
|  
| Describes the format that the image data is encoded in.
|-
|-
| 0x20
| 0x20
| u32
| u32
| 4
| 1
| '''Width'''
| '''Width'''
|  
| Texture X resolution.
|-
|-
| 0x24
| 0x24
| u32
| u32
| 4
| 1
| '''Height'''
| '''Height'''
|  
| Texture Y resolution.
|-
|-
| 0x28
| 0x28
| u32
| u32
| 4
| 1
| '''Depth'''
| '''Depth'''
|  
| Texture Z resolution.
|-
|-
| 0x2C
| 0x2C
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| '''Tile Mode'''
|  
| Indicates how the texture image data is tiled.
|-
|-
| 0x30
| 0x30
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| '''Swizzle'''
|  
| Indicates how the texture image data is swizzled.
|-
|-
| 0x34
| 0x34
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| '''Mipmap Count'''
| Mipmap count? (MC)
|  
|-
|-
| 0x38
| 0x38
| u32[MC]
| u32
| 4 × MC
| ''Mipmap Count''
| {{unknown|Unknown array}}
| '''Mipmap Sizes'''
| Appears to be mipmap sizes, but it doesn't match the size of the image data (unless there's 1)...
| The size of the base level mipmap is calculated with padding and alignment taken into account. The size of subsequent mipmaps is calculated as Width*Height*Depth*BPP/8. This does '''not''' take padding and alignment into account, and so it does not accurately reflect the amount of space the mipmap takes up in the file, and it cannot be used to accurately locate and read mipmap data. The offset and size needs to be calculated from the other parameters in the header. The game calculates this data by calling GX2CalcSurfaceSizeAndAlignment.
|-
|-
| -
| {{none}}
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| {{unknown|Unknown}}
|  
| This parameter is part of NTextureFormat::STextureSamplerData (along with the next 4 parameters)
|-
|-
| -
| {{none}}
| u8
| u8
| 1
| 1
| {{unknown|Unknown}}
| [[#Texture Filter|'''Texture Filter''']]
|  
| Determines how the texture is filtered when sampled.
|-
|-
| -
| {{none}}
| u8
| u8
| 1
| 1
| {{unknown|Unknown}}
| [[#Texture Wrap|'''Texture Wrap X''']]
|  
| Determines how the texture wraps on the X coordinate.
|-
|-
| -
| {{none}}
| u8
| u8
| 1
| 1
| {{unknown|Unknown}}
| [[#Texture Wrap|'''Texture Wrap Y''']]
|  
| Determines how the texture wraps on the Y coordinate.
|-
|-
| -
| {{none}}
| u8
| u8
| 1
| 1
| {{unknown|Unknown}}
| [[#Texture Wrap|'''Texture Wrap Z''']]
|  
| Determines how the texture wraps on the Z coordinate.
|}
 
=== Texture Type ===
 
This enum basically maps directly to a GX2SurfaceDim enum.
 
{| class="wikitable"
! ID
! Type
|-
| 0
| 1D Texture
|-
| 1
| 2D Texture
|-
| 2
| 3D Texture
|-
| 3
| Cube Texture
|-
| 4
| 1D Texture Array
|-
| 5
| 2D Texture Array
|-
| 6
| Multisampled 2D Texture
|-
| 7
| Multisampled 2D Texture Array
|}
 
=== Texture Format ===
 
{| class="wikitable"
! ID
! GX2SurfaceFormat
|-
| 0x00
| GX2_SURFACE_FORMAT_TC_R8_UNORM
|-
| 0x01
| GX2_SURFACE_FORMAT_TC_R8_SNORM
|-
| 0x02
| GX2_SURFACE_FORMAT_TC_R8_UINT
|-
| 0x03
| GX2_SURFACE_FORMAT_TC_R8_SINT
|-
| 0x04
| GX2_SURFACE_FORMAT_TCD_R16_UNORM
|-
| 0x05
| GX2_SURFACE_FORMAT_TC_R16_SNORM
|-
| 0x06
| GX2_SURFACE_FORMAT_TC_R16_UINT
|-
| 0x07
| GX2_SURFACE_FORMAT_TC_R16_SINT
|-
| 0x08
| GX2_SURFACE_FORMAT_TC_R16_FLOAT
|-
| 0x09
| GX2_SURFACE_FORMAT_TC_R32_UINT
|-
| 0x0A
| GX2_SURFACE_FORMAT_TC_R32_SINT
|-
| 0x0B
| GX2_SURFACE_FORMAT_INVALID
|-
| 0x0C
| GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM
|-
| 0x0D
| GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_SRGB
|-
| 0x0E
| GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_FLOAT
|-
| 0x0F
| GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_FLOAT
|-
| 0x10
| GX2_SURFACE_FORMAT_TCD_R16_UNORM
|-
| 0x11
| GX2_SURFACE_FORMAT_TCD_R16_UNORM
|-
| 0x12
| GX2_SURFACE_FORMAT_D_D24_S8_UNORM
|-
| 0x13
| GX2_SURFACE_FORMAT_TCD_R32_FLOAT
|-
| 0x14
| GX2_SURFACE_FORMAT_T_BC1_UNORM
|-
| 0x15
| GX2_SURFACE_FORMAT_T_BC1_SRGB
|-
| 0x16
| GX2_SURFACE_FORMAT_T_BC2_UNORM
|-
| 0x17
| GX2_SURFACE_FORMAT_T_BC2_SRGB
|-
| 0x18
| GX2_SURFACE_FORMAT_T_BC3_UNORM
|-
| 0x19
| GX2_SURFACE_FORMAT_T_BC3_SRGB
|-
| 0x1A
| GX2_SURFACE_FORMAT_T_BC4_UNORM
|-
| 0x1B
| GX2_SURFACE_FORMAT_T_BC4_SNORM
|-
| 0x1C
| GX2_SURFACE_FORMAT_T_BC5_UNORM
|-
| 0x1D
| GX2_SURFACE_FORMAT_T_BC5_SNORM
|-
| 0x1E
| GX2_SURFACE_FORMAT_TC_R11_G11_B10_FLOAT
|-
| 0x1F
| GX2_SURFACE_FORMAT_TCD_R32_FLOAT
|-
| 0x20
| GX2_SURFACE_FORMAT_TC_R16_G16_FLOAT
|-
| 0x21
| GX2_SURFACE_FORMAT_TC_R8_G8_UNORM
|}
 
=== Texture Filter ===
 
Invalid values default to 1 (linear).
 
{| class="wikitable"
! ID
! GX2TexMipFilterType
|-
| 0
| GX2_TEX_MIP_FILTER_POINT
|-
| 1
| GX2_TEX_MIP_FILTER_LINEAR
|}
 
=== Texture Wrap ===
 
Invalid values default to 0 (clamp).
 
{| class="wikitable"
! ID
! GX2TexClamp
|-
| 0
| GX2_TEX_CLAMP_CLAMP
|-
| 1
| GX2_TEX_CLAMP_WRAP
|-
| 2
| GX2_TEX_CLAMP_MIRROR
|-
| 3
| GX2_TEX_CLAMP_MIRROR_ONCE
|}
|}


Line 116: Line 294:
! Offset
! Offset
! Type
! Type
! Size
! Count
! Description
! Name
! Notes
! Notes
|-
|-
| 0x0
| 0x0
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| {{unknown|Unknown}}
|  
| Always 4
|-
|-
| 0x4
| 0x4
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| {{unknown|Unknown}}
|  
|  
Line 134: Line 312:
| 0x8
| 0x8
| u32
| u32
| 4
| 1
| '''GPU section offset'''
| '''GPU Section Offset'''
| Relative to the start of the file
| Relative to the start of the file
|-
|-
| 0xC
| 0xC
| u32
| u32
| 4
| 1
| {{unknown|Unknown}}
| '''Base Alignment'''
|  
| Alignment of the surface image data
|-
|-
| 0x10
| 0x10
| u32
| u32
| 4
| 1
| '''GPU data start'''
| '''GPU Data Start'''
| This is the offset to the start of the GPU data, immediately after the GPU section header.
| This is the offset to the start of the GPU data, immediately after the GPU section header.
|-
|-
| 0x14
| 0x14
| u32
| u32
| 4
| 1
| '''GPU section size'''
| '''GPU Section Size'''
| Matches the size from the GPU section header.
| Matches the size from the GPU section header.
|-
|-
| 0x18
| 0x18
| u32
| u32
| 4
| 1
| '''Compressed buffer count''' (BC)
| '''Compressed Buffer Count'''
|  
|  
|-
|-
| 0x1C
| 0x1C
| [[#Compressed Buffer|Compressed Buffer]][BC]
| [[#Compressed Buffer|Compressed Buffer]]
| 0xC × BC
| ''Compressed Buffer Count''
| '''Compressed buffer metadata'''
| '''Compressed Buffer Array'''
|  
|  
|}
|}
Line 176: Line 354:
! Offset
! Offset
! Type
! Type
! Description
! Name
! Notes
! Notes
|-
|-

Latest revision as of 21:04, 17 December 2017

See TXTR (File Format) for the other revisions of this format.

The TXTR format is Tropical Freeze's texture format. The image data in the GPU buffer is compressed using LZSS compression.


This file format needs more research
There are a couple unknowns in the header. It would also be good to have some documentation on how to deswizzle/decompress different texture formats.


Format

The format starts with the typical form descriptor found in every Tropical Freeze format. Following that, there's a HEAD header section that contains most of the texture parameters, then the GPU section containing the actual compressed image data. This is the structure of the HEAD section:

Offset Type Count Name Notes
0x0 Chunk Descriptor 1 HEAD Chunk Descriptor
0x18 u32 1 Texture Type Describes the type/dimensionality of the texture (2D texture, 3D texture, cubemap, array of 2D images, etc).
0x1C u32 1 Texture Format Describes the format that the image data is encoded in.
0x20 u32 1 Width Texture X resolution.
0x24 u32 1 Height Texture Y resolution.
0x28 u32 1 Depth Texture Z resolution.
0x2C u32 1 Tile Mode Indicates how the texture image data is tiled.
0x30 u32 1 Swizzle Indicates how the texture image data is swizzled.
0x34 u32 1 Mipmap Count
0x38 u32 Mipmap Count Mipmap Sizes The size of the base level mipmap is calculated with padding and alignment taken into account. The size of subsequent mipmaps is calculated as Width*Height*Depth*BPP/8. This does not take padding and alignment into account, and so it does not accurately reflect the amount of space the mipmap takes up in the file, and it cannot be used to accurately locate and read mipmap data. The offset and size needs to be calculated from the other parameters in the header. The game calculates this data by calling GX2CalcSurfaceSizeAndAlignment.
u32 1 Unknown This parameter is part of NTextureFormat::STextureSamplerData (along with the next 4 parameters)
u8 1 Texture Filter Determines how the texture is filtered when sampled.
u8 1 Texture Wrap X Determines how the texture wraps on the X coordinate.
u8 1 Texture Wrap Y Determines how the texture wraps on the Y coordinate.
u8 1 Texture Wrap Z Determines how the texture wraps on the Z coordinate.

Texture Type

This enum basically maps directly to a GX2SurfaceDim enum.

ID Type
0 1D Texture
1 2D Texture
2 3D Texture
3 Cube Texture
4 1D Texture Array
5 2D Texture Array
6 Multisampled 2D Texture
7 Multisampled 2D Texture Array

Texture Format

ID GX2SurfaceFormat
0x00 GX2_SURFACE_FORMAT_TC_R8_UNORM
0x01 GX2_SURFACE_FORMAT_TC_R8_SNORM
0x02 GX2_SURFACE_FORMAT_TC_R8_UINT
0x03 GX2_SURFACE_FORMAT_TC_R8_SINT
0x04 GX2_SURFACE_FORMAT_TCD_R16_UNORM
0x05 GX2_SURFACE_FORMAT_TC_R16_SNORM
0x06 GX2_SURFACE_FORMAT_TC_R16_UINT
0x07 GX2_SURFACE_FORMAT_TC_R16_SINT
0x08 GX2_SURFACE_FORMAT_TC_R16_FLOAT
0x09 GX2_SURFACE_FORMAT_TC_R32_UINT
0x0A GX2_SURFACE_FORMAT_TC_R32_SINT
0x0B GX2_SURFACE_FORMAT_INVALID
0x0C GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM
0x0D GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_SRGB
0x0E GX2_SURFACE_FORMAT_TC_R16_G16_B16_A16_FLOAT
0x0F GX2_SURFACE_FORMAT_TC_R32_G32_B32_A32_FLOAT
0x10 GX2_SURFACE_FORMAT_TCD_R16_UNORM
0x11 GX2_SURFACE_FORMAT_TCD_R16_UNORM
0x12 GX2_SURFACE_FORMAT_D_D24_S8_UNORM
0x13 GX2_SURFACE_FORMAT_TCD_R32_FLOAT
0x14 GX2_SURFACE_FORMAT_T_BC1_UNORM
0x15 GX2_SURFACE_FORMAT_T_BC1_SRGB
0x16 GX2_SURFACE_FORMAT_T_BC2_UNORM
0x17 GX2_SURFACE_FORMAT_T_BC2_SRGB
0x18 GX2_SURFACE_FORMAT_T_BC3_UNORM
0x19 GX2_SURFACE_FORMAT_T_BC3_SRGB
0x1A GX2_SURFACE_FORMAT_T_BC4_UNORM
0x1B GX2_SURFACE_FORMAT_T_BC4_SNORM
0x1C GX2_SURFACE_FORMAT_T_BC5_UNORM
0x1D GX2_SURFACE_FORMAT_T_BC5_SNORM
0x1E GX2_SURFACE_FORMAT_TC_R11_G11_B10_FLOAT
0x1F GX2_SURFACE_FORMAT_TCD_R32_FLOAT
0x20 GX2_SURFACE_FORMAT_TC_R16_G16_FLOAT
0x21 GX2_SURFACE_FORMAT_TC_R8_G8_UNORM

Texture Filter

Invalid values default to 1 (linear).

ID GX2TexMipFilterType
0 GX2_TEX_MIP_FILTER_POINT
1 GX2_TEX_MIP_FILTER_LINEAR

Texture Wrap

Invalid values default to 0 (clamp).

ID GX2TexClamp
0 GX2_TEX_CLAMP_CLAMP
1 GX2_TEX_CLAMP_WRAP
2 GX2_TEX_CLAMP_MIRROR
3 GX2_TEX_CLAMP_MIRROR_ONCE

PAK Metadata

The pak metadata for the TXTR format primarily contains compression-related information and provides the values required to decompress it.

Offset Type Count Name Notes
0x0 u32 1 Unknown Always 4
0x4 u32 1 Unknown
0x8 u32 1 GPU Section Offset Relative to the start of the file
0xC u32 1 Base Alignment Alignment of the surface image data
0x10 u32 1 GPU Data Start This is the offset to the start of the GPU data, immediately after the GPU section header.
0x14 u32 1 GPU Section Size Matches the size from the GPU section header.
0x18 u32 1 Compressed Buffer Count
0x1C Compressed Buffer Compressed Buffer Count Compressed Buffer Array

Compressed Buffer

This is a small struct that defines a compressed data buffer within the GPU section.

Offset Type Name Notes
0x0 u32 Decompressed Size
0x4 u32 Compressed Size
0x8 u32 Offset Relative to after the GPU section header