mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 13:59:12 +01:00
Tiles drawn at the same level met exactly, but a finer tile beside a coarser one has samples on their shared edge that the coarser one skips, and the ground between them could open up. This closes the gap the standard way (CDLOD): each vertex slides towards the next coarser level as its distance nears the end of its level's range, so that by the end of the band a tile is, vertex for vertex, the coarser tile beyond it. Levels also stop popping when they change. The mip chain is point sampled, so the next level's grid is this level's even samples. An odd vertex slides onto its even neighbour and takes its height, and the grid, whose diagonals all run the same way at every level, collapses exactly into the coarser triangulation. No second texture and no neighbour information is needed; the morph is computed per vertex from its distance to the camera, the same distance the level is chosen by. Two things the geometry demands, both settled by tools/terraincook/seamcheck.py, which walks random camera positions over 128 m, 256 m and 12.8 km tiles and counts every edge vertex where the finer side has not finished morphing or the coarser side has started: - the band ends a rescan's worth of travel (a quarter tile) short of the level's range. Levels are chosen where the camera stood at the last rescan, the morph follows it every frame, and a band ending at the range itself left gaps at every level boundary; - the band is a fifth of the range wide, and level ranges are counted in tiles (four for the finest level) rather than fixed metres, which keeps the coarser tile's band clear of any edge a finer tile reaches, whatever the tile size. The script finds no gap with these values. In the game on baltyk, a low view differs from the unmorphed shader only in a strip of distant ground at the horizon, and nearer than the first band the picture is identical. The cooker's comment claimed tile seams were identical at every level; that held only for neighbours at the same level, and now says so.
96 lines
4.1 KiB
Python
Executable File
96 lines
4.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Checks that terrain tiles at neighbouring levels meet without gaps.
|
|
|
|
The renderer picks each tile's level from its distance at the last rescan, and morphs every
|
|
vertex towards the next level as the camera moves (rendering/terrainclipmap.vert). Two
|
|
neighbours at levels L and L+1 share their edge exactly when, all along it, the finer tile
|
|
has finished morphing and the coarser one has not started. This walks random camera
|
|
positions, lets the camera drift up to a rescan's distance from where the levels were
|
|
chosen, and counts every edge vertex where that does not hold.
|
|
|
|
The constants mirror rendering/terrainstatus.cppm; change them together. Exits non-zero
|
|
when a gap is found.
|
|
"""
|
|
|
|
import math
|
|
import random
|
|
import sys
|
|
|
|
FINEST_TILES = 4.0 # terrain_finest_tiles
|
|
RESCAN_TILES = 0.25 # terrain_rescan_tiles
|
|
MORPH_BAND = 0.2 # terrain_morph_band
|
|
LEVELS = 6
|
|
|
|
|
|
def check(tilesize, step, trials, reach):
|
|
finest = FINEST_TILES * tilesize
|
|
|
|
def level_range(level):
|
|
return finest * 2 ** level
|
|
|
|
def level_for(distance):
|
|
if distance <= finest:
|
|
return 0
|
|
return min(int(math.log2(distance / finest)) + 1, LEVELS - 1)
|
|
|
|
def nearest(x, z, tilex, tilez):
|
|
nx = min(max(x, tilex * tilesize), (tilex + 1) * tilesize)
|
|
nz = min(max(z, tilez * tilesize), (tilez + 1) * tilesize)
|
|
return math.hypot(nx - x, nz - z)
|
|
|
|
def morph(level, distance):
|
|
if level + 1 >= LEVELS:
|
|
return 0.0
|
|
end = level_range(level) - RESCAN_TILES * tilesize
|
|
begin = end - MORPH_BAND * level_range(level)
|
|
return min(max((distance - begin) / (end - begin), 0.0), 1.0)
|
|
|
|
gaps = 0
|
|
example = ""
|
|
for _ in range(trials):
|
|
scanx, scanz = random.uniform(-5000, 5000), random.uniform(-5000, 5000)
|
|
drift, heading = random.uniform(0, RESCAN_TILES * tilesize), random.uniform(0, 2 * math.pi)
|
|
camx, camz = scanx + drift * math.cos(heading), scanz + drift * math.sin(heading)
|
|
basex, basez = math.floor(camx / tilesize), math.floor(camz / tilesize)
|
|
for tilex in range(basex - reach, basex + reach):
|
|
for tilez in range(basez - reach, basez + reach):
|
|
here = level_for(nearest(scanx, scanz, tilex, tilez))
|
|
for stepx, stepz in ((1, 0), (0, 1)):
|
|
there = level_for(nearest(scanx, scanz, tilex + stepx, tilez + stepz))
|
|
if here == there:
|
|
continue
|
|
if abs(here - there) > 1:
|
|
gaps += 1
|
|
continue
|
|
fine, coarse = min(here, there), max(here, there)
|
|
count = int(tilesize / step) >> fine
|
|
for index in range(count + 1):
|
|
along = index * tilesize / count
|
|
if stepx:
|
|
x, z = (tilex + 1) * tilesize, tilez * tilesize + along
|
|
else:
|
|
x, z = tilex * tilesize + along, (tilez + 1) * tilesize
|
|
distance = math.hypot(x - camx, z - camz)
|
|
# an odd vertex of the finer tile is not on the coarser grid and has
|
|
# to have finished its move; the coarser edge must not be moving yet
|
|
if (index % 2 == 1 and morph(fine, distance) < 1.0) or morph(coarse, distance) > 0.0:
|
|
gaps += 1
|
|
if not example:
|
|
example = (f"camera {camx:.0f},{camz:.0f}, levels {fine}/{coarse}, "
|
|
f"distance {distance:.0f} m")
|
|
return gaps, example
|
|
|
|
|
|
def main():
|
|
random.seed(1)
|
|
failed = False
|
|
for tilesize, step, trials, reach in ((128, 1.0, 300, 40), (256, 2.0, 300, 40), (12800, 100.0, 60, 6)):
|
|
gaps, example = check(tilesize, step, trials, reach)
|
|
print(f"tile {tilesize} m, grid {step} m: {gaps} gaps" + (f" (e.g. {example})" if gaps else ""))
|
|
failed = failed or gaps > 0
|
|
return 1 if failed else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|