Clipmap algorithm

Godot Version

4.7

Question

I have a grid of size 32 x 32 of tiles of size 128 x128 making a terrain of size 4096 x 4096. The

terrain was originally chunked LOD style but I decided to take advantage of the vertex displacement shader and simply drag the terrain grid around underneath the player and then I realized I had a super simple clipmap with very little modification …

cliipmap.gd

	var curr_world_coords_grid32 = Vector3( floor( player.global_position.x / 4.0) , 
											0.0, 
											floor( player.global_position.z / 4.0)  )
	if (( int(curr_world_coords_grid32.x) != int(old_world_coords.x) ) or
		( int(curr_world_coords_grid32.z) != int(old_world_coords.z) ))  :	
		old_world_coords = curr_world_coords_grid32 #Vector3( floor( player.global_position.x ) / 32.0, 0.0, floor( player.global_position.z ) / 32.0 )
		global_position = Vector3(floor( player.global_position.x ) - 2048.0 - 64.0 , 0.0, floor( player.global_position.z ) - 2048.0 - 64.0)

	

What I am asking about is how to do a couple of things …

  1. The clipmap’s Level of Detail (LOD) 0 is 128 x 128, and the tiles can move on integer steps of 4.0, because the fine displacement detail texture is scale 4.0. So every time the player moves 4.0 units I snap the entire set of tiles to the new position. The problem is that the LOD level below that (64 x 64) does not snap cleanly on moves of 4.0. The question is … should the terrain be made of several grids that move at different times, and how should I attempt to fix the overlap if visible?

  2. how should the grid be created in the first place ? At the moment I put LOD 0 at less than 256 units distance from the player, then LOD 1 at 256-512, LOD 2 at 512-1024 etc. Is there a cleaner function or a rectangular function that conveniently a good grid? What is the function called ?

  3. how should I handle virtualizing the data space for the terrain - instead of one 4k image maybe I can add on another 4k image, or even a 2k image, then move smoothly between them - how should the shader handle the transition, and the compute shader - it is all virtualized. Is there a good way of doing that?

  4. If all the tile LOD’s share the same shader, how can I send unique information to them (i.e. what LOD they are, should they snap vertex positions to the next LOD?) without making a unique shader instance ? This is like matrix data, it shouldn’t mean another shader in GPU memory or a unique material.