1
00:00:00,540 --> 00:00:03,809
This is a 3D scan of a museum statue.

2
00:00:03,809 --> 00:00:06,450
A web browser is drawing it in real time.

3
00:00:06,450 --> 00:00:11,550
The scan is a mesh of 1.35 million triangles.

4
00:00:11,550 --> 00:00:15,710
From here, the statue covers about 60,000 pixels of the

5
00:00:15,710 --> 00:00:16,590
picture.

6
00:00:16,590 --> 00:00:20,140
That is more than twenty triangles for every pixel.

7
00:00:21,879 --> 00:00:26,198
It stands in a canyon with 334 other objects.

8
00:00:26,198 --> 00:00:29,960
Each of these knights is a scan of two million triangles.

9
00:00:29,960 --> 00:00:33,638
From here, this one covers about four thousand pixels:

10
00:00:33,638 --> 00:00:36,647
five hundred triangles for every pixel.

11
00:00:36,647 --> 00:00:40,970
Counting every copy, the canyon holds 107 million

12
00:00:40,970 --> 00:00:42,192
triangles.

13
00:00:42,192 --> 00:00:45,450
A full HD screen has two million pixels,

14
00:00:45,450 --> 00:00:48,649
so that is 52 triangles for each one.

15
00:00:48,649 --> 00:00:53,480
Stored as plain triangles, the canyon is 3.6 gigabytes.

16
00:00:55,338 --> 00:00:59,420
A web page that shows 3D usually downloads each model

17
00:00:59,420 --> 00:01:03,340
whole, and the GPU draws all of its triangles in every

18
00:01:03,340 --> 00:01:04,535
frame.

19
00:01:04,535 --> 00:01:07,820
From a distance, dozens of those triangles land in the

20
00:01:07,820 --> 00:01:11,390
same pixel, and most of them are wasted work.

21
00:01:11,390 --> 00:01:14,990
The common fix is to ship a few simplified copies of each

22
00:01:14,990 --> 00:01:18,670
model, and to swap the whole model for a coarser copy as

23
00:01:18,670 --> 00:01:20,270
the camera moves away.

24
00:01:20,270 --> 00:01:22,472
That fails for anything large.

25
00:01:22,472 --> 00:01:25,630
A cliff you are standing beside needs full detail at your

26
00:01:25,630 --> 00:01:28,510
feet and almost none at its far end,

27
00:01:28,510 --> 00:01:32,540
and a whole-model copy has one level of detail everywhere.

28
00:01:32,878 --> 00:01:35,280
What you want is finer-grained:

29
00:01:35,280 --> 00:01:38,720
every small patch of every surface drawn with triangles

30
00:01:38,720 --> 00:01:41,760
about the size of a pixel, and only those patches

31
00:01:41,760 --> 00:01:42,879
downloaded.

32
00:01:42,879 --> 00:01:46,240
Fine patches for what is near, coarse ones for what is

33
00:01:46,240 --> 00:01:49,710
far, and nothing for what the camera can't see.

34
00:01:50,045 --> 00:01:53,229
The name for this is virtualized geometry.

35
00:01:53,229 --> 00:01:56,852
As with virtual memory, the full data stays on disk and

36
00:01:56,852 --> 00:01:59,200
only the parts in use are loaded.

37
00:02:00,925 --> 00:02:05,580
This is webgpu-virtual-mesh, an engine that does that in

38
00:02:05,580 --> 00:02:08,141
real time, in a browser tab.

39
00:02:08,141 --> 00:02:11,340
The canyon is streaming from a folder of static files as

40
00:02:11,340 --> 00:02:13,068
the camera flies.

41
00:02:13,068 --> 00:02:16,030
This counter is the number of triangles drawn in the

42
00:02:16,030 --> 00:02:17,390
current frame.

43
00:02:17,390 --> 00:02:21,710
It stays under twelve million, out of 107 million.

44
00:02:21,710 --> 00:02:24,990
This one is the geometry held in GPU memory.

45
00:02:24,990 --> 00:02:27,980
Its limit is 56 megabytes.

46
00:02:28,371 --> 00:02:30,614
The demo has X-ray views.

47
00:02:30,614 --> 00:02:34,240
In this one, each patch of colour is one cluster of up to

48
00:02:34,240 --> 00:02:36,880
128 triangles.

49
00:02:36,880 --> 00:02:39,035
Clusters are what the engine chooses,

50
00:02:39,035 --> 00:02:41,150
downloads and draws.

51
00:02:49,729 --> 00:02:52,769
The canyon is one of five worlds in the demo.

52
00:02:52,769 --> 00:02:56,800
This is a fjord of 35 million triangles.

53
00:02:59,340 --> 00:03:02,810
A flooded jungle temple of 44 million.

54
00:03:05,550 --> 00:03:09,020
An archipelago of 25 and a half million.

55
00:03:11,760 --> 00:03:14,750
A forest of 41 million.

