[2.1] Line primitives visible through surface when camera is far away
-
- Gnoblar
- Posts: 19
- Joined: Tue Oct 27, 2020 5:34 pm
[2.1] Line primitives visible through surface when camera is far away
Hello,
I render a surface with some lines located mostly underneath the surface. They are close to the surface but not directly on/in it. When I am quite close to the surface with the camera everything looks fine (some parts of the lines actually go up through the surface so this is correct):
However, the farther I move away with the camera the more the lines that are located underneath the surface start to come through. There is NO depth bias applied to any materials.
Why does this happen?
I render a surface with some lines located mostly underneath the surface. They are close to the surface but not directly on/in it. When I am quite close to the surface with the camera everything looks fine (some parts of the lines actually go up through the surface so this is correct):
However, the farther I move away with the camera the more the lines that are located underneath the surface start to come through. There is NO depth bias applied to any materials.
Why does this happen?
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: [2.1] Line primitives visible through surface when camera is far away
This sounds weird, but it may just be good old Z-fighting.
Given that it's a regular line primitive (which are rare), it might be a GPU bug.
Ogre 2.2 implemented ReverseZ which will help at this problem if it's Z-fighting.
You could try tweaking depth bias dynamically based on distance to camera, but it could easily break and would need testing on multiple GPUs.
Or you could increase the near plane (push it away from camera) for a massive boost in precision. But ideally use ReverseZ.
Given that it's a regular line primitive (which are rare), it might be a GPU bug.
Ogre 2.2 implemented ReverseZ which will help at this problem if it's Z-fighting.
You could try tweaking depth bias dynamically based on distance to camera, but it could easily break and would need testing on multiple GPUs.
Or you could increase the near plane (push it away from camera) for a massive boost in precision. But ideally use ReverseZ.
-
- Gnoblar
- Posts: 19
- Joined: Tue Oct 27, 2020 5:34 pm
Re: [2.1] Line primitives visible through surface when camera is far away
Alright, thanks for your answer. Maybe I am not understanding Z-fighting correctly but how can it be Z-fighting when the primitives do not have the same Z value (there is really some space between the surface and the lines)? Or is it a precision issue?
-
- OGRE Team Member
- Posts: 5436
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1343
Re: [2.1] Line primitives visible through surface when camera is far away
Z fighting happens when the value is the same... in the z buffer.
Z precision is horrible once you get a little far away from the camera. To put into context two objects 10 meters away from each other, both around 20.000 meters away from camera will map to the same depth value and will Z fight.
Reverse Z drastically diminishes Z fighting because it distributes precision over distance much better.
With regular Z, 50% of the available precision is wasted between the near plane and 2x near plane. So if your near plane is 0.1, you get sub-nanometer precision between 0.1 and 0.2 meters and garbage precision between 0.2 and the far plane
Z precision is horrible once you get a little far away from the camera. To put into context two objects 10 meters away from each other, both around 20.000 meters away from camera will map to the same depth value and will Z fight.
Reverse Z drastically diminishes Z fighting because it distributes precision over distance much better.
With regular Z, 50% of the available precision is wasted between the near plane and 2x near plane. So if your near plane is 0.1, you get sub-nanometer precision between 0.1 and 0.2 meters and garbage precision between 0.2 and the far plane