Flicking large scale object

Hi, I have problem witch large scaled object. The problem is with flicking and deformating mesh at some distances. I had this problem before in Unity but unfortunatelly can’t remember what is the solution. Link to video: - YouTube

I have had this same problem before, and actually put a project on hold because I couldn’t figure out how to fix it. I would love to discover the solution to this as well.

Does flicker stay if you disable your material?

It’s either an issue with z-fighting or an issue with dynamic shadows. If it’s z-fighting then it’s due to the surfaces being close together, when you move away they get rendered at the same depth even if they aren’t actually at the same depth.

That does not look like z-buffer fighting to me.

Z-buffer is usually caused by two objects sharing the same space or height information aligning with one another which is more of a render order along the same aliment.

Z-buffer is very pronounced and can not be confused with anything else but you can try this if the object is not sharing the same space.

What that looks like to me is a improper mapping type that even shows up as a explicit mapping problem between the use of environmental materials or as a texture in 3ds Max.

Sorry don’t know how to fix it off hand but the starting point would be the details panel to see what the material needs to work with or an improper mapping type

Z-fighting can happen once you zoom out, there’s a limited amount of depth information which becomes less precise as the scale of the scene becomes larger.

It’s funny because if I select the object the problem disappear, and when I select other object it returns. Of course if I release it the problem is there.

This problem is due to low z-precision at huge distances. Its not exactly the same as z-fighting since it can happen even with fairly large distances between the surfaces in question.

You can work around this using vertex shaders to ‘pull’ the top mesh closer to the camera without making it look any larger. There may be side effects if the mesh casts dynamic shadows or if the fog density is extremely high there. In general you should only pull it in enough to fix the Z precision.

The basic setup here is simple.

Take “CameraPosition” and subtract “WorldPosition” then normalize that. Then multiply it by a scalar parameter for the amount of pull you want (negative numbers should push the object further instead but also try that incase my math is backwards).

If you have to push it really far and the camera needs to get close to it, you may need to clamp the “length” parameter by the distance from the camera to worldposition times some scalar factor (ie, 0.75 is a good buffer). Otherwise it will actually push the mesh past the camera if you do not check for that and you get closer than your offset.

Thank You all for the answers.

I’m interested in doing what suggested, but I don’t know how to do it.

Can someone provide an example?

If you do not intend to get particularly close to anything you can also consider a simpler solution: raising the near clip value. This will allow for more precision in the distance. You can find the Near clip value in Project Settings > General Settings.

If you can’t raise this any further and still have z-fighting you should indeed do what Ryan explained.

Yeah I’m just not following exactly how I’m supposed to do it.

Is talking about a transform in the shader? Or is he messing with pixel depth offset (which seems to change nothing for me, even when you visualize the depth buffer nothing changes, ive tried 0, 1, 100000, depth buffer doesnt change)
or do i have to toggle custom scene depth on the mesh?

I started looking at the unreal engine code and I was going to see if I could hack in a logarithmic Z buffer. Apparently this is the holy grail of zbuffer. I narrowed it down to DepthRendering.cpp (I think…) but that’s where I stopped. It would probably take me a few days to figure out the exact spot to overide the Z buffer with a logarithmic one. I’m surprised Unreal doesn’t have it as an option in the editor, feels like it would be trivial to add, and add a VERY useful feature.

If I do ever figure it out maybe I can submit a pull request and they can add it as a optional z buffer in the editor. Z-fighting is a bummer when you have a huge scene or far away objects. It even seems to affect decals, shadows, textures and shaders as well when your z precision starts to fail.

Just a very basic vertex shader, nothing fancy.

the min clamp is to prevent it from pushing past the near clip plane if you ever get close, but 0.9 is just a randomly chosen value that should work ok. Ideally you would do some math to apply the offset if the verts are beyond a certain distance which would be easy but I didn’t feel like cluttering up this image any more.

fwiw, you cant use pixel depth offset to pull things closer to the camera. It can only push things farther away.

can technically I should have named the parameter “pull” rather than push but oh well.