56
00:03:17,490 --> 00:03:20,369
All five are assembled from real scans:

57
00:03:20,369 --> 00:03:24,610
rocks, cliffs and trees reconstructed from photographs,

58
00:03:24,610 --> 00:03:28,770
and statues scanned in museums, all free to reuse.

59
00:03:28,770 --> 00:03:32,769
Together they hold 253 million triangles,

60
00:03:32,769 --> 00:03:34,480
counting every copy.

61
00:03:36,140 --> 00:03:39,731
Three costs decide whether you can put this on a page.

62
00:03:39,731 --> 00:03:42,220
The first is time per frame.

63
00:03:42,220 --> 00:03:45,580
The project's benchmark, on an integrated GPU,

64
00:03:45,580 --> 00:03:50,620
measures 1.27 milliseconds of GPU work per frame at

65
00:03:50,620 --> 00:03:52,940
1440 by 840.

66
00:03:52,940 --> 00:03:56,459
A 60-hertz display allows 16.7.

67
00:03:56,459 --> 00:03:59,260
When we ran the demo in real time at four K,

68
00:03:59,260 --> 00:04:02,860
seven times as many pixels, a frame took between five and

69
00:04:02,860 --> 00:04:04,490
nine milliseconds.

70
00:04:04,830 --> 00:04:06,660
The second is memory.

71
00:04:06,660 --> 00:04:10,509
Geometry sits in one GPU buffer with a fixed limit,

72
00:04:10,509 --> 00:04:12,827
56 megabytes in the demo.

73
00:04:12,827 --> 00:04:16,510
When it fills, the geometry that has gone unused longest

74
00:04:16,510 --> 00:04:17,580
is dropped.

75
00:04:17,920 --> 00:04:20,080
The third is download.

76
00:04:20,080 --> 00:04:22,549
Opening the canyon fetches two files,

77
00:04:22,549 --> 00:04:24,800
6.2 megabytes together.

78
00:04:24,800 --> 00:04:28,400
The first view was complete after 8.6 more megabytes of

79
00:04:28,400 --> 00:04:29,520
geometry.

80
00:04:29,520 --> 00:04:32,400
After six viewpoints from one end of the canyon to the

81
00:04:32,400 --> 00:04:37,680
other, the tab had fetched 11.4 megabytes of the 27.6 on

82
00:04:37,680 --> 00:04:38,930
the server.

83
00:04:38,930 --> 00:04:42,050
And the server runs no code for any of this.

84
00:04:42,050 --> 00:04:45,970
It only has to serve a folder of files and support HTTP

85
00:04:45,970 --> 00:04:49,680
Range requests, which ask for one part of a file.

86
00:04:54,540 --> 00:04:57,826
The unit of everything the engine does is the cluster:

87
00:04:57,826 --> 00:05:01,900
a patch of up to 128 connected triangles.

88
00:05:01,900 --> 00:05:06,697
At full detail the statue is 11,620 of them.

89
00:05:06,697 --> 00:05:09,820
A cluster is small enough that detail can vary across a

90
00:05:09,820 --> 00:05:13,660
single object, and big enough that the GPU can accept or

91
00:05:13,660 --> 00:05:17,770
reject 128 triangles with one test.

92
00:05:19,429 --> 00:05:23,430
To draw the statue from far away, the engine needs coarser

93
00:05:23,430 --> 00:05:25,364
versions of those clusters:

94
00:05:25,364 --> 00:05:28,224
fewer triangles over the same surface.

95
00:05:28,224 --> 00:05:31,325
Simplifying a mesh is a standard operation.

96
00:05:31,325 --> 00:05:34,308
It merges two neighbouring vertices into one,

97
00:05:34,308 --> 00:05:37,830
again and again, each time choosing the pair that moves

98
00:05:37,830 --> 00:05:39,300
the surface least.

99
00:05:39,637 --> 00:05:42,818
The trouble is the border between two clusters.

100
00:05:42,818 --> 00:05:45,480
If each cluster is simplified on its own,

101
00:05:45,480 --> 00:05:48,200
the two sides of the shared border end up with different

102
00:05:48,200 --> 00:05:51,350
vertices, and a gap opens between them.

103
00:05:51,760 --> 00:05:55,209
The simple fix is to leave border vertices alone.

104
00:05:55,209 --> 00:05:58,890
The surface stays closed, but then every border keeps all

105
00:05:58,890 --> 00:06:01,370
of its original vertices at every level,

106
00:06:01,370 --> 00:06:03,880
and the coarse levels are mostly border.

107
00:06:05,339 --> 00:06:08,540
The compiler in this project works on clusters eight at a

108
00:06:08,540 --> 00:06:10,620
time: a group of neighbours.

109
00:06:10,620 --> 00:06:13,500
It locks only the vertices on the outside border of the

110
00:06:13,500 --> 00:06:14,300
group.

