The shimmering of TODs and target objects and the flickering of shadows in the thirdwire game engine always anoyed me. And since I'm playing FE2 recently, there this problems are more intense,I decided to have a closer look at this issue and possible solutions. This is what I came up with:
As many of you already know, the shimmering of the objects and flickering of shadows is caused by the limited precision of the z-buffer.
The precision of the z-buffer depends (besides the buffers bit depth) on two values: the near clipping plane distance (znear) and the far clipping plane distance (zfar). To increase the z-buffer precision you have to shorten the interval[znear,zfar], either by decreasing zfar or by increasing znear. Whereby increasing znear is FAR more effective for increasing z-buffer precision.
I'm not quite sure what *.ini setting defines zfar. But I think that decreasing the horizon distance in the game options menu decreases zfar. But I found to see any (minor) effect (regarding reducing shimmering/flickering) I had to change the horizon setting to Near. But I like the horizon setting at Very Far and I will let it at Very Far.
znear is defined in the flightengine.ini by
SF2 with object fading disabled (fading enabled I haven't investigated yet):
But there is an exception: If in the <aircraft>_cockpit.ini OpenCockpit= is set to TRUE, then znear is defined by (the usually smaller value) ExternalClipDistMin=. Thats the reason why in some aircraft the shimmering happens, while in the external view it does not. The external view uses the flightengine.ini setting.
The znear value has to be increased as much as possible. Unfortunately this value can not be increased arbitrary without side effects: e.g. clipping issues. You have to experiment until you find a maximum znear value without side effects.
If you are lucky then the znear increase was sufficient to stop the shimmering/flickering.
If not, then you have to tweak further.
Tweaks against flickering shadows:
Against the flickering shadows I don't know any tweaks. The only solution is to switch them off: Shadow option = High switches TOD shadows off, = Medium also switches target object shadows off.
The following tweaks are meant to reduce the shimmering caused by z-fighting between the terrain and the TODs / target objects. What the tweaks do is to increase the z value distances between the terrain and the TODs / target objects.
Tweak against shimmering TODs:
In the <terrain>_data.ini set
ZBufferOffset=2.0 or higher (in FE2 I set it to 5.0 to stop the shimmering)
That modifies the z value by an offset so that the TODs are put a bit "forward" in the z-buffer.
But this doesn't affect target objects shimmering.
Tweak against shimmering target objects (and TODs).
The solution I found is to modify the terrain shaders:
TERTERRAINEFFECT.FX (near terrain)
TERFARTERRAINEFFECT.FX (far terrain)
TERWATEREFFECT0.FX (terrain with water, Water Detail = Low)
TERWATEREFFECT1.FX (terrain with water, Water Detail = Medium)
TERWATEREFFECT2.FX (terrain with water, Water Detail = High)
In each shader I added the following lines in the vertex shader code
const float zOffset = 3.0e-7;
output.pos.z += zOffset * output.pos.w;
That adds an offset to the z value so that the terrain is put a bit "back" in the z-buffer.
This tweak ALSO affects TOD shimmering.
But it has a side effect: The TOD / target object shadows are a bit shifted if viewed from greater distances. It's a tradeoff: choosing a greater zOffset value lessens the shimmering but shifts the shadows more and vice versa. You can try to decrease/increase zOffset in small steps (e.g. 1.0e-7) to see which offset fits best.
The terrain shaders for FE2:
fe2_zbufferoffset_shaders.zip 13.82KB 176 downloads
Put the shader files (*.fx) into the Terrains\<terrain> directory.
@admins/moderators: I also have modified SF2 shaders. But I don't know if the combatace policy allows to upload modified LOCKED shaders.
The terrain shaders for SF2:
sf2_zbufferoffset_shaders.zip 16.04KB 261 downloads
Edited by mue, 29 April 2015 - 02:09:14 PM.