Skip to content

Commit

Permalink
[Textures] New index and 32 bit texture support article (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
muczc1wek authored Aug 4, 2024
1 parent 3096f75 commit 674ee2b
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 3 deletions.
3 changes: 0 additions & 3 deletions docs/zengin/textures.md

This file was deleted.

57 changes: 57 additions & 0 deletions docs/zengin/textures/32bit_texture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 32 Bit texture support

By default, ZenGin supports only compressed `DXT1` and `DXT3` textures. [zSurface32 patch](https://worldofplayers.ru/threads/43009/page-3#post-1180504), created by Gratt improves texture quality by adding proper `RGBA8888`, `BGRA8888`, `ARGB8888` and `ABGR8888` format readout and DirectX 32 Bit surface support in ZenGin[^1].

To use the patch you must have [Union](../union/index.md) installed. Download the `.patch` file [here](https://worldofplayers.ru/attachments/114570/), and put it into `system\` directory.

!!! Warning
It is advised to use `BGRA8888` due to performance reasons, as other [color spaces](https://en.wikipedia.org/wiki/RGBA_color_model) require additional conversion at runtime.

## Compilation

ZenGin doesn’t natively support the compilation of such textures. This can only be achieved using external programs. The simplest method to create a texture is by utilizing [zTEXiPy](https://gitlab.com/Shoun2137/ztexipy).

1. Open your texture in zTEXiPy[^2]:
![zTEXiPy's splash dialog](../../assets/images/32bit-texture-support/STEP_1.WEBP)
2. Choose `Save TEX as...`
3. In this window:
![zTEXiPy's saving dialog](../../assets/images/32bit-texture-support/STEP_3.WEBP)
- Uncheck `Generate Mipmaps` if your texture is meant to be used as UI.
- Set the `Colorspace` to `BGRA8888 (zEnum:3)` or other supported format.
4. Press `Save` and check your texture in-game:
![In-game Example](../../assets/images/32bit-texture-support/EXAMPLE_INGAME.WEBP)

## But why?

This type of texture is compatible with any asset, whether it’s armour or a sword. However, the primary application for such high-quality textures is in user interface elements, which make extensive use of gradients and the alpha channel:

=== "BGRA8888 vs DXT3"

![Comparison between BGRA8888 vs DXT3 (Alpha)](../../assets/images/32bit-texture-support/EXAMPLE_1.WEBP){: style='background-color: white;'}

This example shows comparison between raw BGRA8888 color space and DXT3 (BC2)[^3] compression.
DXT3 shows noticeable banding throughout entire texture wherever there's alpha channel, while BGRA8888 has smooth gradient transition.

=== "BGRA8888 vs DXT1"

![Comparison between BGRA8888 vs DXT1](../../assets/images/32bit-texture-support/EXAMPLE_2.WEBP)

This example shows comparison between raw BGRA8888 color space and DXT1 (BC1)[^3] compression.
DXT1 shows lossy quantization artifacts, while BGRA8888 has none.

[Source comparison files are available here.](../../assets/examples/32bit_texture_support.7z)

The drawback of using these textures is their large size, as they contain uncompressed color data. However, this is a small price to pay for the improved quality of the final product.

!!! Note
This article was originally written by [Shoun](https://gitlab.com/Shoun2137) and published on [G2O Docs](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/client-manual/32bit-texture-support/).


[^1]:
To learn more about [ZenGin Textures reference click here](https://zk.gothickit.dev/engine/formats/texture/).

[^2]:
zTEXiPy supports TGA, DDS, PNG and WEBP by default, so make sure it's one of those formats.

[^3]:
To learn more about [DXTn Algorithm click here](https://www.buckarooshangar.com/flightgear/tut_dds.html).
70 changes: 70 additions & 0 deletions docs/zengin/textures/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Textures

Textures are pictures that get projected onto 3D models and on a 2D user interface in the game. ZenGin uses its own texture format `.TEX`, that actually is a container for the texture in one of available formats. This section will discuss how to work with textures in ZenGin.

!!! Note
Technical documentation of the `.TEX` texture format can be found in the [ZenKit documentation](https://zk.gothickit.dev/engine/formats/texture/).

## Basics

All created textures have to be located in the `_WORK\DATA\TEXTURES\` directory. The compiled `.TEX` files are saved in the `_COMPILED\` subdirectory.

Here are some tips for working with Gothic textures:

- Textures must have dimensions that are multiples of 4.
- Square textures (with some exceptions, like faces or some interface elements) are preferred for easier mipmap generation.
- It is recommended not to use textures bigger than 4096x4096.
- Avoid things like `_V0`, `_A1` etc. in the texture name endings, as suffixes like this are used for [multitextures](multitextures.md).

## Formats

When working with textures in ZenGin, it is recommended to use the default texture format if you are unsure about other options. Many of the other formats are either unsupported or buggy in gothic. For transparency, `DXT3` format should be used. For pure RGB colors, `DXT1` format is recommended.

!!! Tip
Formats like `RGBA8888`, `BGRA8888`, `ARGB8888` and `ABGR8888` are properly supported with the zSurface32 patch. Learn more about it in the [32 Bit texture support](./32bit_texture.md) article.

## Mipmaps

[Mipmaps](https://en.wikipedia.org/wiki/Mipmap) are pre-generated versions of textures at different levels of detail. They are used, to improve rendering performance and reduce aliasing artifacts. When engine converts the texture it automatically generates mipmaps. Other tools may handle it differently, so it's better to check it before conversion.

!!! Example "How it works?"
If you want to learn more about mipmaps in ZenGin there is a [great article](https://www.gothic-reloaded-mod.org/en/blog/more-than-a-texture-patch-2) by Gothic Reloaded Mod Team.

## Engine compilation

By default, `.tga` files with a proper resolution are converted to `.TEX` files by the engine, when they appear in the game or a game is started with `-convertall` parameter. Also, you can convert textures to `.TEX` manually using one of the [available tools](#tools).

The engine compilation may be affected by keywords in the texture name or directory.

**Color depth**

Textures are compiled by default with a color depth of 16 bits per pixel and needs 4 bits of memory per pixel. To force the engine to convert textures with a different color depth, you need to add an ending to the name of the texture or directory `_16BIT` or `_32BIT`. Using 16/32 bit images makes sense when there are visual problems or noise after compression, but they take up more memory.

Example: `_WORK\DATA\TEXTURES\SKY\NOMIP_16BIT\CLOUDS.TGA`.

**nomip**

By default, [Mipmaps](#mipmaps) are generated for all textures. However, if the texture path contains the directory `nomip`, then a Mipmap will not be created for such a texture. It makes sense to use if you experience visual problems or interference associated with the use of Mipmaps, and also to save memory if the texture is rarely used in the game, or the texture is too small.

Example: `_WORK\DATA\TEXTURES\EFFECTS\NOMIP\LIGHTNING.TGA`

## Tools
There are some tools created by the Gothic community, that simplify working with ZenGin textures.

### GoMan
Oldest texture tool, created by PyroX. Has a good viewer, but there are already better alternatives.

[:octicons-download-16: Download](https://www.worldofgothic.de/dl/download_97.htm)

### GoTex
Simple converter, written by [ThielHater](https://forum.worldofplayers.de/forum/members/52111-ThielHater?). Implements features like custom mipmaps and popular image formats support.

[:material-forum: Thread on WoG](https://forum.worldofplayers.de/forum/threads/1601349-Tool-GoTex)

[:fontawesome-brands-github: GitHub](https://github.com/ThielHater/GoTex)

### zTEXiPy
Latest tool, developed by [Shoun](https://gitlab.com/Shoun2137). Offers batch conversion, an intuitive viewer, and Windows context menu shortcuts.

[:fontawesome-brands-gitlab: GitLab](https://gitlab.com/Shoun2137/ztexipy)

23 changes: 23 additions & 0 deletions docs/zengin/textures/multitextures.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Multitextures

Multitextures are used, for example, to create animation. For example, rippling water is represented by a sequence of textures `WATER_A0.TGA` that can be applied to 3D geometry. Also in Gothic, multitextures are used to replace the texture of a character's body.

## Naming convention

The naming convention for multitextures is as follows:
```
NAME_[Letter0][Number0]_..[LetterN][NumberN].TGA
```

Example: `HUM_HEAD_HAIR1_C0_V0.TGA`

In this way, multitextures are interconnected. The format is used exclusively for creating multitextures. Therefore, a name like `w_s2_v1.TGA` to name only one texture is not allowed. The engine handles incorrect names, but not quickly.

## Body textures

Multitextures used for the body use two channels:

- V - for skin variation
- C - for skin tone

For example, the texture `Hum_Body_Naked_V2_C3.tga` describes the body of a person without armor, variant 2, and skin tone 3 (Dark-skinned). Setting up specific character texture variations is determined in the script.
6 changes: 6 additions & 0 deletions docs/zengin/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ video games Gothic and Gothic 2 Night of the Raven.
- [Gothic World Editor](https://worldofplayers.ru/threads/40530/) - World editor for vanilla worlds, works with G1, G2 and G2 NotR worlds
- [Spacer.NET](https://forum.worldofplayers.de/forum/threads/1557793-WORLD-EDITOR-Spacer-NET) - A modernised version of Spacer available as a Gothic Mod.

**[Texture tools](../textures/index.md#tools)**

- [GoMan](https://www.worldofgothic.de/dl/download_97.htm) - Oldest tool, for viewing and converting textures.
- [GoTex](https://forum.worldofplayers.de/forum/threads/1601349-Tool-GoTex) - Simple texture converter.
- [zTEXiPy](https://gitlab.com/Shoun2137/ztexipy) - Latest texture tool, offers batch conversion and an intuitive viewer.

**Libraries**

- [ZenKit](libraries/zenkit.md) - A library to load, save and use almost all ZenGin asset files
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 674ee2b

Please sign in to comment.