Infinite Terrain in Godot 4 - The 'Wandering' Clipmap Terrain Technique (with LOD) — Transcript
Full transcript
- 0:00all right ladies and gents i'm checking
- 0:02in with another video good day to you in
- 0:04today's episode of how to mess around in
- 0:07godot 4 i'm going to take on a very
- 0:09important subject
- 0:11and that is terrain especially large
- 0:14terrain or infinite terrain even
- 0:16i have this interesting technique to
- 0:18demonstrate today which i'm sure i
- 0:20didn't invent i just don't know if it
- 0:22has a name so for the purpose of this
- 0:24video i'ma call it of the wandering
- 0:26terrain uh technique now if you're a
- 0:28godot developer you'll have heard of
- 0:30zillan's height map terrain plug-in for
- 0:32godot 3
- 0:34and that is what i used to use
- 0:36unfortunately zilen hasn't ported his
- 0:38plugin to godot 4 yet and i haven't
- 0:41found anything else that would be half
- 0:42decent so i decided to play around by
- 0:45myself
- 0:46and there are at least a few good
- 0:48approaches to creating cheap terrain in
- 0:51godot
- 0:52and they all have one thing in common
- 0:54they use vertex shaders to deform a flat
- 0:56mesh into a terrain well with this
- 0:58technique you still need a mesh to begin
- 1:00with right because the vertex shader as
- 1:03you know doesn't create vertices it only
- 1:05visually displaces existing vertices
- 1:08so
- 1:09my first idea was to create a grid mesh
- 1:12in the blender and then chunk it up into
- 1:14pieces bring it over to godot
- 1:16and put a vertex shader on it that way
- 1:19you could benefit from godot's frustum
- 1:21culling to call out any chunks which are
- 1:24outside of camera view this is the
- 1:26approach wojtek used in his godot 4
- 1:28forest demo which is freaking brilliant
- 1:31if you haven't seen it go check it out
- 1:33now the problem with trunks though is
- 1:34that you can't use lod for the trunks
- 1:36which are further out because when you
- 1:38decimate a chunk mesh you'll see these
- 1:41horrible looking cracks between the
- 1:42chunks
- 1:43so i thought
- 1:45no i need a way to create various
- 1:47resolutions on a single mesh i need to
- 1:49be able to build a mesh from a height
- 1:51map image and decimate the parts which
- 1:53are further out but still it has to be
- 1:55one mesh
- 1:56so i started to experiment with
- 1:58immediate mesh which used to be known as
- 2:01immediate geometry in good o3 and i was
- 2:03able to create vertices from pixels and
- 2:06build triangles and quads from them and
- 2:08it works but if i was going to collapse
- 2:10the patches of vertices every other
- 2:12frame or whatever i would need to
- 2:14iterate through the arrays each time
- 2:16which is simply not feasible in gd
- 2:19script i mean you can do it in c plus
- 2:21plus if you know how but i suck at c
- 2:23plus plus so that was not an option for
- 2:26me but the idea of having various
- 2:28resolutions on a single mesh stuck with
- 2:30me
- 2:31i just i knew that this was the way i
- 2:33just didn't know how to do it there are
- 2:35two main approaches here one is called
- 2:37quad tree and this one's about
- 2:39subdividing a grid based on your
- 2:40position
- 2:42and and the other one
- 2:44uses the so-called clip map which allows
- 2:46you to decimate the patches of the mesh
- 2:48that are further away from a certain
- 2:49point more or less of course i mean
- 2:51there's a lot more to it but the bottom
- 2:53line is clip map was the one that i
- 2:55wanted but i wanted it without gd native
- 2:58and then it dawned on me that i could
- 3:00just create a clip map mesh in blender
- 3:03it into godot and rather than rebuild it
- 3:05on every frame i could just project the
- 3:07terrain onto it with a vertex shader and
- 3:10then move the terrain with the player
- 3:12and as i moved it i would offset the
- 3:14terrain projection to reverse what the
- 3:16movement has done to it meaning that if
- 3:18i move the clip map plus one meter on
- 3:20the x-axis for example
- 3:22i would then move the projection by a
- 3:24negative one meter on the x-axis to
- 3:27counter the effect and that way the
- 3:28projected terrain would be visually
- 3:30locked in place while the clip map
- 3:32itself would move around now the
- 3:34benefits of this would be multiple but
- 3:36most importantly it would be easy to set
- 3:38up the clip map would only be drawn once
- 3:41and the height map texture could be set
- 3:43to repetitive meaning that the train
- 3:45would be infinite without any impact
- 3:47whatsoever on performance
- 3:50so that's what i did and uh it works
- 3:52pretty damn well i gotta say first i
- 3:54built my clip mesh in blender it's easy
- 3:57enough to do as you can imagine just
- 3:58create a grid and subdivide it a few
- 4:00times
- 4:01then i built my vertex shader for it
- 4:05it's a bit rough but you get the idea i
- 4:07had to decompose the uv vector
- 4:10in order to be able to export the uv x
- 4:13and y as uniforms so that i could then
- 4:15manipulate those variables in gd script
- 4:18then i compose them back into the vector
- 4:203 and connect into the texture 2d uv
- 4:23slot and i also exported the height map
- 4:25texture itself to a texture uniform so
- 4:28that i could easily change it in the
- 4:29inspector later and then i multiply the
- 4:31y coordinate by height value which i
- 4:33also exported to uniform
- 4:35add the vertex input into it and connect
- 4:37into the output boom done so in the
- 4:40inspector you can see i have these
- 4:42shader parameters now which i can
- 4:44manipulate in code
- 4:45and you can see if i scroll the uv
- 4:47coordinates the projection moves as
- 4:50expected if i set the height map
- 4:52multiplier to something higher i get a
- 4:53bigger amplitude and so on so next using
- 4:56gd script i'm going to set the uvs to be
- 4:58locked in place as the ground mesh moves
- 5:01with the player
- 5:02this is what the end result is going to
- 5:04look like now hopefully you can see how
- 5:06the terrain gets more detail as i
- 5:07approach
- 5:09all right let's uh jump into the script
- 5:11i have this snap function which runs
- 5:14once per second this is the function
- 5:16that moves the clip mesh around the
- 5:18world you don't really have to do it in
- 5:19process because the clip map is set to
- 5:22snap to grid so you're not gaining much
- 5:24from running this function more
- 5:26frequently except it would be eating
- 5:28away on your fps you can see here the
- 5:30player's global transform is using the
- 5:32snapped function with a step variable
- 5:35that is set to 20 meters so every time
- 5:38the player moves 20 meters away from a
- 5:40certain position the clip map will move
- 5:42to that position and snap to grid uh the
- 5:44reason snapping is important is that if
- 5:46you unsnap it now actually let me move
- 5:48the snap function to
- 5:50process just for a second so you can see
- 5:51the issue
- 5:53if you unsnap it you'll get this
- 5:55floating terrain effect which looks a
- 5:57bit uh ridiculous so you do need to snap
- 6:00it and it should always be snapped to a
- 6:02round uh number the terrain is following
- 6:04the player's x and y position right here
- 6:07and i am offsetting the uv shader
- 6:09parameters to keep the terrain
- 6:11projection locked in place as the clip
- 6:13map is following the player so basically
- 6:16what i'm doing is reversing the effect
- 6:18of the ground mesh movement by pushing
- 6:21the uvs back by the same increment as
- 6:23the movement increment and the way to
- 6:25achieve this is to divide the uv value
- 6:28by the size of your clip map mesh in
- 6:30meters okay my clip map mesh is 000
- 6:33meters so i divide the uvs by 2 000 and
- 6:36i'm golden by the way if you want to use
- 6:38a fragment shader to texture your
- 6:39terrain which i'm sure you do
- 6:41the rule is the same you have to do you
- 6:44have to do the same thing for the
- 6:46fragment shader otherwise the terrain
- 6:48textures will move with you and that's
- 6:50not what you want unless that's what you
- 6:52want
- 6:53performance seems pretty good if i
- 6:55disable vsync i get about just under 500
- 6:58frames per second without terrain
- 7:00collision and some 380 to 400 frames
- 7:04with collision i'm creating the
- 7:05collision shape from the same height map
- 7:07image which i'm using for the terrain
- 7:10there is a simple although a little bit
- 7:11tricky way to do this and i will explain
- 7:14that in my next video where i'm also
- 7:16expecting to be able to show you a way
- 7:18to implement vegetation with this
- 7:20technique
- 7:21so stay tuned for that and in the
- 7:23meantime do try out this technique and
- 7:25let me know what results you get also
- 7:27check my twitter for more frequent
- 7:29updates i hope you enjoyed the video
- 7:32i'll see you in the next one take care
- 7:42[Music]
- 7:51you
About this transcript
This page contains the full transcript of Infinite Terrain in Godot 4 - The 'Wandering' Clipmap Terrain Technique (with LOD) by devmar, generated from the public captions YouTube serves with the video. The transcript has 1,488 words across 216 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.