W3: Chunked terrain mesh, collision and LOD
TerrainView draws the island as 16 x 16 chunks of 64 m, each at one of four detail levels (2, 4, 8 and 16 m spacing) chosen by distance to the camera. TerrainChunkBuilder builds chunk geometry on WorkerThreadPool threads; the main thread only uploads finished meshes, within a 2 ms per-frame budget, nearest chunks first. - Seams: every chunk hangs skirts deeper than twice the most any level strays from the full-resolution edge, so neighbours at any two levels meet without a crack. Normals come from the full-resolution heightfield at every level, and back faces light like the ground above them. - Splat material: a procedural shader blends sand, marsh, grass and rock with weights from the island's bands, averaged over 4 m so borders blend. Steep ground turns to rock and summits weather pale. - Collision stays SimGround's heightfield, with no renderer involved. - Capture scenarios terrain, terrain_lod (tinted by level) and terrain_cracks (magenta sky). tools/crack_check.gd counts sky pixels seen through the ground; make terrain-capture requires cracks in a skirtless control and none in the real terrain. Tests: chunk vertices sit on the heightfield; skirts cover every pairing of levels on sampled shared edges; detail falls with distance; flying across the island at 30 m/s for 2,037 frames streams 661 chunk rebuilds with the worst main-thread frame at 0.8 to 1.4 ms (headless, CPU only); 24 players over 900 ticks on two generated islands never sink into the ground, and a player sprints up towards a summit unharmed. make terrain-capture: control 437 crack pixels, terrain 0. Closes #10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
## Capture scenario for the streamed island terrain. The camera stands `lift` metres above
|
||||
## the ground at `eye` (x, z) and looks at `target`. With `crack_check` the sky is a flat
|
||||
## magenta that appears nowhere in the terrain, so any crack between chunks shows up as
|
||||
## magenta pixels for tools/crack_check.gd to count.
|
||||
extends Node3D
|
||||
|
||||
const CRACK_COLOUR: Color = Color(1.0, 0.0, 1.0)
|
||||
|
||||
@export var island_seed: int = 2
|
||||
@export var eye: Vector2 = Vector2(700.0, 760.0)
|
||||
@export var lift: float = 12.0
|
||||
@export var target: Vector3 = Vector3(520.0, 35.0, 470.0)
|
||||
@export var show_lod: bool = false
|
||||
@export var crack_check: bool = false
|
||||
@export var fov: float = 70.0
|
||||
## Off only in terrain_cracks_control, which must show cracks.
|
||||
@export var skirts: bool = true
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var island: Island = Island.generate(island_seed)
|
||||
var environment: Environment = Environment.new()
|
||||
if crack_check:
|
||||
environment.background_mode = Environment.BG_COLOR
|
||||
environment.background_color = CRACK_COLOUR
|
||||
environment.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR
|
||||
environment.ambient_light_color = Color(0.5, 0.5, 0.5)
|
||||
environment.tonemap_mode = Environment.TONE_MAPPER_LINEAR
|
||||
else:
|
||||
var sky_material: ProceduralSkyMaterial = ProceduralSkyMaterial.new()
|
||||
sky_material.sky_top_color = Color(0.32, 0.5, 0.68)
|
||||
sky_material.sky_horizon_color = Color(0.82, 0.78, 0.68)
|
||||
sky_material.ground_bottom_color = Color(0.18, 0.2, 0.2)
|
||||
sky_material.ground_horizon_color = Color(0.82, 0.78, 0.68)
|
||||
var sky: Sky = Sky.new()
|
||||
sky.sky_material = sky_material
|
||||
environment.background_mode = Environment.BG_SKY
|
||||
environment.sky = sky
|
||||
environment.ambient_light_source = Environment.AMBIENT_SOURCE_SKY
|
||||
environment.ambient_light_energy = 0.45
|
||||
environment.tonemap_mode = Environment.TONE_MAPPER_FILMIC
|
||||
environment.fog_enabled = true
|
||||
environment.fog_light_color = Color(0.78, 0.78, 0.74)
|
||||
environment.fog_density = 0.0005
|
||||
environment.fog_aerial_perspective = 0.4
|
||||
var world: WorldEnvironment = WorldEnvironment.new()
|
||||
world.environment = environment
|
||||
add_child(world)
|
||||
|
||||
var sun: DirectionalLight3D = DirectionalLight3D.new()
|
||||
sun.rotation_degrees = Vector3(-35.0, -130.0, 0.0)
|
||||
sun.light_energy = 0.95
|
||||
sun.shadow_enabled = not crack_check
|
||||
sun.directional_shadow_max_distance = 600.0
|
||||
add_child(sun)
|
||||
|
||||
var camera: Camera3D = Camera3D.new()
|
||||
camera.fov = fov
|
||||
camera.far = 2000.0
|
||||
camera.position = Vector3(eye.x, island.ground.terrain_height(eye.x, eye.y) + lift, eye.y)
|
||||
add_child(camera)
|
||||
camera.look_at(target)
|
||||
camera.make_current()
|
||||
|
||||
var terrain: TerrainView = TerrainView.new()
|
||||
terrain.setup(island)
|
||||
terrain.focus = camera.position
|
||||
terrain.show_lod = show_lod
|
||||
terrain.skirts = skirts
|
||||
add_child(terrain)
|
||||
terrain.build_all_now()
|
||||
Reference in New Issue
Block a user