Skip to content

Commit 4b45552

Browse files
committed
Document physics interpolation and shader compilation in Fixing jitter and stutter
1 parent 5e20706 commit 4b45552

File tree

1 file changed

+72
-31
lines changed

1 file changed

+72
-31
lines changed

tutorials/rendering/jitter_stutter.rst

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,53 +37,92 @@ Finally, a game exhibiting *stutter* will appear smooth, but appear to *stop* or
3737
Jitter
3838
------
3939

40-
There can be many causes of jitter, the most typical one happens when the game
40+
There can be many causes of jitter. The most typical one happens when the game
4141
*physics frequency* (usually 60 Hz) runs at a different resolution than the
4242
monitor refresh rate. Check whether your monitor refresh rate is different from
4343
60 Hz.
4444

45-
This is generally not a problem, given that most monitors are 60 Hz, and
46-
starting with Godot 3.1, a frame timer was introduced that tries to synchronize
47-
with refresh as well as possible.
48-
49-
Sometimes only some objects appear to jitter (character or background). This
45+
Sometimes, only some objects appear to jitter (character or background). This
5046
happens when they are processed in different time sources (one is processed in
51-
the physics step while another is processed in the idle step). Godot 3.1 does
52-
some improvements to this, from allowing kinematic bodies to be animated in the
53-
regular ``_process()`` loop, to further fixes in the frame timer.
47+
the physics step while another is processed in the idle step).
48+
49+
This cause of jitter can be alleviated by enabling
50+
:ref:`physics interpolation <doc_physics_interpolation_quick_start_guide>`
51+
in the Project Settings. Physics interpolation will smooth out physics updates by
52+
interpolating the transforms of physics objects between physics frames.
53+
This way, the visual representation of physics objects will always look
54+
smooth no matter the framerate and physics tick rate.
55+
56+
Enabling physics interpolation has some caveats you should be aware of.
57+
For example, care should be taken when teleporting objects so that they
58+
don't visibly interpolate between the old position and new position
59+
when it's not intended. See the
60+
:ref:`doc_physics_interpolation` documentation for details.
61+
62+
.. note::
63+
64+
Enabling physics interpolation will increase input lag for behavior
65+
that depends on the physics tick, such as player movement.
66+
In most games, this is generally preferable to jitter, but consider this carefully
67+
for games that operate on a fixed framerate (like fighting or rhythm games).
68+
This increase in input lag can be compensated by increasing the physics
69+
tick rate as described in the :ref:`doc_jitter_stutter_input_lag` section.
5470

5571
Stutter
5672
-------
5773