111
00:06:14,300 --> 00:06:17,986
Inside, the eight clusters are joined into one mesh,

112
00:06:17,986 --> 00:06:21,665
and that mesh is simplified to half as many triangles.

113
00:06:21,665 --> 00:06:25,580
The result is cut into new clusters of up to 128

114
00:06:25,580 --> 00:06:26,779
triangles.

115
00:06:26,779 --> 00:06:28,890
Those belong to the next level.

116
00:06:29,228 --> 00:06:32,111
At the next level the clusters are grouped again,

117
00:06:32,111 --> 00:06:34,668
and the groups fall in different places.

118
00:06:34,668 --> 00:06:37,630
A border that was locked last time is now in the middle of

119
00:06:37,630 --> 00:06:40,350
a group, and it gets simplified along with everything

120
00:06:40,350 --> 00:06:41,260
around it.

121
00:06:41,600 --> 00:06:45,440
Before any of this, every vertex is snapped to one shared

122
00:06:45,440 --> 00:06:49,200
grid, so two clusters that share a vertex store the same

123
00:06:49,200 --> 00:06:50,350
numbers for it.

124
00:06:50,750 --> 00:06:53,799
For the statue the loop runs twelve times.

125
00:06:53,799 --> 00:06:59,013
1.35 million triangles become 673 thousand,

126
00:06:59,013 --> 00:07:04,770
then 336 thousand, and so on down to 132.

127
00:07:04,770 --> 00:07:07,250
Each level is about half the one below,

128
00:07:07,250 --> 00:07:11,969
so all thirteen together hold 2.69 million triangles:

129
00:07:11,969 --> 00:07:13,700
twice the original.

130
00:07:13,700 --> 00:07:16,740
A new cluster is made from the triangles of several

131
00:07:16,740 --> 00:07:19,940
clusters below it, and each of those feeds several

132
00:07:19,940 --> 00:07:21,540
clusters above.

133
00:07:21,540 --> 00:07:24,820
That makes the levels a directed acyclic graph,

134
00:07:24,820 --> 00:07:29,250
a DAG, and this graph is what the compiler writes to disk.

135
00:07:30,905 --> 00:07:34,426
This X-ray view colours each cluster by its level.

136
00:07:34,426 --> 00:07:37,710
Light blue is level zero, the scan itself.

137
00:07:37,710 --> 00:07:40,512
Green is one level up, then yellow,

138
00:07:40,512 --> 00:07:42,269
orange and red.

139
00:07:42,269 --> 00:07:45,035
From here the nearest knights are yellow-green,

140
00:07:45,035 --> 00:07:47,230
two levels above their scan.

141
00:07:47,230 --> 00:07:50,830
The far ones are orange and red, four and five levels

142
00:07:50,830 --> 00:07:51,707
above.

143
00:07:51,707 --> 00:07:54,485
The cliffs are light blue almost everywhere:

144
00:07:54,485 --> 00:07:58,030
their scans have so few triangles for their size that even

145
00:07:58,030 --> 00:08:00,510
the far ones need nearly all of them.

146
00:08:00,510 --> 00:08:02,672
As the camera moves in on one knight,

147
00:08:02,672 --> 00:08:06,300
its clusters change to green and then to light blue.

148
00:08:06,638 --> 00:08:09,760
Two levels meet along every colour boundary in this

149
00:08:09,760 --> 00:08:12,229
picture, and there are no gaps there.

150
00:08:12,229 --> 00:08:15,760
A level boundary always runs along the border of a group,

151
00:08:15,760 --> 00:08:19,230
and that border was locked when the coarser side was made.

152
00:08:23,873 --> 00:08:27,474
Which level should a given piece of surface be drawn from?

153
00:08:27,474 --> 00:08:29,970
Whenever the compiler simplifies a group,

154
00:08:29,970 --> 00:08:32,690
it records how far the new surface can be from the

155
00:08:32,690 --> 00:08:34,051
original scan.

156
00:08:34,051 --> 00:08:37,250
That distance is stored with each new cluster as its

157
00:08:37,250 --> 00:08:38,160
error.

158
00:08:38,566 --> 00:08:42,207
This cluster on the statue's chest is from level two.

159
00:08:42,207 --> 00:08:45,321
Its error is 6.5 millimetres.

160
00:08:45,321 --> 00:08:49,735
From ten metres away, on a screen 1,080 pixels tall,

161
00:08:49,735 --> 00:08:54,089
one metre at the statue covers 124 pixels.

162
00:08:54,089 --> 00:08:59,010
So 6.5 millimetres covers 0.8 of a pixel.

163
00:08:59,350 --> 00:09:02,710
The level above it draws the same surface with an error of

164
00:09:02,710 --> 00:09:04,710
12.1 millimetres.

165
00:09:04,710 --> 00:09:07,940
From here that is 1.5 pixels.

166
00:09:09,396 --> 00:09:12,680
The engine draws a cluster when two things hold.

