AWTools icon indicating copy to clipboard operation
AWTools copied to clipboard

Hi

Open Bxaa opened this issue 5 years ago • 12 comments

Thanks for your work! I have a some questions: I alredy make all remastered textures for alan wake, but cant repack it. How can i correcly convert dds\tga to alanwake tex? (i try use old Alan wake tool v0.5 https://zenhax.com/viewtopic.php?t=1029) but all reexported textures is broken (seems to be convertion broke mips)

I have a lot of experience with different formats, but I cannot understand this alan wake "tex" unuseful container for dds. Is this format unique for this game (it is not as some old tex from serios sam)?

My remasters textures: https://www.nexusmods.com/oblivion/mods/50381 https://www.nexusmods.com/newvegas/mods/69848 https://www.nexusmods.com/fallout3/mods/24340

Bxaa avatar Oct 06 '20 01:10 Bxaa

Hi Bxaa, as of now, I don't know of any tools capable of converting dds/tga images to tex. The tex format is pretty straightforward with a fixed size header. You can see the header meanings in lines 199-207 of tex2tga.py where every field is a little endian 4 byte integer and the corresponding enums for type and format in lines 26-49. The reason why I didn't wrote such a tool, is for the simple lack of a decent dxt compression library in python. Also, you have to consider mipmaps when creating tex files, which are not even considered in tex2tga. From what I know, the tex format is unique to Alan Wake and Alan Wakes American Nightmare (Quantum Break and Control have also tex files, but these are actually dds files). I didn't looked into serious sam but considering the fact, that the Alan Wake/Northlight Engine was an Inhouse Engine, I highly doubt that anyone else used this format. If you have any more questions, feel free to ask :)

Nostritius avatar Nov 08 '20 12:11 Nostritius

HI, DDS2TEX with correct new TEX header for DDS (if dds size is changed) this is main task (not tga or png) Also: change format or type not necessary, because new textures is full equal type and format except only SIZE

After TEX header standard DDS header and standard dds image (tex is just container) You don't need any compress coding - just build new TEX header with preserving old type and format. Thats all. This is 100% solution for Alan Wake.

While packing textures, you need to recalculate new offsets (bin/rmdp2), because the size of the new textures will be different.

If you want i can give you some remastered textures for test? Sorry my english :)

Bxaa avatar Jan 23 '21 07:01 Bxaa

Hi Bxaa, I will take a look into a dds2tex tool, just keep in mind that this tool won't be able to create certain types of textures, for example lightmaps, since they use probably a custom swizzling scheme (haven't researched this). Could you send me some examplery dds files, so I can see how you intend to save them? Furthermore, here are some information I learned about the engine, which might be relevant for you:

  • The files in the resourcedb directory (cid_streamed*.bin) contain meta information about the files, including textures. There for example the width, height and mipmapcount are saved. Also you should keep in mind, that if you create new texture besides the old ones, the meshs reference their textures. I don't know if the engine uses this values.
  • In newer games, this is replaced by the packmeta files and the *.meta files.
  • If you intend to use my rmdp tool, you should keep in mind, that it currently only works for Nightmare

Nostritius avatar Jan 23 '21 12:01 Nostritius

Hi, Nostritius! Don't worry about mips and lightmaps (forget my first post. Reason of broken textures is wrong sizes in headers...i think) Also i can make original mip count for each textures.

Also you should keep in mind, that if you create new texture besides the old ones, the meshs reference their textures. I don't know if the engine uses this values.

I replace all textures with same name. UV map and upscaled textures it is directx\d3d, not engine (no problem as in any other game)

About cid streamed*.bin: if engine use W\H sizes and it provide issues - we need just *4 all values (W\H) for each texture in it's meta data, if texture height or width > 96 (i skip texures <= 96x96 and will use original tex). Upsacale factor is static and it is 4.

Yes, this alanwake2008headb not bad in original, but i took it as example texture alanwake2008headb(NEW TEXTURE).dds - My new texture (preserved mip count and original format DTX1\BC1_Unorm and image type in dds container) alanwake2008headb.tex - original tex container from ep999-000 game data alanwake2008headb(RIPPED FROM TEX).dds - Ripped data from TEX (it is a correct DDS texture) NOTE : alanwake2008headb.TEX contain alanwake2008headb(RIPPED FROM TEX).dds as raw data after TEX header)

Our task is a making from new DDS texture correct TEX

Official tools from nvidia site: https://developer.nvidia.com/nvidia-texture-tools-exporter (use 'Standalone Application' - need reg to download)

  • you can make it for default opening dds (to control wrong dds format or else)

