# Spatial Jitter problem in large unity project

I have a very large environment where i am getting very weird view of objects as picture given below:

As you can see there are black lines/spot, maybe the vertex lit problem. Currently I am using Standard specular shader. Remember this problem is only occuring at the end of the project (away from origin like position -17000, 0, 144)

As a workaround i tried to change my shader to Unlit and i found this shader

 Shader "Unlit/UnlitAlphaWithFade"
{
Properties
{
_Color ("Color Tint", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white"
}

Category
{
Lighting Off
ZWrite Off
ZWrite On  // uncomment if you have problems like the sprite disappear in some rotations.
Cull back
Blend SrcAlpha OneMinusSrcAlpha
//AlphaTest Greater 0.001  // uncomment if you have problems like the sprites or 3d text have white quads instead of alpha pixels.
Tags {Queue=Transparent}

{

Pass
{
SetTexture [_MainTex]
{
ConstantColor [_Color]
Combine Texture * constant
}
}
}
}
}


This shader has almost solve the problem but i have to tweak and set colour of each object as be default it is not according to my expectation.

The object was far from the origin i.e., it was creating spatial Jitter (SJ) or wobble effects in mesh. The surprising thing was for me that why it is creating problem at position 17000 of x-axis while unity allow value less than 1,000,000 (not restricted to it actually). The problem has solve through floating origin technique, the general idea is that : You usually move more and more away from the origin (0/0/0), so you should try to keep your camera and/or player/point-of-interest always around the origin, instead of letting it travel to vast distances (ref).

With regard to your question: "The surprising thing was for me that why it is creating problem at position 17000 of x-axis while unity allow value less than 1,000,000 (not restricted to it actually)."

jitter starts to occur earlier than you might expect because the resolution gap of floating point increases (gets worse) almost immediately as you move away from the origin.

Specifically, the resolution ("gap error") for a single precision float at the origin is of the order of 10^-7, then at 2 it doubles (gets worse by 2), doubles at 4 and so on with every power of 2 distance from the origin. Explained in thesis: https://doi.org/DOI:10.13140/RG.2.2.10421.32481, section 2.1. This resolution value is the base gap error in each floating point coordinate variable (x,y,z) and rendering calculations magnify it through multiplication, addition etc. As rendering is a very demanding of accuracy, if your viewpoint is close to where the jitter manifests, you may see it at smaller distances than you expect.

It might be because of your meshes' vertex normals. They are probably wrong. Unity calculates shadows based on vertex normals, which should be perpendicular to the relative face, like this:

If you select the raw mesh in unity, from the project view, and in the inspector you select "recalculate normals" the problem might get fixed. If not, you probably need to remodel the meshes that are corrupted.

• No this my meshes are fine when they are near the origin (0,0,0). I guess its distance problem form the origin. – Muhammad Faizan Khan Apr 10 '18 at 10:15
• Mmmmmmh..... that's really weird... are you using the directional light? Or are you using light probes/reflection probes? Are you using the deferred renderer? Are you using SSAO or any other ambient occlusion technique? Right now it could be so many things.. – user115399 Apr 10 '18 at 11:02