167
00:09:12,680 --> 00:09:15,318
Its own error is at most one pixel,

168
00:09:15,318 --> 00:09:16,912
so it is fine enough.

169
00:09:16,912 --> 00:09:19,811
And the level above it has an error over one pixel,

170
00:09:19,811 --> 00:09:21,750
so nothing coarser would do.

171
00:09:22,156 --> 00:09:25,370
Follow one piece of surface up through its levels.

172
00:09:25,370 --> 00:09:29,450
The error grows at every step, so it crosses one pixel in

173
00:09:29,450 --> 00:09:30,970
one place only.

174
00:09:30,970 --> 00:09:34,360
The level just below that crossing is the one drawn.

175
00:09:34,699 --> 00:09:37,660
Bring the camera closer and every error covers more

176
00:09:37,660 --> 00:09:40,940
pixels, so the choice moves to a finer level.

177
00:09:40,940 --> 00:09:43,770
Back away and it moves to a coarser one.

178
00:09:44,083 --> 00:09:47,368
Both numbers in the test are stored with the cluster.

179
00:09:47,368 --> 00:09:50,350
No cluster needs to look at its neighbours or follow the

180
00:09:50,350 --> 00:09:51,149
graph.

181
00:09:51,149 --> 00:09:53,549
So the test runs as a compute shader,

182
00:09:53,549 --> 00:09:56,990
a program the GPU runs on many items at once,

183
00:09:56,990 --> 00:09:59,820
and all the clusters are tested in parallel.

184
00:10:01,471 --> 00:10:04,840
This is the demo's wireframe view while the camera pushes

185
00:10:04,840 --> 00:10:08,198
in on the statue from nineteen metres to two.

186
00:10:08,198 --> 00:10:11,080
For most of the way, the triangles stay about the same

187
00:10:11,080 --> 00:10:12,840
size on screen.

188
00:10:12,840 --> 00:10:16,280
As the camera closes in, coarse clusters are replaced by

189
00:10:16,280 --> 00:10:17,640
finer ones.

190
00:10:17,640 --> 00:10:21,000
In the last metres the finest level is the scan itself,

191
00:10:21,000 --> 00:10:23,062
and its triangles grow on screen.

192
00:10:23,062 --> 00:10:26,595
The count drawn per frame never passes five million,

193
00:10:26,595 --> 00:10:29,190
in a scene of 107 million.

194
00:10:34,792 --> 00:10:38,130
The one-pixel rule picks a level for every surface in the

195
00:10:38,130 --> 00:10:41,726
scene, including the surfaces the camera can't see.

196
00:10:41,726 --> 00:10:44,400
Those are removed by three more tests.

197
00:10:44,696 --> 00:10:47,577
A cluster outside the camera's field of view,

198
00:10:47,577 --> 00:10:49,890
its frustum, is skipped.

199
00:10:49,890 --> 00:10:52,900
A cluster that faces entirely away from the camera is

200
00:10:52,900 --> 00:10:53,908
skipped.

201
00:10:53,908 --> 00:10:57,460
Each cluster stores a cone that contains the directions

202
00:10:57,460 --> 00:11:01,906
all its triangles face, so one comparison decides it.

203
00:11:01,906 --> 00:11:05,348
And a cluster hidden behind something nearer is skipped.

204
00:11:05,348 --> 00:11:08,550
For this the engine keeps the depth image of the previous

205
00:11:08,550 --> 00:11:12,789
frame: the distance to the nearest surface at each pixel.

206
00:11:12,789 --> 00:11:15,910
It stores that image at several smaller sizes,

207
00:11:15,910 --> 00:11:19,750
a Hi-Z pyramid, and compares each cluster's bounding

208
00:11:19,750 --> 00:11:21,140
sphere against it.

209
00:11:21,559 --> 00:11:24,113
The clusters that pass are tested again,

210
00:11:24,113 --> 00:11:26,041
triangle by triangle.

211
00:11:26,041 --> 00:11:30,285
By the project's measurement, that last step removes 75 to

212
00:11:30,285 --> 00:11:33,270
83 percent of the triangles that reach it.

213
00:11:34,726 --> 00:11:38,007
The demo can show these decisions from outside.

214
00:11:38,007 --> 00:11:40,890
One key freezes them at the current camera,

215
00:11:40,890 --> 00:11:43,286
and the view is then free to move.

216
00:11:43,286 --> 00:11:46,489
The blue lines are the frozen camera's frustum.

217
00:11:46,489 --> 00:11:48,570
Everything outside it is missing:

218
00:11:48,570 --> 00:11:51,062
the rest of the canyon is bare ground.

219
00:11:51,062 --> 00:11:54,330
Inside it, only the surfaces that camera could see are

220
00:11:54,330 --> 00:11:55,335
drawn.

221
00:11:55,335 --> 00:11:58,451
The far sides of the rocks and statues are missing,

222
00:11:58,451 --> 00:12:00,600
and so is everything they hid.

