Guekka / bethutil

Common utilities for working with bethesda assets (dds, nif, bsa, hkx...)
https://guekka.github.io/bethutil/
Mozilla Public License 2.0
4 stars 2 forks source link

Ensure proper compatibility with FNV #44

Closed mklokocka closed 3 months ago

mklokocka commented 4 months ago

Hi, as discussed, there are several things that must be handled to have full compatibility with FNV (and other older titles I assume).

Crucial

Archive flags:
00000000000000001 - Named Directory - always set
00000000000000010 - Named Files - always set
00000000000000100 - Compressed - use zlib compression
00000000000010000 - Retain Names - set with sound effects
00000000010000000 - Startup Strings - set with meshes
00000000100000000 - Embed Name - set with textures

The first three are self-explanatory. The other three are important for the given asset type. That is, if the archive in question contains either of the noted types, it must have the given flag set.

The file tags are self-explanatory. The important thing is that for the BSA to be usable, it must have the correct file flags set depending on the content - otherwise, the game will never check the archive for the given type. Full mapping of file extensions to file flags (pulled from engine) in comments.

KF - This is a priority. Most animations are build with an engine extension that currently does not support BSA packed KF files.
MP3
XML
JSON
INI

Necessary improvements

The game supports DXT1, DXT3, and DXT5. DXT3 is useless. The current logic causes problems - textures without any alpha will be compressed with BC5 which is uncompatible with Dx9 the game uses (as far as I can tell). Textures using a single bit of alpha get processed with BC3 which fills out the alpha (for some reason), which can for example mess up the specular on normal textures. The correct logic is:

In fact, using DXGI_FORMAT_R8G8B8A8_UNORM when not compressing does break the specular as well (specular - alpha component of normal texture). Wonder if there is some explicit alpha adjustment being done by bethutil itself or it's due to the format.

~Mipmap generation - Mipmaps should be generated for everything but UI textures (textures/interface/*).~

Important note: Gamma correction should be applied (and only ever applied) to diffuse textures. Assuming standard conventions (described here) this means gamma correction should be applied to any texture not ending with _n/_m/_em/_g/_sk/_hl/_e.

Scratched. Turns out DirectXTex has no direct support for gamma correction of mipmaps. It could probably be done manually, but not worth the effort.

Nice to have

Not crucial, but would be very helpful.

mklokocka commented 4 months ago

Engine mapping of file extensions to file (archive) types:

"kf" -> ARCHIVE_TYPE_MESHES
"nif" -> ARCHIVE_TYPE_MESHES
"egm" -> ARCHIVE_TYPE_MESHES
"egt" -> ARCHIVE_TYPE_MESHES
"tri" -> ARCHIVE_TYPE_MESHES
"cmp" -> ARCHIVE_TYPE_MESHES
"lst" -> ARCHIVE_TYPE_MESHES
"dtl" -> ARCHIVE_TYPE_MESHES

"dds" -> ARCHIVE_TYPE_TEXTURES
"tai" -> ARCHIVE_TYPE_TEXTURES
"tga" -> ARCHIVE_TYPE_TEXTURES
"bmp" -> ARCHIVE_TYPE_TEXTURES

"wav" -> ARCHIVE_TYPE_SOUNDS

"ogg" -> ARCHIVE_TYPE_VOICES
"lip" -> ARCHIVE_TYPE_VOICES

"xml" -> ARCHIVE_TYPE_MENUS
"txt" -> ARCHIVE_TYPE_MENUS

"spt" -> ARCHIVE_TYPE_TREES

"fnt" -> ARCHIVE_TYPE_FONTS
"tex" -> ARCHIVE_TYPE_FONTS

"vso" -> ARCHIVE_TYPE_SHADERS
"pso" -> ARCHIVE_TYPE_SHADERS
"vsh" -> ARCHIVE_TYPE_SHADERS
"psh" -> ARCHIVE_TYPE_SHADERS
"lsl" -> ARCHIVE_TYPE_SHADERS
"h" -> ARCHIVE_TYPE_SHADERS
mklokocka commented 4 months ago

The striken-out points will better be handled by CAO (i.e. disabling compression, mesh/anim optimization, skipping LOD textures, override creation).

Guekka commented 3 months ago

Can we close this now @mklokocka?

mklokocka commented 3 months ago

Yeah, I think so. 👍