At the starting camp of our game, trees cost 4.0 to 4.4 ms of every frame, and part of that went to trees nobody could see: they stood on the far side of the planet. Two fixes, smaller pieces of trees and a test that skips whatever is behind the horizon, cut the GPU part of the frame by 3.0 to 3.5 ms in each of three test runs, but the full frame got faster by more than half a millisecond only in run 3 (2.4 ms at 120 m, 3.1 ms at 64 m).
The game is Planet Wanderer, and it is an experiment: AI coding agents write it in Godot 4, and I direct them, play the builds and check what they measure. A small rover drives around a planet built from hexagonal cells. The planet is a sphere with a radius of 380 m, small enough that the world curves away visibly.
The numbers below come from the game's own benchmark on one Windows laptop: an RTX 4060 Laptop GPU, Godot 4.7.2 with the Compatibility renderer (OpenGL 3.3), 1920x1080, VSync off, frame rate capped at 60 per second (none of the means below reached the cap). The benchmark drives the camera to a fixed spot beside the starting camp, turns one kind of object on or off, and logs the frame time and the GPU time of each variant twice, alternating: the new variant, the old one, the new one again, the old one again.
We were looking for where the camp's frame time went. Trees stood out: 4.0 to 4.4 ms per frame. Of that, 3.4 ms came from the far level of detail, the cheap version of a tree that is used when it is distant, which made it the first suspect.
The far level of detail was set to draw trees up to 900 m from the eye. The planet's radius is 380 m. From the camp, the horizon is much closer than 900 m, and everything past it is hidden by the ground. The trees were culled by the camera's view and by that distance, and the forests on the planet's back side passed both. So the game sent them to the GPU, the GPU drew them, and the depth test threw them away pixel by pixel.
The same was true of the town. A settlement of six cells stands 600 to 680 m from the camp, on the other side of the planet. It cost 0.7 to 0.8 ms per frame while being completely invisible.
Godot has its own answer to this: occlusion culling with a sphere occluder (OccluderInstance3D with a SphereOccluder3D). The benchmark tried it on 14 November, on an earlier build that still had the old 180 m tree pieces, with a sphere the size of the planet's lowest ground. At 120 m from the camp, the occluder and an early version of the horizon test described below each left 6.24 of 6.86 million triangles drawn, and the GPU times were close: 18.0 and 18.7 ms for the occluder, 17.3 and 18.8 ms for the horizon test.
The game kept its own test because of what the engine's occluder had done to the ground earlier. The planet's land pieces already skipped themselves behind the horizon with this test, after a sphere occluder 3 m under the sea left holes along the tiles' edges near the camera, and a sphere 20 m under the sea did the same. The engine takes the box's point nearest the eye by distance, and for a 64 m piece of land right beside the camera that point does not have the box's smallest depth along the view. So the trees and the town went onto the test the land already used.
Two changes fixed this:
The test is the horizon culling point from a Cesium article on horizon culling. What a sphere hides from an eye is a convex region. If all eight corners of a bounding box are hidden, the whole box is hidden. So the game computes one point per box once, and each frame checks only that point.
static func horizon_point(box: AABB, r_occ: float) -> Vector3:
var d: Vector3 = box.get_center().normalized()
var m := 0.0
for i in 8:
var p: Vector3 = box.get_endpoint(i) / r_occ
var mag2: float = maxf(p.length_squared(), 1.0)
var mag: float = sqrt(mag2)
var dir: Vector3 = p.normalized()
var cos_a: float = dir.dot(d)
var sin_a: float = dir.cross(d).length()
var cos_b: float = 1.0 / mag
var sin_b: float = sqrt(mag2 - 1.0) * cos_b
var den: float = cos_a * cos_b - sin_a * sin_b
if den <= 1e-6:
return Vector3.ZERO
m = maxf(m, 1.0 / den)
return d * m
static func hidden(p: Vector3, cv: Vector3, vh2: float) -> bool:
var vt: Vector3 = p - cv
var vt_vc: float = -vt.dot(cv)
return vt_vc > vh2 and vt_vc * vt_vc / vt.length_squared() > vh2
r_occ is the radius of a sphere 8 m under the sea, 372 m against the planet's 380 m: a line of sight lower than that runs through the ground, or through water at a grazing angle, which shows nothing. Everything is divided by r_occ, so that sphere becomes the unit sphere. horizon_point runs once per box when the world loads. hidden costs a dot product and a few multiplications, and the game tests a quarter of the list each frame, so each box is checked every fourth frame; the 8 m margin covers the frames in between.
The box for a settlement cell is its hexagon made a third wider, from 2 m under its ground to 40 m above it. It is sized this way on purpose. The settlement's buildings grow as the game goes on, so a box built from the current geometry would be too small a few stages later.
The test for it checks that the box contains the ground point, the point 40 m above it and the hexagon's corners, that the cell is not hidden when seen from above it, and that it is hidden from the opposite side of the planet. The not-hidden check is there because a horizon test that hides too much looks fine in a benchmark and shows up later as a hole in the world.
The first version hid the town's cells from the moment the player landed. Its frame time was the same as the final version's. But after a landing, the town had no footpaths and no trampled grass.
The game reads the ground under each settlement cell, to paint paths and worn grass, from the meshes that are visible. A cell hidden behind the planet had no visible mesh, so nothing was read. The fix is an ordering one: cells go on the horizon list only after the ground-reading step has run for them. The frame time did not change, and the town got its paths back.
The benchmark ran three times on 15 November within about an hour, on the same laptop and the same build. Each cell below is the mean of the two repeats inside one run.
| Run | Camera from the camp | GPU before | GPU after | Frame before | Frame after |
|---|---|---|---|---|---|
| 1 | 120 m | 17.9 ms | 14.5 ms | 23.7 ms | 25.2 ms |
| 1 | 64 m | 20.3 ms | 16.8 ms | 21.6 ms | 21.7 ms |
| 2 | 120 m | 17.9 ms | 14.6 ms | 23.2 ms | 25.8 ms |
| 2 | 64 m | 18.4 ms | 15.3 ms | 24.4 ms | 23.9 ms |
| 3 | 120 m | 20.1 ms | 17.0 ms | 20.9 ms | 18.5 ms |
| 3 | 64 m | 21.3 ms | 18.4 ms | 22.1 ms | 19.0 ms |
The two changes together saved 3.0 to 3.5 ms of GPU time in every run and at both distances. At 120 m the scene went from 6.86 to 5.76 million triangles and from about 2,620 to 2,480 draw calls.
Run 1 also measured the smaller pieces without the horizon test. At 120 m the pieces alone moved the GPU time from 17.9 to 17.7 ms and raised the draw calls from about 2,620 to 3,270; the horizon test then brought them to 14.5 ms and 2,477 draw calls, 3.25 ms of the saving. At 64 m the pieces alone gave 20.3 to 19.2 ms, and the horizon test 16.8 ms.
In runs 1 and 2 the full frame sat up to 11.2 ms above the GPU time. At 64 m the frame changed by less than half a millisecond (21.6 to 21.7 ms, 24.4 to 23.9 ms). At 120 m the mean got 1.5 ms longer in run 1 and 2.6 ms longer in run 2, all of it in one measurement: the new variant's first repeat at 120 m, which is also the first measurement of each run. It took 27.2 and 28.5 ms, against 23.2 and 23.0 ms for the new variant's second repeat. In run 3 the frame sat less than a millisecond above the GPU time before the change, and it followed the GPU down: 20.9 to 18.5 ms at 120 m, 22.1 to 19.0 ms at 64 m, which is 48 to 54 and 45 to 53 frames per second.
Run 3 is also the only one that logged the CPU's rendering time. It fell from 9.4 to 8.5 ms at 120 m and from 9.5 to 8.5 ms at 64 m, while the draw calls at 120 m went from about 2,620 to 2,480. My guess is that fewer pieces drawn cost the CPU less to submit, but nothing in the log separates that out.
Frames from before and after were compared pixel by pixel: at most 60 pixels out of about two million differed, and none by more than 12 out of 255 levels.
The same build, on the same laptop, an hour apart, gave a GPU time of 17.9 ms in one run and 20.1 ms in another, and a frame time of 23.7 ms in one and 20.9 ms in another. Inside each of the three runs of 15 November the GPU repeats agree within about 0.75 ms, so the spread comes from one run to the next (the 14 November run was looser: 17.3 and 18.8 ms for the same variant). The frame repeats agree less, and the two slow ones were each the first measurement of their run, which is why a warm-up pass is the first thing I would try.
In runs 1 and 2 the frame was waiting on something that was not the GPU, and those two runs did not log the CPU side, so I can't say what it was. My guesses are the laptop's power and clock states, which the benchmark does not record, or the driver queueing frames under the Compatibility renderer. Neither is measured.
There are no Mac numbers in this article. On the Mac the GPU time reads as 0 in the game's log, so only full frames could be compared there.
So here is the question I'd like an answer to: on a laptop GPU, how do you make a Godot 4 frame-time benchmark repeat between runs, so that a 3 ms GPU saving shows up in the frame every time and not once in three? Pinning clocks, a warm-up pass, more repeats, a different renderer: if you have tried one of these on a similar scene, I would like to hear what moved the spread.
Planet Wanderer has no release yet. Its page, with the other things my agents build and measure, is at allkeep.org/en/products.