58-
Stutter may happen due to two different reasons. The first, and most obvious
59-
one, is the game not being able to keep full framerate performance. Solving this
60-
is game specific and will require optimization.
61-
62-
The second is more complicated, because it is often not associated to the engine
63-
or game but the underlying operating system. Here is some information regarding
64-
stutter on different OSs.
65-
66-
On platforms that support disabling V-Sync, stuttering can be made less
67-
noticeable by disabling V-Sync in the project settings. This will however cause
68-
tearing to appear, especially on monitors with low refresh rates. If your
69-
monitor supports it, consider enabling variable refresh rate (G-Sync/FreeSync)
70-
while leaving V-Sync enabled. This avoids mitigating some forms of stuttering
71-
without introducing tearing.
72-
73-
Forcing your graphics card to use the maximum performance profile can also help
74-
reduce stuttering, at the cost of increased GPU power draw.
74+
Stutter may happen due to several different reasons. One reason is the game
75+
not being able to keep full framerate performance due to a CPU or GPU bottleneck.
76+
Solving this is game-specific and will require
77+
:ref:`optimization <doc_general_optimization>`.
78+
79+
Another common reason for stuttering is *shader compilation stutter*. This occurs
80+
when a shader needs to be compiled when a new material or particle effect is spawned
81+
for the first time in a game. This kind of stuttering generally only happens on the first
82+
playthrough, or after a graphics driver update when the shader cache is invalidated.
83+
84+
Since Godot 4.4, when using the Forward+ or Mobile renderers, the engine tries to
85+
avoid shader compilation stutter using an ubershader approach.
86+
For this approach to be most effective, care must be taken
87+
when designing scenes and resources so that Godot can gather as much information as
88+
possible when the scene/resource is loaded, as opposed as to when it's being drawn
89+
for the first time. See :ref:`doc_pipeline_compilations` for more information.
90+
91+
However, when using the Compatibility renderer, it is not possible to use this
92+
ubershader approach due to technical limitations in OpenGL. Therefore, to avoid
93+
shader compilation stutter in the Compatibility renderer, you need to spawn every
94+
mesh and visual effect in front of the camera for a single frame when the level is loading.
95+
This will ensure the shader is compiled when the level is loaded, as opposed to
96+
occurring during gameplay. This can be done behind solid 2D UI (such as a fullscreen
97+
:ref:`class_ColorRect` node) so that it's not visible to the player.
98+
99+
.. note::
100+
101+
On platforms that support disabling V-Sync, stuttering can be made less
102+
noticeable by disabling V-Sync in the project settings. This will however cause
103+
tearing to appear, especially on monitors with low refresh rates. If your
104+
monitor supports it, consider enabling variable refresh rate (G-Sync/FreeSync)
105+
while leaving V-Sync enabled. This allows mitigating some forms of stuttering
106+
without introducing tearing. However, it will not help with large stutters,
107+
such as the ones caused by shader compilation stutter.
108+
109+
Forcing your graphics card to use the maximum performance profile can also help
110+
reduce stuttering, at the cost of increased GPU power draw.
111+
112+
Additionally, stutter may be induced by the underlying operating system.
113+
Here is some information regarding stutter on different OSes:
75114

76115
Windows
77116
~~~~~~~
78117

79118
Windows is known to cause stutter in windowed games. This mostly depends on the
80119
hardware installed, drivers version and processes running in parallel (e.g.
81120
having many browser tabs open may cause stutter in a running game). To avoid
82-
this, starting with 3.1, Godot raises the game priority to "Above Normal". This
83-
helps considerably but may not completely eliminate stutter.
121+
this, Godot raises the game priority to "Above Normal". This helps considerably,
122+
but may not completely eliminate stutter.
84123

85124
Eliminating this completely requires giving your game full privileges to become
86-
"time critical", which is not advised. Some games may do it, but it is advised
125+
"Time Critical", which is not advised. Some games may do it, but it is advised
87126
to learn to live with this problem, as it is common for Windows games and most
88127
users won't play games windowed (games that are played in a window, e.g. puzzle
89128
games, will usually not exhibit this problem anyway).
@@ -147,6 +186,8 @@ iOS
147186
iOS devices are generally stutter-free, but older devices running newer versions
148187
of the operating system may exhibit problems. This is generally unavoidable.
149188

189+
.. _doc_jitter_stutter_input_lag:
190+
150191
Input lag
151192
---------
152193

@@ -238,8 +279,8 @@ however result in high CPU usage, so 500 Hz may be a safer bet on low-end CPUs.
238279
If your mouse offers multiple :abbr:`DPI (Dots Per Inch)` settings, consider also
239280
`using the highest possible setting and reducing in-game sensitivity to reduce mouse latency <https://www.youtube.com/watch?v=6AoRfv9W110>`__.
240281

241-
On Linux, disabling compositing in window managers that allow it (such as KWin
242-
or Xfwm) can reduce input lag significantly.
282+
On Linux when using X11, disabling compositing in window managers that allow it
283+
(such as KWin or Xfwm) can reduce input lag significantly.
243284

244285
Reporting jitter, stutter or input lag problems
245286
-----------------------------------------------

0 commit comments

Comments
 (0)