223
00:12:00,929 --> 00:12:04,700
Through the gate, the frozen camera could see one statue

224
00:12:04,700 --> 00:12:07,819
and a patch of cliff at the far end of the canyon.

225
00:12:07,819 --> 00:12:11,690
They are all that is drawn there, in a few large clusters.

226
00:12:17,349 --> 00:12:19,344
This is the canyon on the server.

227
00:12:19,344 --> 00:12:23,794
Eleven geometry files, 27.6 megabytes together.

228
00:12:23,794 --> 00:12:27,270
One metadata file of 1.4 megabytes.

229
00:12:27,270 --> 00:12:30,870
It says where every object stands, and it holds the error

230
00:12:30,870 --> 00:12:32,851
and bounds of every cluster.

231
00:12:32,851 --> 00:12:35,909
It also carries the coarsest levels of every scan,

232
00:12:35,909 --> 00:12:38,230
about a thousand triangles each.

233
00:12:38,230 --> 00:12:41,860
And one file of textures, 4.8 megabytes.

234
00:12:42,199 --> 00:12:45,480
Opening the world fetches the metadata and the textures in

235
00:12:45,480 --> 00:12:47,437
two parallel requests.

236
00:12:47,437 --> 00:12:51,080
With the errors and bounds, the tab can run the one-pixel

237
00:12:51,080 --> 00:12:52,798
test for the whole canyon.

238
00:12:52,798 --> 00:12:55,960
And with those coarsest levels it can already draw every

239
00:12:55,960 --> 00:12:59,640
object, before it has fetched any geometry file.

240
00:12:59,640 --> 00:13:03,110
This is the canyon drawn from the metadata file alone.

241
00:13:04,598 --> 00:13:08,330
Suppose the test wants a cluster that isn't in memory yet.

242
00:13:08,330 --> 00:13:11,639
The shader draws the coarser cluster above it instead,

243
00:13:11,639 --> 00:13:14,650
so the surface is never missing, and it writes a request

244
00:13:14,650 --> 00:13:16,809
to a buffer, with a priority:

245
00:13:16,809 --> 00:13:19,850
the number of pixels of error that coarser cluster is

246
00:13:19,850 --> 00:13:20,840
causing.

247
00:13:21,248 --> 00:13:24,460
The engine's JavaScript reads that buffer back and looks

248
00:13:24,460 --> 00:13:27,500
up which pages hold the requested clusters.

249
00:13:27,500 --> 00:13:30,940
A page here is a block of up to 16 kilobytes in one

250
00:13:30,940 --> 00:13:32,380
geometry file.

251
00:13:32,380 --> 00:13:35,260
Then it asks the server for those bytes.

252
00:13:35,260 --> 00:13:37,416
This request is from our recording:

253
00:13:37,416 --> 00:13:45,470
bytes 93,679 to 101,598 of the statue's file.

254
00:13:45,470 --> 00:13:48,142
The server answers with status 206,

255
00:13:48,142 --> 00:13:51,130
Partial Content, and those eight kilobytes.

256
00:13:51,463 --> 00:13:55,003
Twelve Web Workers decode pages off the main thread,

257
00:13:55,003 --> 00:13:58,270
and the clusters are copied into the GPU buffer.

258
00:13:58,270 --> 00:14:01,150
On the next frame the test finds them there and draws

259
00:14:01,150 --> 00:14:01,820
them.

260
00:14:03,280 --> 00:14:06,560
The order of pages inside each file is chosen to keep

261
00:14:06,560 --> 00:14:08,469
those requests few.

262
00:14:08,469 --> 00:14:10,706
The coarse levels come first.

263
00:14:10,706 --> 00:14:13,920
Within a level, pages follow a Hilbert curve through the

264
00:14:13,920 --> 00:14:17,890
scan: a path that winds through space without jumping,

265
00:14:17,890 --> 00:14:20,960
so pages that sit together in the file sit together on the

266
00:14:20,960 --> 00:14:22,154
statue.

267
00:14:22,154 --> 00:14:24,813
When our camera moved in close on the statue,

268
00:14:24,813 --> 00:14:28,879
the tab fetched 159 pages of this file.

269
00:14:28,879 --> 00:14:32,372
They came as 19 unbroken runs of bytes,

270
00:14:32,372 --> 00:14:34,830
and each run is one request.

271
00:14:35,165 --> 00:14:38,290
Chromium's cache handles Range requests to the same

272
00:14:38,290 --> 00:14:40,172
address one at a time.

273
00:14:40,172 --> 00:14:43,570
So the engine repeats each range in the address as a query

274
00:14:43,570 --> 00:14:47,730
string, which makes every request a separate cache entry.

275
00:14:47,730 --> 00:14:51,040
In our recording, up to 24 ran at once.

276
00:14:52,549 --> 00:14:56,180
In the demo's stream view, a page flashes light blue when

