1

I've created an app that takes DTED positional data and creates a basic contour mesh. With depth testing enabled this works fine and I don't have issues simply rendering the terrain.

The problem I've run into is that when I place objects on the terrain surface I get a lot of z-fighting causing visual corruption in the boxes/spheres. Does there exist any way to mitigate this besides modifying nearclip/farclip?

I've tried using a nearclip of .1 and a farclip of 5000 and I still suffer a lot of flicker. Keep in mind my terrain may be 100k units wide so I want to keep my farclip high enough to view the entire terrain at once. I've gone through every question related to the depth buffer in FX and have not yet found anything to help mitigate it besides near/farclip settings.

Sparkfizt
  • 113
  • 1
  • 8
  • I'm sure you are already doing this, but, just to check, are you creating your scenes with [depthBuffer set to true](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/Scene.html#Scene-javafx.scene.Parent-double-double-boolean-javafx.scene.SceneAntialiasing-)? – jewelsea Apr 05 '16 at 19:32
  • Yeah without depth testing render order is determined by the node order in the scene graph so objects will overlap strangely. The behavior I see is when depth testing is turned on. – Sparkfizt Apr 06 '16 at 15:38

2 Answers2

2

I had the same problem with JavaFX. Your solution worked for me, but I was curious why that was, especially because I found someone with the same problem, but in Autodesk Maya.

The reason behind this, of course, is depth buffer precision. As the zFar plane moves away, or the zNear plane comes closer, too much precision is lost. This affects the zNear plane much more than the zFar plane.

A good explanation is on khronos' OpenGL wiki: Depth Buffer Precision

TL;DR: Always move the zNear plane as far away as possible and the zFar plane as near as possible.

Sadret
  • 301
  • 2
  • 10
1

After a lot of tinkering I found that adjusting my farclip never helped reduce flicker. However if I set my nearclip to 1 I can have a farclip of 500k with virtually no flicker.

Sparkfizt
  • 113
  • 1
  • 8
  • THANK YOU!! I've spent hours searching for a solution and it honestly had not occurred to me to set nearclip HIGHER. I had to set mine to 100 or so, but given the scale of the 3D model this didn't matter at all, however now all flicker is gone. Thanks! – RDM Jun 20 '17 at 13:41
  • I know your pain ;) – Sparkfizt Jun 20 '17 at 17:30
  • Thanks man - that actually worked!! Was getting crazy bout this ... It also took care of annoying flickering between intersecting objects with bump mapping enabled. – schwaller Nov 23 '22 at 23:48