More than a texture patch? (Part 6)

More than a texture patch? (Part 6)

Jul 26, 2022

The sixth part will be about lighting in Gothic - about light, shadow and colour. The starting point was a question I asked myself at the time: Why do our textures look different in-game from what we thought?

It was not a big difference, rather subtle. The textures looked muddy, as if a colour filter had been put over them, especially the bright pixels were affected. I was wondering if it was due to the compression. This reduces the colour space, but I wanted to know more. As a test, I used a texture that consisted half of pure white and deep black and was placed on top of this decayed hut.

The shading was to be expected, but the two light areas at the top of the scene gave me second thoughts, as they were warmer than pure white. I compared the colour values of the texture before and after compression with its appearance in-game:

The compression had an effect but it was negligible. It was obvious that Gothic rendered the textures differently than expected. But for what reason, how does it work and can we take advantage of it for our project?

The Spacer, Gothic's editor, is responsible for the lighting. In it, you place objects, create the way net for the NPCs, add ambient sounds, design camera travel and so on - a true marvel of technology. The calculation is triggered via the following dialogue window:

The lighting is calculated using a raytracing method that simulates the incidence of light from the sun and determines for each vertex of the level mesh how strongly it is illuminated. This technique is therefore also called vertex lighting. The intensity of the light is normalised to an interval from 0 to 255. Gothic can also calculate light maps in different quality levels. This is a data structure that combines the lighting information for several faces.

For each level, the light calculation is carried out for one position of the light source and one angle of incidence - correspondingly, the lighting in Gothic is static. Whether the sun rises, is high or sets, whether it rains or the moon shines, that has no influence. You can see it well in the shadows of the wall remains:

So if the lighting basically doesn't change, why are there clearly recognisable times of day? The answer is that Gothic multiplies a colour value onto the texture when drawing the faces, which is taken from the Poly Light Colour Lookup Table or CLUT for short. This is a table that is recalculated with every frame and contains different gradations of the current colour of the global light source. Thus, the world is coloured yellowish at noon, reddish in the evening and bluish at night. The value for the lookup is the brightness of the respective vertex, which was previously calculated by the Spacer.

For test purposes, I overwrote the CLUT with pure white:

This made the bright pebbles in the rubble pile stand out better, but on the other hand it cancelled out the shading. The first step towards improvement would therefore be to adjust the colour values calculated by Gothic in the CLUT so that they are richer in contrast and less saturated. The next step after that could be using a Union plug-in to calculate the lighting at runtime of the game. However, this has not happened so far, instead I have filled the CLUT with random values. 🤣

Through the Gothic I 3D+ Mesh-Patch by davied, I later became aware that the lighting in Gothic can also be influenced in other ways. As you can see from the screenshots, the shadows of the objects are rendered softer. But how did he manage that?

What has not yet been mentioned in any article are the so-called materials. The texture contains only the image data, the properties are stored in the associated material. Gothic 1, however, has only a few compared to modern engines and most of them are not important. The material group (matGroup), for example, controls which sound is played when the player walks over a surface with this material. A special case is the material group WATER. If you use it, the surface is rendered semi-transparently, the collision check is deactivated and the player can swim in it. Among other properties for animated textures, one of interest remains: The smoothing angle (smoothAngle).

This is the threshold value for the angle between two faces, which influences the rendering of the shadows. If the respective angle is below, the edge is rendered softly. If it is higher, it is rendered hard. In Gothic, by the way, it is 60° by default. The following spheres are geometrically completely identical, only the shadows are rendered differently:

As you can see, the difference is significant. Since it also costs no performance, we will also make use of it in the Gothic Reloaded Mod. The following comparison from the Old Mine demonstrates the effect in Gothic quite well, especially in the right half of the image. However, the softer shadows are accompanied by a loss of contrast, as you can see from the dull appearing rock ledges. Overall, the Old Mine appears more atmospheric, but we will have to try out different values for the smoothing angle.