277
00:14:56,180 --> 00:14:57,348
it lands.

278
00:14:57,348 --> 00:15:01,220
Here the demo's connection is slowed to its simulated 4G

279
00:15:01,220 --> 00:15:02,259
setting.

280
00:15:02,259 --> 00:15:05,220
Now the camera jumps from the sanctum to the mouth of the

281
00:15:05,220 --> 00:15:09,060
valley, where the tab holds every statue only at a coarse

282
00:15:09,060 --> 00:15:10,099
level.

283
00:15:10,099 --> 00:15:13,299
This is the same jump again, slowed down.

284
00:15:13,299 --> 00:15:16,237
The first frames are drawn from the coarse levels.

285
00:15:16,237 --> 00:15:19,377
Then the pages arrive, most urgent first,

286
00:15:19,377 --> 00:15:21,941
and the statues sharpen patch by patch,

287
00:15:21,941 --> 00:15:23,777
all across the frame.

288
00:15:23,777 --> 00:15:27,140
Within two seconds of the jump, every cluster the test

289
00:15:27,140 --> 00:15:29,010
asked for is in memory.

290
00:15:31,589 --> 00:15:35,110
Everything that arrives goes into one GPU buffer,

291
00:15:35,110 --> 00:15:38,630
shared by all the scans and divided into four-kilobyte

292
00:15:38,630 --> 00:15:39,740
blocks.

293
00:15:39,740 --> 00:15:42,950
When it is full, the pages that have gone longest without

294
00:15:42,950 --> 00:15:46,627
being drawn give up their blocks to the new arrivals.

295
00:15:46,627 --> 00:15:51,316
Here the canyon's limit is cut from 56 megabytes to 24,

296
00:15:51,316 --> 00:15:54,280
on the same simulated 4G link.

297
00:15:54,280 --> 00:15:56,361
As the camera flies down the valley,

298
00:15:56,361 --> 00:15:59,880
pages are evicted all the way, and the memory used stays

299
00:15:59,880 --> 00:16:01,430
flat under the limit.

300
00:16:01,766 --> 00:16:04,810
The project's benchmark times how long a view takes to

301
00:16:04,810 --> 00:16:06,650
fill in after a jump.

302
00:16:06,650 --> 00:16:09,610
It runs at a smaller picture size than our recording,

303
00:16:09,610 --> 00:16:12,089
against a server on the same machine.

304
00:16:12,089 --> 00:16:15,370
In the canyon, the first view is complete after about one

305
00:16:15,370 --> 00:16:16,326
second.

306
00:16:16,326 --> 00:16:19,130
Each of the five jumps after it is complete within about a

307
00:16:19,130 --> 00:16:20,569
tenth of a second.

308
00:16:20,569 --> 00:16:24,010
On a simulated 4G link, in three other scenes,

309
00:16:24,010 --> 00:16:26,570
a jump takes a little over half a second.

310
00:16:26,570 --> 00:16:30,170
And in all of these runs, every page that was downloaded

311
00:16:30,170 --> 00:16:31,122
was used.

312
00:16:31,122 --> 00:16:32,600
None was dropped.

313
00:16:37,207 --> 00:16:40,464
Stored plainly, a triangle is three corners,

314
00:16:40,464 --> 00:16:44,218
and each corner is three coordinates of 32 bits.

315
00:16:44,218 --> 00:16:49,340
That is 288 bits per triangle, and it is where the 3.6

316
00:16:49,340 --> 00:16:51,050
gigabytes came from.

317
00:16:51,390 --> 00:16:54,430
The project's file format saves most of that in three

318
00:16:54,430 --> 00:16:55,470
places.

319
00:16:55,470 --> 00:16:58,001
The first is how the triangles connect.

320
00:16:58,001 --> 00:17:01,470
A plain mesh file lists three vertex numbers for every

321
00:17:01,470 --> 00:17:02,433
triangle.

322
00:17:02,433 --> 00:17:06,291
Even at one byte per number, that is 24 bits.

323
00:17:06,291 --> 00:17:10,094
This format uses a method called Edgebreaker instead.

324
00:17:10,094 --> 00:17:13,150
The coder walks across the cluster from each triangle to a

325
00:17:13,150 --> 00:17:16,590
neighbour, and for every step it writes one of six

326
00:17:16,590 --> 00:17:17,550
symbols.

327
00:17:17,550 --> 00:17:20,910
On the statue that comes to under two bits per triangle,

328
00:17:20,910 --> 00:17:22,940
a twelfth of the plain list.

329
00:17:23,279 --> 00:17:25,939
The second is where the vertices are.

330
00:17:25,939 --> 00:17:30,080
On the shared grid, a position is three numbers of 14 bits

331
00:17:30,080 --> 00:17:32,160
each: 42 bits.

332
00:17:32,160 --> 00:17:35,120
But a new vertex is usually close to where its neighbours

333
00:17:35,120 --> 00:17:36,244
suggest.

