ndix UR

TOOL:tga2tpc

Recommended Posts

tga2tpc


tga2tpc

Author: ndix UR
Release: Sep 2020
Version: 4.0.0

Convert TGA images to TPC format for use in KotOR and TSL.

TPC files contain the information from a TXI file (so the TXI file is no longer needed when a TPC file is used), and can be uncompressed or compressed with either DXT1 or DXT5.

Advanced features like animation and cubemap layering are initiated by the presence of specific TXI directives like cube 1 and proceduretype cycle.

For some reason, the game really wants normal maps to be in TPC format. This will let you create and use full 32-bit color normal maps without having to make them into simple height maps by using indexed color.

The tool is free, open source, and cross-platform. Code is available at https://github.com/ndixUR/tga2tpc

The app is written in javascript, built on Electron using three.js, jquery, bootstrap. It includes a ported version of the AMD/GPUOpen Compressonator image compression library.

============================================================

How do I set it up?
Windows: unzip the package, run tga2tpc.exe

Mac: unzip the package, move tga2tpc.app to /Applications, run it
* This is not a signed application, so you have to do whatever is required to run non-MAS applications on your MacOS version.

============================================================

How do I use it?
Drag files in and hit start. There shouldn't be much more to it than that. Using power-of-2 sized textures is always required for optimal quality, TXI information is optional, and the settings are pretty much self-explanatory. The nature of TPC alpha blending is not necessarily intuitive so you may need to seek information to use it properly.

Compressor settings:

  • Super Fast - the lowest quality setting, uses the pre-4.0.0 image compressor that includes the 'compression failure' error for long conversion queues
  • Fast - Bare bones setting
  • Normal - Runs two profiles and selects the best result, adaptive color weighting
  • Slow - Deeper refinement of the color palette for each 4x4 pixel block
  • Ultra - 3D refinement of the color palette for each 4x4 pixel block

How Automatic encoding mode selects encoding for each texture in the queue:

  • 24bpp TGA = DXT1
  • 32bpp TGA = DXT5
  • 8bpp TGA = 8bpp uncompressed
  • isbumpmap1 or compresstexture 0 in TXI data = 24 or 32bpp uncompressed

============================================================

Features

  • Create cubemaps
  • Create animated textures
  • Automatic compression selection based on trends from the vanilla game
  • High quality DXT1/5 compression engine using custom ported version of AMD/GPUOpen Compressonator
  • Multi-core image compression on systems with 4 or more cores
  • Horizontal/Vertical flip, for those pesky wrongly oriented TGA files
  • Bicubic downsampling for mipmaps (precomputed lower detail versions of the texture, part of the TPC format)
  • Control texture alpha blending setting (part of TPC format), can be loaded from TXI file comments of the form: "# alphablending 0.67"


Known Issues

  • Cannot create uncompressed animated textures.
  • Super Fast compressor has a memory leak issue, leading to errors for long conversion queues
  • Using 4:1 and wider size ratios for individual frames of animated textures seem to crash the game. 2:1 is fine, 1:4 is fine, etc.
  • Only for converting from TGA to TPC. For TPC to TGA, use Kotor Tool, xoreos-tools, tpcview, etc.
  • Progress bar doesn't update as often as you might want.
  • The package size is large. This is the cost of easy cross-platform GUI support. All electron applications are large like this.
  • You are likely to have problems trying to read TGAs from folders containing markup entities/encoded characters (like ')

============================================================

Thanks
DarthParametric for inciting the creation of this tool, and doing the testing.
DrMcCoy and all the contributors to xoreos, whose TPC decoding implementation provided the basis for the TPC library herein.
bead-v for moral support.


 

  • Like 4

Share this post


Link to post
Share on other sites

These recent tools are amazing!

 

In one motion you apparently made TXI files obsolete and Photoshop unecessary for animations. I am looking forward to trying these out.

Share this post


Link to post
Share on other sites

This is why good things happen when Tools 'leave the nest' and go into the world.

 

Actually, in this version, the app expects a big multi-frame TGA image like the kind we normally make for animated textures. I could (somewhat) easily make it handle an input set of images (one per frame) though, and that sounds like it could be an improvement for some workflows, so cheers!

Share this post


Link to post
Share on other sites

There appears to be an issue when processing a series of textures one after the other. After the 3rd or 4th texture, the program shows a red "compression failed" message. It's not a problem with the texture, as after closing the program and restarting it, the texture is processed with no issue. I got the error twice whilst converting a batch of 14 textures.

Share this post


Link to post
Share on other sites

Interesting. I will look into it. I am assuming that these are all 4K textures? DXT1 or 5 (and does this change the behavior)?

 

EDIT: Reproduced the issue, I think I've got it sorted. Next release will be fixed. Turns out that it is good to free malloc'ed heap memory copied into (and out of) emscripten compiled libraries (if only someone had told the dxt-js author :)).