DDS Thumbnail Viewer https://developer.nvidia.com/sites/default/files/akamai/tools/files/DDS_viewer.exe

  • it show miniatures for dds like for other pictures files in windows file explorer (very useful)

Example TEX\DDS: https://drive.google.com/file/d/1wEpgen-5Cli4o5Ka1o-JJ0PIfAXx2HVa/view?usp=sharing

Bxaa avatar Jan 24 '21 07:01 Bxaa

I just added a new dds2tex tool, which can only export formats 5, 7 and 9 which are effectively DXT1,3,5 compressed images. Could you test, if it is sufficient for your needs?

Nostritius avatar Jan 24 '21 20:01 Nostritius

Hi, Nostritius! Thanks for you dds2tex. But in game textures still work not correctly. I'll try to understand why it happened. Look at pic. Strange... hands texture is ok. (hands texture is modified too and equal format as other) https://i.ibb.co/vmQ3CqV/1.png

streamed*.bin?

I also added some code to your dds2tex for batch conversion, but i dont think it is a reason of issue. Python not my language :)

p_Input = 'C:\\To_Convert'
t_Paths = os.walk(os.path.abspath(p_Input + '/'))
for root, dirs, files in t_Paths:
    for o_file in files:      
        f_base = os.path.join(root, o_file)
        fdds = open(f_base, 'rb')
        ftex = open(os.path.join(root, pathlib.Path(f_base).stem) , 'wb') #Input files already with ext like texture.TEX.DDS in my case. Just remove 'dds'
        ----\\----\\----
        os.remove(f_base)

Textures for test that i try repack to game ep999-000 https://drive.google.com/file/d/1Vui1x_NTvFD76MAXJgA7gNA5xMqCjZzz/view?usp=sharing (already converted to tex) https://drive.google.com/file/d/10W7OHyNmc_i3SuvNMwcybuyHAk_BdU-e/view?usp=sharing (before converting to tex)

Bxaa avatar Jan 25 '21 09:01 Bxaa

Which tool do you use for packing the resources together? Could you try to unpack it using my unrmdp tool and then convert it with my tex2tga tool? In what folder lies the texture and does it show you the correct image? As I know from my own experience with these other tools, they throw away a lot of important information about the folder structure in the rmdp files.

Nostritius avatar Jan 25 '21 11:01 Nostritius

I tried your unrmdp, but:

Screen-1


Screen-2 And then i tried Alan wake tool v0.5 (seems to be it unpack correct tex, but not import)

Ok i'll try you tex2tga tool (but after conversion to tga we will lost dds format. it is important for dxt1\dtx3-5) Anyway...well, i will be look at _n suffix for normal map textures. Are your tex2tga correct save image alpha channels?

Archive with: ep999-000.bin and ep999-000.rmdp from latest GOG DRM-FREE game version.

  • (i'll add links when it uploaded)
  • Done https://drive.google.com/file/d/1r5kWJhhl9WUOOxjOqvIUyCOPmJPQ1LuO/view?usp=sharing

EDIT: Why you not use OpenCV (cv2.imwrite) in tex2tga?

Bxaa avatar Jan 25 '21 13:01 Bxaa

Ok, i fixed unrmdp.py for alan wake. I made a mistake when adding support for control and quantum break. The whole thing behind why I asked you to use it, is to exclude the possibility that the Alan Wake Tool puts it in the wrong place or corrupts it somehow. You can also verify it with my new tex2dds tool, I just pushed. I didnt used OpenCV because I wanted to keep the scripts as simple as possible. They are mainly intended for experimentation and serve as a reference for possible other, more production ready, implementations. Also, someone with little knowledge python and its ecosystem can use the tools without pulling a huge framework like opencv.

Nostritius avatar Jan 26 '21 21:01 Nostritius

Hi, Nostritius Your rmdp.py not needed a fix similar like unrmdp.py?

EDIT: You current version of rmdp.py make not correct archive For test: I just unpack ep999-000.rmdp with unrmdp.py and then repack it with rmdp.py If i try unpack it again - "Invalid folder name crc checksum" (game also not run with new archive)

EDIT: Other tools also not work with new archive

Bxaa avatar Jan 27 '21 02:01 Bxaa

Well, rmdp.py does only work with american nightmare (Where I did most of my testing).

Nostritius avatar Jan 28 '21 10:01 Nostritius

Ok...then it's all useless without rmdp pack script :)

Bxaa avatar Jan 28 '21 13:01 Bxaa