334
00:17:36,244 --> 00:17:39,280
When the walk reaches one, the decoder guesses that it

335
00:17:39,280 --> 00:17:42,480
completes a parallelogram with the triangle just left,

336
00:17:42,480 --> 00:17:45,931
and the file stores only how far off that guess is.

337
00:17:45,931 --> 00:17:49,905
On the statue, that takes about 19 bits per vertex:

338
00:17:49,905 --> 00:17:51,310
less than half.

339
00:17:51,646 --> 00:17:53,546
The third is the borders.

340
00:17:53,546 --> 00:17:56,770
Two neighbouring clusters have the same vertices along the

341
00:17:56,770 --> 00:17:58,210
border between them.

342
00:17:58,210 --> 00:18:00,450
If the neighbour has already been decoded,

343
00:18:00,450 --> 00:18:03,571
the file does not store such a vertex again.

344
00:18:03,571 --> 00:18:06,530
It stores a short mark that means "take the neighbour's

345
00:18:06,530 --> 00:18:09,970
copy", and that mark costs less than one bit.

346
00:18:09,970 --> 00:18:13,890
In the statue's file, one vertex in six is stored this

347
00:18:13,890 --> 00:18:14,720
way.

348
00:18:15,061 --> 00:18:18,740
What the file holds, then, is three streams of small

349
00:18:18,740 --> 00:18:22,020
numbers: the symbols of the walk, the corrections to the

350
00:18:22,020 --> 00:18:24,581
guesses, and the copy marks.

351
00:18:24,581 --> 00:18:27,860
In each stream a few values come up far more often than

352
00:18:27,860 --> 00:18:28,980
the rest.

353
00:18:28,980 --> 00:18:31,939
An entropy coder gives those the shortest codes,

354
00:18:31,939 --> 00:18:34,900
which is how a symbol can cost less than two bits and a

355
00:18:34,900 --> 00:18:36,610
mark less than one.

356
00:18:36,957 --> 00:18:41,190
The statue's file holds all thirteen levels in 5.9

357
00:18:41,190 --> 00:18:42,229
megabytes.

358
00:18:42,229 --> 00:18:45,670
That is 18 bits for each triangle it stores,

359
00:18:45,670 --> 00:18:48,371
against 288 stored plainly:

360
00:18:48,371 --> 00:18:49,780
one sixteenth.

361
00:18:54,485 --> 00:18:56,839
With this many triangles on screen,

362
00:18:56,839 --> 00:19:00,201
shading each one as it is drawn wastes work.

363
00:19:00,201 --> 00:19:03,480
Much of that shading is overwritten by a nearer triangle a

364
00:19:03,480 --> 00:19:04,630
moment later.

365
00:19:04,970 --> 00:19:07,520
So the first pass computes no colour.

366
00:19:07,520 --> 00:19:11,450
For each pixel it writes one 32-bit number that says which

367
00:19:11,450 --> 00:19:13,930
cluster, and which triangle within it,

368
00:19:13,930 --> 00:19:15,274
is in front.

369
00:19:15,274 --> 00:19:18,428
This image of numbers is a visibility buffer.

370
00:19:18,428 --> 00:19:21,370
A second pass reads the number at each pixel,

371
00:19:21,370 --> 00:19:24,454
fetches that triangle, and computes texture,

372
00:19:24,454 --> 00:19:27,240
light and shadow, once per pixel.

373
00:19:27,554 --> 00:19:32,540
In the project's benchmark, the visibility pass takes 0.45

374
00:19:32,540 --> 00:19:36,780
milliseconds and shading takes 0.37.

375
00:19:36,780 --> 00:19:40,940
Ambient occlusion, sunbeams and tone mapping add a quarter

376
00:19:40,940 --> 00:19:42,723
of a millisecond between them.

377
00:19:42,723 --> 00:19:45,260
Everything else takes a fifth of a millisecond,

378
00:19:45,260 --> 00:19:48,010
and the whole frame is 1.27.

379
00:19:52,589 --> 00:19:55,470
The engine draws only some of the triangles,

380
00:19:55,470 --> 00:19:58,989
so its picture has to be checked against the full mesh.

381
00:19:58,989 --> 00:20:02,272
The demo includes two reference models for this.

382
00:20:02,272 --> 00:20:05,381
Each can be drawn both ways from the same camera:

383
00:20:05,381 --> 00:20:08,110
through the engine, and with every triangle of the

384
00:20:08,110 --> 00:20:09,150
original.

385
00:20:09,150 --> 00:20:11,310
Left of this line is the engine.

386
00:20:11,310 --> 00:20:13,260
Right of it is the original.

387
00:20:13,559 --> 00:20:16,464
Here are the same two pictures as wireframes,

388
00:20:16,464 --> 00:20:19,118
with one small part of each enlarged.

389
00:20:19,118 --> 00:20:21,360
The two are almost the same mesh.

