Jump to content


Photo

shimmering TODs and target objects

shimmering flickering tod target object zbuffer

  • Please log in to reply
12 replies to this topic

#1 mue

mue
  • +MODDER
  • 144 Posts

Posted 29 April 2015 - 04:23:23 AM

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.

Changing zfar:

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.

Changing znear:

znear is defined in the flightengine.ini by

FE2:
[NearSceneClip]
NearClipDistance=

SF2 with object fading disabled (fading enabled I haven't investigated yet):
[ForegroundSceneClip]
NearClipDistance=

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

[SolidObjectTextureMaterial]
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:
Attached File  fe2_zbufferoffset_shaders.zip   13.82KB   137 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.

 

Update:

The terrain shaders for SF2:

Attached File  sf2_zbufferoffset_shaders.zip   16.04KB   221 downloads


Edited by mue, 29 April 2015 - 02:09:14 PM.

  • jeanba, MigBuster and Stary like this

#2 Stary

Stary

    "magnificent B@stard"

  • +MODDER
  • Political Arena
  • 8,194 Posts

Posted 29 April 2015 - 04:40:06 AM

now that is most interesting find Mue! :clapping:

 

the shimmering city TODs of mine were driving me crazy for ages now! So big thanks for every and any of your findings!


  • quack74 likes this

Drama Queen on occasion


#3 7eleven

7eleven

    Known As Not Paulo!

  • +MODDER
  • Deutsche Luftwaffe
  • 6,107 Posts

Posted 29 April 2015 - 05:01:25 AM

:good:

Thank you Mue!



#4 Geezer

Geezer
  • +MODDER
  • 1,063 Posts

Posted 29 April 2015 - 06:02:13 AM

Thank you!  That fixed the problem on my rig - the shimmering towns went away.


  • baffmeister and Stary like this

#5 Wrench

Wrench

    Known As Bob.

  • ADMINISTRATOR
  • Political Arena
  • 21,462 Posts

Posted 29 April 2015 - 12:56:59 PM

as far as I'm concerned, you certainly MAY upload them!!


Terraformer Extraordinaire
Making the Game Look Like the Real World ™ Since 2007
"We are the Princes of the Ini-verse"
"A little bit of something, is better than a whole lot of nothing"

 

Dat banned achievment


#6 mue

mue
  • +MODDER
  • 144 Posts

Posted 29 April 2015 - 02:10:41 PM

I added the modified terrain shaders for SF2 to the first post.



#7 jeanba

jeanba
  • ELITE MEMBER
  • 1,413 Posts

Posted 30 April 2015 - 01:26:58 AM

I can't wait before testing !



#8 jeanba

jeanba
  • ELITE MEMBER
  • 1,413 Posts

Posted 03 May 2015 - 02:08:54 PM

I tried on sf2v expansion terrain : a good value seems 5e-7, 3e-7 is too low


Edited by jeanba, 03 May 2015 - 02:41:40 PM.


#9 jeanba

jeanba
  • ELITE MEMBER
  • 1,413 Posts

Posted 03 May 2015 - 03:21:30 PM

I also tried with the Isreal Map from 1948 War for Independence/1956 Suez Crisis 2.1 :

It does not work, if I put ZBufferOffset=2.0, the runways are disappearing, 0 is ok, obviously



#10 mue

mue
  • +MODDER
  • 144 Posts

Posted 03 May 2015 - 04:05:39 PM

I also tried with the Isreal Map from 1948 War for Independence/1956 Suez Crisis 2.1 :

It does not work, if I put ZBufferOffset=2.0, the runways are disappearing, 0 is ok, obviously

 

Have you really set ZBufferOffset of [SolidObjectTextureMaterial]?

Disappearing runways seems to indicate that you changed [NormalTextureMaterial] or [BackgroundMaterial].



#11 jeanba

jeanba
  • ELITE MEMBER
  • 1,413 Posts

Posted 04 May 2015 - 01:12:11 AM

Thank you for the tip, I will check



#12 Wilches

Wilches
  • SENIOR MEMBER
  • 953 Posts

Posted 04 May 2015 - 09:40:07 AM

mue, you wrote:

"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."

 

Where´s "ExternalClipDistMin="? What´s the best parameter?
 



#13 mue

mue
  • +MODDER
  • 144 Posts

Posted 04 May 2015 - 11:03:43 AM

mue, you wrote:

"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."

 

Where´s "ExternalClipDistMin="? What´s the best parameter?
 

 

It's in the <aircraft>_cockpit.ini. Try to increase it as much as possible as long as you don't get any clipping issues. E.g. in FE2 for an aircraft I could increase that value only from 0.05 to 0.08 without clipping issues.


  • Wilches likes this




0 user(s) are reading this topic

0 members, 0 guests