YouTube2Text

Infinite Terrain in Godot 4 - The 'Wandering' Clipmap Terrain Technique (with LOD) — Transcript

by devmar · 1,488 words · 216 segments · language en · Watch on YouTube

Full transcript

  1. 0:00all right ladies and gents i'm checking
  2. 0:02in with another video good day to you in
  3. 0:04today's episode of how to mess around in
  4. 0:07godot 4 i'm going to take on a very
  5. 0:09important subject
  6. 0:11and that is terrain especially large
  7. 0:14terrain or infinite terrain even
  8. 0:16i have this interesting technique to
  9. 0:18demonstrate today which i'm sure i
  10. 0:20didn't invent i just don't know if it
  11. 0:22has a name so for the purpose of this
  12. 0:24video i'ma call it of the wandering
  13. 0:26terrain uh technique now if you're a
  14. 0:28godot developer you'll have heard of
  15. 0:30zillan's height map terrain plug-in for
  16. 0:32godot 3
  17. 0:34and that is what i used to use
  18. 0:36unfortunately zilen hasn't ported his
  19. 0:38plugin to godot 4 yet and i haven't
  20. 0:41found anything else that would be half
  21. 0:42decent so i decided to play around by
  22. 0:45myself
  23. 0:46and there are at least a few good
  24. 0:48approaches to creating cheap terrain in
  25. 0:51godot
  26. 0:52and they all have one thing in common
  27. 0:54they use vertex shaders to deform a flat
  28. 0:56mesh into a terrain well with this
  29. 0:58technique you still need a mesh to begin
  30. 1:00with right because the vertex shader as
  31. 1:03you know doesn't create vertices it only
  32. 1:05visually displaces existing vertices
  33. 1:08so
  34. 1:09my first idea was to create a grid mesh
  35. 1:12in the blender and then chunk it up into
  36. 1:14pieces bring it over to godot
  37. 1:16and put a vertex shader on it that way
  38. 1:19you could benefit from godot's frustum
  39. 1:21culling to call out any chunks which are
  40. 1:24outside of camera view this is the
  41. 1:26approach wojtek used in his godot 4
  42. 1:28forest demo which is freaking brilliant
  43. 1:31if you haven't seen it go check it out
  44. 1:33now the problem with trunks though is
  45. 1:34that you can't use lod for the trunks
  46. 1:36which are further out because when you
  47. 1:38decimate a chunk mesh you'll see these
  48. 1:41horrible looking cracks between the
  49. 1:42chunks
  50. 1:43so i thought
  51. 1:45no i need a way to create various
  52. 1:47resolutions on a single mesh i need to
  53. 1:49be able to build a mesh from a height
  54. 1:51map image and decimate the parts which
  55. 1:53are further out but still it has to be
  56. 1:55one mesh
  57. 1:56so i started to experiment with
  58. 1:58immediate mesh which used to be known as
  59. 2:01immediate geometry in good o3 and i was
  60. 2:03able to create vertices from pixels and
  61. 2:06build triangles and quads from them and
  62. 2:08it works but if i was going to collapse
  63. 2:10the patches of vertices every other
  64. 2:12frame or whatever i would need to
  65. 2:14iterate through the arrays each time
  66. 2:16which is simply not feasible in gd
  67. 2:19script i mean you can do it in c plus
  68. 2:21plus if you know how but i suck at c
  69. 2:23plus plus so that was not an option for
  70. 2:26me but the idea of having various
  71. 2:28resolutions on a single mesh stuck with
  72. 2:30me
  73. 2:31i just i knew that this was the way i
  74. 2:33just didn't know how to do it there are
  75. 2:35two main approaches here one is called
  76. 2:37quad tree and this one's about
  77. 2:39subdividing a grid based on your
  78. 2:40position
  79. 2:42and and the other one
  80. 2:44uses the so-called clip map which allows
  81. 2:46you to decimate the patches of the mesh
  82. 2:48that are further away from a certain
  83. 2:49point more or less of course i mean
  84. 2:51there's a lot more to it but the bottom
  85. 2:53line is clip map was the one that i
  86. 2:55wanted but i wanted it without gd native
  87. 2:58and then it dawned on me that i could
  88. 3:00just create a clip map mesh in blender
  89. 3:03it into godot and rather than rebuild it
  90. 3:05on every frame i could just project the
  91. 3:07terrain onto it with a vertex shader and
  92. 3:10then move the terrain with the player
  93. 3:12and as i moved it i would offset the
  94. 3:14terrain projection to reverse what the
  95. 3:16movement has done to it meaning that if
  96. 3:18i move the clip map plus one meter on
  97. 3:20the x-axis for example
  98. 3:22i would then move the projection by a
  99. 3:24negative one meter on the x-axis to
  100. 3:27counter the effect and that way the
  101. 3:28projected terrain would be visually
  102. 3:30locked in place while the clip map
  103. 3:32itself would move around now the
  104. 3:34benefits of this would be multiple but
  105. 3:36most importantly it would be easy to set
  106. 3:38up the clip map would only be drawn once
  107. 3:41and the height map texture could be set
  108. 3:43to repetitive meaning that the train
  109. 3:45would be infinite without any impact
  110. 3:47whatsoever on performance
  111. 3:50so that's what i did and uh it works
  112. 3:52pretty damn well i gotta say first i
  113. 3:54built my clip mesh in blender it's easy
  114. 3:57enough to do as you can imagine just
  115. 3:58create a grid and subdivide it a few
  116. 4:00times
  117. 4:01then i built my vertex shader for it
  118. 4:05it's a bit rough but you get the idea i
  119. 4:07had to decompose the uv vector
  120. 4:10in order to be able to export the uv x
  121. 4:13and y as uniforms so that i could then
  122. 4:15manipulate those variables in gd script
  123. 4:18then i compose them back into the vector
  124. 4:203 and connect into the texture 2d uv
  125. 4:23slot and i also exported the height map
  126. 4:25texture itself to a texture uniform so
  127. 4:28that i could easily change it in the
  128. 4:29inspector later and then i multiply the
  129. 4:31y coordinate by height value which i
  130. 4:33also exported to uniform
  131. 4:35add the vertex input into it and connect
  132. 4:37into the output boom done so in the
  133. 4:40inspector you can see i have these
  134. 4:42shader parameters now which i can
  135. 4:44manipulate in code
  136. 4:45and you can see if i scroll the uv
  137. 4:47coordinates the projection moves as
  138. 4:50expected if i set the height map
  139. 4:52multiplier to something higher i get a
  140. 4:53bigger amplitude and so on so next using
  141. 4:56gd script i'm going to set the uvs to be
  142. 4:58locked in place as the ground mesh moves
  143. 5:01with the player
  144. 5:02this is what the end result is going to
  145. 5:04look like now hopefully you can see how
  146. 5:06the terrain gets more detail as i
  147. 5:07approach
  148. 5:09all right let's uh jump into the script
  149. 5:11i have this snap function which runs
  150. 5:14once per second this is the function
  151. 5:16that moves the clip mesh around the
  152. 5:18world you don't really have to do it in
  153. 5:19process because the clip map is set to
  154. 5:22snap to grid so you're not gaining much
  155. 5:24from running this function more
  156. 5:26frequently except it would be eating
  157. 5:28away on your fps you can see here the
  158. 5:30player's global transform is using the
  159. 5:32snapped function with a step variable
  160. 5:35that is set to 20 meters so every time
  161. 5:38the player moves 20 meters away from a
  162. 5:40certain position the clip map will move
  163. 5:42to that position and snap to grid uh the
  164. 5:44reason snapping is important is that if
  165. 5:46you unsnap it now actually let me move
  166. 5:48the snap function to
  167. 5:50process just for a second so you can see
  168. 5:51the issue
  169. 5:53if you unsnap it you'll get this
  170. 5:55floating terrain effect which looks a
  171. 5:57bit uh ridiculous so you do need to snap
  172. 6:00it and it should always be snapped to a
  173. 6:02round uh number the terrain is following
  174. 6:04the player's x and y position right here
  175. 6:07and i am offsetting the uv shader
  176. 6:09parameters to keep the terrain
  177. 6:11projection locked in place as the clip
  178. 6:13map is following the player so basically
  179. 6:16what i'm doing is reversing the effect
  180. 6:18of the ground mesh movement by pushing
  181. 6:21the uvs back by the same increment as
  182. 6:23the movement increment and the way to
  183. 6:25achieve this is to divide the uv value
  184. 6:28by the size of your clip map mesh in
  185. 6:30meters okay my clip map mesh is 000
  186. 6:33meters so i divide the uvs by 2 000 and
  187. 6:36i'm golden by the way if you want to use
  188. 6:38a fragment shader to texture your
  189. 6:39terrain which i'm sure you do
  190. 6:41the rule is the same you have to do you
  191. 6:44have to do the same thing for the
  192. 6:46fragment shader otherwise the terrain
  193. 6:48textures will move with you and that's
  194. 6:50not what you want unless that's what you
  195. 6:52want
  196. 6:53performance seems pretty good if i
  197. 6:55disable vsync i get about just under 500
  198. 6:58frames per second without terrain
  199. 7:00collision and some 380 to 400 frames
  200. 7:04with collision i'm creating the
  201. 7:05collision shape from the same height map
  202. 7:07image which i'm using for the terrain
  203. 7:10there is a simple although a little bit
  204. 7:11tricky way to do this and i will explain
  205. 7:14that in my next video where i'm also
  206. 7:16expecting to be able to show you a way
  207. 7:18to implement vegetation with this
  208. 7:20technique
  209. 7:21so stay tuned for that and in the
  210. 7:23meantime do try out this technique and
  211. 7:25let me know what results you get also
  212. 7:27check my twitter for more frequent
  213. 7:29updates i hope you enjoyed the video
  214. 7:32i'll see you in the next one take care
  215. 7:42[Music]
  216. 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.