More than a texture patch? (Part 6)

More than a texture patch? (Part 6)

ThielHater | Jul 25, 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 than I thought they would?

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. Was it due to the compression? This reduces the colour space, but I wanted to know more. As a test, I wanted to use a texture that consisted half of pure white and deep black and was placed on this decayed hut.

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

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

First of all, Gothic's world editor named Spacer is responsible for the lighting. In it you place objects, create the way network for the NPCs, add ambient sounds, craft camera travels and so on - a true marvel of technology. The light calculation is triggered via the following dialogue window:

The lighting is calculated using a ray-tracing method that simulates the incoming 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.

The light calculation is done once for each level, for one position of the light source and one angle of incidence. Accordingly, the lighting in Gothic is pretty much static. Whether the sun rises, is high in the sky or sets, whether it rains or the moon shines, this has no influence. You can see it well from the shadows of the wall remains:

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

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 next step towards improvement would therefore be to adjust the colour values calculated by Gothic for the CLUT in such a way that they are richer in contrast and less saturated. The next step after that could be to use a Union plug-in to calculate the lighting at runtime of the game. However, this has not happened yet, 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. However, Gothic 1 has only a few properties 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-transparent, 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 threshold, the edge is rendered softly. If it is above, it is rendered hard. In Gothic 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 picture. However, the softer shadows are accompanied by a loss of contrast, as can be seen in the dull-looking rock ledges. Overall, the Old Mine appears more atmospheric, but we will have to try out different values for the smoothing angle.

If you want to learn even more about the technical details, this video from GuerillaCG is worth a look.