Share this post


Link to post
Share on other sites

There still seems to be an issue with batch processing many textures. I can get about 30 textures done before the red "compression failure" happens on almost every texture. No issue if I do them alone.

Working on a project where I'm uprezzing most of the textures from the game and I'd like to get them into TPC format to save on some space. And doing them in chunks of 30 isn't that practical when I have over a thousand.

Share this post


Link to post
Share on other sites
On 12/3/2020 at 9:30 AM, Jenko said:

There still seems to be an issue with batch processing many textures. I can get about 30 textures done before the red "compression failure" happens on almost every texture. No issue if I do them alone.

Version 4.0.0 has just been released. It uses an entirely new compression engine (as long as you select a compressor setting better than 'Super Fast') that definitely resolves this particular issue (and also produces higher visual quality outputs).

Previous attempts to fix this issue helped but were ultimately unsuccessful.

  • Thanks 1

Share this post


Link to post
Share on other sites
20 hours ago, DarthParametric said:

You should fire that lousy beta tester of yours for being so slow.*

*Not being more proactive. Fixed it for you.

Share this post


Link to post
Share on other sites

Hello, ndix UR!

I was trying for the first time this tool of yours but I am not understanding how I can import the .txi file into it. The  "+ .TXI" button in the menu is always greyed out. I just realized there is an option that will enable the "+ .TXI" button under Settings and that the software automatically imports my exisiting .TXI file when starting the conversion process. 

 

Share this post


Link to post
Share on other sites

That's only enabled when using the "Use TXI text for all TGA". You can either type, paste, or load the TXI text into the window. In the default state ("Use TXI file for each TGA"), it will automatically load any TXI that is named the same as its parent TGA and in the same directory. Typically you'd normally use the default mode, unless you are batch processing a bunch of textures that all use the same TXI semantics.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

One more question, please: above I read under "Features" Create Animated Textures but under "Known Issues" I read "Cannot create uncompressed animated textures."

Can I use this tool with .txi files like the following or not?

proceduretype cycle
numx 9
numy 9
fps 12
#blending additive
#decal 1 

Share this post


Link to post
Share on other sites

Oh right, thanks DP!

I just thought that uncompressed .tpc textures would just not give any size benefit over standard .tga so I had not considered that option. Now I can see under settings that there is "Uncompressed".

One day I will learn to read properly... 😞

Share this post


Link to post
Share on other sites

Hello again!

I have tried making a couple of conversions using the best quality setting but when I compared the .tpc with the original .tga image, I seem to notice a change in colors which end up being overall a bit brighter.

Is this just my eyes playing a trick or...?

Share this post


Link to post
Share on other sites

Well, after over one year I am trying to take another stab at this and I am still encountering issues with wrong color in some conversions.

I was attempting to reduce the size of the upscaled textures I have (amounting to well over 15 GBs) by converting .TGAs to TCPs but as you can see from the attached images, it can happen that the conversion fails with the colors.

This one is PLC_KolPuz.tga (upscaled size 16 Mbs)

ImageTGA.thumb.jpg.f16f00f6d5fb397c94a6c4fb2d5d71c1.jpg

and this one is a section of the conversion (is it possible to zoom out, by the way?):

ImageSectionTPC.thumb.jpg.1ea580a6c63f060cb9b69f75e0aa1e0e.jpg

As you can see the black part is completely absent. I checked the original image and the upscaled .TGA version is of course the correct one.

I never had anyone comment on this issues one year ago but I hope to be more lucky this time.

Cheers!

Share this post


Link to post
Share on other sites
52 minutes ago, Salk said:

As you can see the black part is completely absent.

tpcview takes account on rendering alpha-channel with the diffuse/texture, so that black area appear transparent there as it's applied with alpha-mask purposed for envmap in-game, if I call this matter correctly.

Therefore, I don't see any issue regarding tga2tpc's TPC end-result -- particularly in this substance.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks for explaining this for me, ebmar.

Very useful information. So if I understand correctly the texture would look in game the way it was rendered in the .tpc image?

But I seem to recall that in 2020 I met critical color differences that didn't just interest black areas.

I'll keep you updated if I happen to meet one such texture again in my next conversions. 

Share this post


Link to post
Share on other sites
24 minutes ago, Salk said:

...the texture would look in game the way it was rendered in the .tpc image?

Yeah, more or less.

Basically,--speaking as an end-user of the format--I'm quite certain there are no differences regarding TGA vs TPC colors, pixels' positioning/orientation in such it'd make them details changing shapes or something -- and even if there's one there can only bits of jaggedness/artefacts at parts. However, I guess that's inevitable regarding how compression works -- like almost in general.

But again, there are probably edge-cases like you experienced -- which I never had one, and that can be down to many things such as the [conversion] process itself.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.