390
00:20:21,360 --> 00:20:24,400
At this picture size, a triangle of the original that the

391
00:20:24,400 --> 00:20:27,280
camera can see is about as small as a pixel,

392
00:20:27,280 --> 00:20:29,760
so the engine has kept nearly all of them.

393
00:20:29,760 --> 00:20:32,130
They differ where this camera can't see.

394
00:20:32,130 --> 00:20:35,200
The demo's freeze holds the levels the engine chose for

395
00:20:35,200 --> 00:20:38,560
this view, while the camera moves round to the back.

396
00:20:38,560 --> 00:20:41,920
There the engine's mesh is coarse, with holes,

397
00:20:41,920 --> 00:20:44,719
and the original is as fine as in front.

398
00:20:44,719 --> 00:20:47,120
Of the original's three million triangles,

399
00:20:47,120 --> 00:20:48,958
the engine drew a third.

400
00:20:48,958 --> 00:20:51,600
From the front again, this is the difference between the

401
00:20:51,600 --> 00:20:55,250
two pictures, brightened sixteen times.

402
00:20:55,250 --> 00:20:58,930
The project repeats this for six views of the two models,

403
00:20:58,930 --> 00:21:03,570
and scores each pair with PSNR, peak signal-to-noise

404
00:21:03,570 --> 00:21:04,815
ratio.

405
00:21:04,815 --> 00:21:07,970
The score rises as two pictures get closer.

406
00:21:07,970 --> 00:21:12,627
Five of the six score between 33 and 53 decibels.

407
00:21:12,627 --> 00:21:16,450
At 33, the pictures differ by about two percent of full

408
00:21:16,450 --> 00:21:17,488
brightness.

409
00:21:17,488 --> 00:21:20,530
At 53, by a fifth of a percent.

410
00:21:20,530 --> 00:21:24,690
For those five, the engine draws between 8 and 31 percent

411
00:21:24,690 --> 00:21:26,129
of the triangles.

412
00:21:26,129 --> 00:21:30,098
In the sixth, a close-up, the two pictures are identical,

413
00:21:30,098 --> 00:21:31,632
pixel for pixel.

414
00:21:31,632 --> 00:21:33,809
A second check looks for cracks:

415
00:21:33,809 --> 00:21:36,450
pixels inside the model's outline where the background

416
00:21:36,450 --> 00:21:37,770
shows through.

417
00:21:37,770 --> 00:21:40,400
In all six views there are none.

418
00:21:42,059 --> 00:21:45,420
These checks live in the repository as three benchmark

419
00:21:45,420 --> 00:21:49,259
suites: image quality, streaming and frame time.

420
00:21:49,259 --> 00:21:52,683
They run in a real browser on a real GPU.

421
00:21:52,683 --> 00:21:56,700
Each suite also counts WebGPU validation errors.

422
00:21:56,700 --> 00:22:00,170
According to these tests, the published demo has none.

423
00:22:04,869 --> 00:22:07,461
Your own model goes through three steps.

424
00:22:07,461 --> 00:22:11,150
The compiler reads an OBJ file and writes the cluster

425
00:22:11,150 --> 00:22:12,104
graph.

426
00:22:12,104 --> 00:22:15,950
The packer orders and compresses it into the static files.

427
00:22:15,950 --> 00:22:18,590
Then the folder goes onto a web server.

428
00:22:18,590 --> 00:22:22,486
For the demo, with five worlds and two reference models,

429
00:22:22,486 --> 00:22:25,870
that folder is 275 megabytes.

430
00:22:25,870 --> 00:22:30,350
Its largest file is 15.5, so it fits servers that limit

431
00:22:30,350 --> 00:22:32,380
the size of a single file.

432
00:22:33,711 --> 00:22:36,519
The engine is also a standalone library.

433
00:22:36,519 --> 00:22:39,880
Your page needs only the engine, and none of the demo's

434
00:22:39,880 --> 00:22:40,921
code.

435
00:22:40,921 --> 00:22:44,600
A scene is a list of assets, a list of where each one is

436
00:22:44,600 --> 00:22:47,478
placed, and a set of camera bookmarks.

437
00:22:47,478 --> 00:22:52,301
Materials, lighting, sky and fog are your own shader code,

438
00:22:52,301 --> 00:22:55,559
compiled into the engine's shaders through hooks.

439
00:22:55,559 --> 00:22:59,160
Each of the demo's five worlds is one scene definition

440
00:22:59,160 --> 00:23:00,550
with its own hooks.

441
00:23:01,806 --> 00:23:04,170
The engine draws rigid meshes.

442
00:23:04,170 --> 00:23:07,250
Skeletal animation is outside the project's scope,

443
00:23:07,250 --> 00:23:09,250
and so are physics and audio.

444
00:23:09,250 --> 00:23:11,969
It needs a browser with WebGPU.

445
00:23:11,969 --> 00:23:15,120
The demo and the source are at these addresses.
