Coding Terrain From Scratch In Godot

  Рет қаралды 3,909

Majikayo Games

Majikayo Games

Күн бұрын

Download the SimpleTerrain addon here: github.com/majikayogames/Simp...
Follow me on Twitter: / majikayogames
Here's the interactive web demo of the rotation matrix visualization I made for the video: majikayogames.github.io/rotat...
For the demo scene in the video I used the Spatial Gardener addon to add trees and grass to the terrain: github.com/dreadpon/godot_spa...
Contents of this video:
0:00 - Intro
1:40 - Creating terrain with a heightmap & the vertex shader
7:23 - Chunked LOD system
10:00 - Stitching different LOD levels together seamlessly
16:38 - Calculating terrain normals
22:30 - Combining texture normals with linear algebra
38:00 - Triplanar texturing
42:19 - Editor plugin GUI
43:51 - The terrain brush
44:45 - Splatmap
46:27 - Holes & Collision map
47:37 - Outro
Licenses for the assets used in the demo scene in this video (demo scene is included in the releases tab of the GitHub repo):
github.com/majikayogames/Simp...
If you enjoyed this video, consider supporting the channel on Patreon or Ko-fi:
/ majikayogames
ko-fi.com/majikayogames

Пікірлер: 50
@elilentiart8025
@elilentiart8025 8 күн бұрын
This tool is amazing! Thank you so much for sharing this with the Godot community.
@dustinandrews89019
@dustinandrews89019 3 ай бұрын
Chalk up a big win for the algorithm! This was very interesting and very instructive. I’ve done a reasonable amount of work with vector math, but I would’ve reached for trigonometry to solve the normal problem. Vectors is the way to go. This was also really helpful to give me an idea of how shaders work. when I first took a look at shaders, the code was very difficult to understand. But this shader code looks quite simple and intuitive.
@MajikayoGames
@MajikayoGames 3 ай бұрын
Awesome! Really glad you got something out of it. Yep I learned a lot in the making of this video and I felt the same way, this was my first foray into shaders and I'm not sure why I was so scared of them at first. 99% of what you're doing is just moving around vertex positions in the vertex shader (to create effects like the wavy text in the beginning of the video) and setting the color of each pixel one by one in the fragment shader. No magic going on really it's just that. Not sure if I explained the linear algebra/matrix part well but it was the same there! I had learned about matrices vaguely before, but they have this very intuitive visual understanding about them which I hadn't known about till I really gave them a try for myself.
@KevinIndreland
@KevinIndreland 3 ай бұрын
I have tried almost all of the Godot Terrain creators out there and this is the first that will work in browser. Great job and thank you for creating a quality item!
@MajikayoGames
@MajikayoGames 3 ай бұрын
Awesome!! So glad it works for you. Yes I was testing it in browser, I prefer to have browser demos so I can send to friends to test and get a quick feedback loop. Part of the reason is probably because it's 100% GDScript. All the heavy lifting is done in the shader so there's no need for C# or a C++ GDExtension to be used to increase performance. Also makes it easier to modify and iterate on, I tried to keep the codebase pretty simple and condensed.
@KevinIndreland
@KevinIndreland 3 ай бұрын
@@MajikayoGames I'm not happy developing for the browser, with all the limitations and most beauty stripped away in the mobile renderer. But definitely happy I came across your terrain. I was tired of creating terrain in Maya, with low poly collision mesh and importing into Godot.
@zm7160
@zm7160 3 ай бұрын
So nice to have a in-depth explanation of the many aspects of this solution. I have implemented parts of this myself, it works but it was a fever dream and my code is a mess. This is really helpful.
@MajikayoGames
@MajikayoGames 3 ай бұрын
Awesome!!! So glad you got something out of it :) Let me know if I can clarify any parts of it
@BonnieMallet
@BonnieMallet 3 ай бұрын
Great videos! One of the best I have seen on KZbin. Covers various interesting points in terrain generation and Godot. A recommended watch I reckon (for those interested in this sort of thing). Thanks for making and sharing!
@MajikayoGames
@MajikayoGames 3 ай бұрын
Awesome!!! Thanks for your comment glad you enjoyed :)
@amorpilo9666
@amorpilo9666 3 ай бұрын
This is great! The explanation really makes a difference!
@MajikayoGames
@MajikayoGames 3 ай бұрын
Thank you!! Glad you enjoyed! Let me know if I can clarify anything else. I'm still working on video pacing and explanations so I'm hoping to improve on them over time.
@cjdaylight3407
@cjdaylight3407 3 ай бұрын
I was expecting this tutorial gonna teach me how to make this add-on from scratch
@MajikayoGames
@MajikayoGames 3 ай бұрын
Sorry about that ! Experimenting with different video types. Planning on doing some more tutorials in the future.
@proboscideank.7069
@proboscideank.7069 3 ай бұрын
were you expecting someone to feed you and wipe your ass, as well?
@wukerplank
@wukerplank 3 ай бұрын
Incredibly interesting! Thank you for putting this together.
@MajikayoGames
@MajikayoGames 3 ай бұрын
Glad you enjoyed! Was worried it turned out a bit too technical and dry of an explanation but happy at least one person found it interesting!
@wukerplank
@wukerplank 3 ай бұрын
@@MajikayoGames Foundational things aren't flashy, but important none the less. I'm a sucker for procedural generation, so everything I can learn about it is welcome 😊
@MajikayoGames
@MajikayoGames 3 ай бұрын
​@@wukerplank Great to hear it! Actually planning a procedural generation video for my next one... Going to be on level generation though not terrain :)
@wukerplank
@wukerplank 3 ай бұрын
@@MajikayoGames Can't wait to see it!
@t2pol904
@t2pol904 3 ай бұрын
Great video man. I hope you can also do an endless terrain tutorial in the future 😃
@MajikayoGames
@MajikayoGames 3 ай бұрын
Appreciate your comment and thank you! If there's demand for it I definitely would :) the KZbin channel DitzyNinja's Godojo has a tutorial on just that actually if you are interested: kzbin.info/www/bejne/fpjZapx3mcatgck
@PastaMaster115
@PastaMaster115 Ай бұрын
Half of this flew right over my head. I can replicate what you did, but understanding it? Hahaha that's a whole other thing.
@MajikayoGames
@MajikayoGames Ай бұрын
Yeah I was trying to strike the right balance of detail without going too slow here. I think I might have packed quite a lot into this vid so understandable if you didn't understand it all. Not sure what parts you didn't get but I'd be happy to help explain here if you have any questions :) I also just did a more comprehensive explanation of the linear algebra/matrix part I explained in the last part in my newest video, How Godot's Transform3D Type Works, if you didn't get that part.
@Yumenoki99
@Yumenoki99 3 ай бұрын
Such a good watch, I have been wondering how game terrain works for a while, thanks so much for explaining! Especially after trying to model a map in blender and going through lots of frustration trying to manually create LODs for it and trying to paint it in substance painter, big mistake lol. Maybe one day I can try my hand at an own terrain system customized to my needs!~
@MajikayoGames
@MajikayoGames 3 ай бұрын
Glad you enjoyed! Yes I wanted to organize as much of the key details as I could in one video for others interested in learning about it, maybe implementing their own, or to modify mine. I jumped around a bunch of different resources to learn everything in this video so wanted to create a singular resource for it as well as a small public domain code base to save others time and not duplicate work as much as possible. :)
@k4gi
@k4gi 3 ай бұрын
this was a great watch, thanks :)
@nowherebrain
@nowherebrain 3 ай бұрын
I love spatial gardener!
@enzozirotti6427
@enzozirotti6427 3 ай бұрын
This is so helpful thank you!!!!
@MajikayoGames
@MajikayoGames 3 ай бұрын
Glad you enjoyed :D let me know if you have any questions or if I can clarify anything. Was aiming to save others time. Anyone needing to implement terrain in Godot, I wanted this video to be a good reference for, to speed up their process, or you can modify mine and take whatever code you need as it's CC0.
@enzozirotti6427
@enzozirotti6427 3 ай бұрын
Have you worked with ragdolls in Godot 4?
@MajikayoGames
@MajikayoGames 3 ай бұрын
@@enzozirotti6427 I have not! That sounds like an interesting topic though I'll add it to my list of potential video ideas
@davew723
@davew723 2 ай бұрын
Basic question from someone just starting learning...I tried to 'Create a Trimesh Static Body' for the MeshInstance3D in your examples. The problem is the shaders vertex variation isn't getting applied to the collisionshape. Is there a different better way to create the collision body to match the mesh rendering? (BTW...Great video!). Actually just got farther in the video where you briefly discussed your collision map handling. Still wrapping my head around the usage/integration of that function.
@MajikayoGames
@MajikayoGames 2 ай бұрын
Ah yes this is one common problem with vertex shaders. The vertices are not actually 'moved' it's just moved in render. So this means if you create a trimesh static body, it would create a flat plane. Because it's still a flat plane underlying the mesh, we are just morphing them each frame right before rendering in the vertex shader/on the GPU only. The engine still sees it as a flat plane. I also discuss this for normals, to get correct normals with this method you need to calculate them by hand after moving the vertices (17:00). So there are some gymnastics you have to do to use this method, the benefit it is it is more flexible and faster overall for LODs. The way I create my collision meshes, is that I did the same process in GDScript, and made sure the logic was exactly the same as the vertex shader. There isn't any easy way to do this unfortunately, you would either need to do calculate them in code from your heightmap, or do something like create the mesh in blender or a 3D modelling program to have a correct final mesh (or you could export a .mesh from SimpleTerrain and use that on a MeshInstance3D in your scene, I just added this feature the other day). If you calculate them in code you can use the HeightmapShape3D and just add all the image pixel values of your noise texture. Here's the line where I do that in my code: github.com/majikayogames/SimpleTerrain/blob/a074a13789bd64e9a11866fb8fb6d27666145642/addons/SimpleTerrain/SimpleTerrain.gd#L399 Glad you enjoyed the video :) Let me know if you have any more questions
@elilentiart8025
@elilentiart8025 4 күн бұрын
So, I've been playing around with this tool and am having a blast. I have tried several terrain options for Godot and this is by far my favourite and the most intuitive for a beginner. I have a few questions but please forgive my ignorance as I am new to game dev. Is there any way to add further textures to the map or is it locked to 4 (I'm assuming not)? Also, is it possible to use a shader as a texture while still using the splatmap function? A final suggestion, I feel like the one key feature this tool could use is a smooth brush. It could help a lot with sculpting land formations. I realise that is something you have probably already considered but wanted to share my impressions. Thanks again for sharing this!
@MajikayoGames
@MajikayoGames 3 күн бұрын
Glad you are enjoying! All valid questions, and would be very good to add. However, this add-on was more intended as a proof of concept/starting point for anyone to create their own terrain system, modifying mine or referencing my code and this video. For the core of it, I want to keep it as simple as possible. It is locked to 4 textures currently. Shader you couldn't use as a texture. It only accepts Texture2Ds as textures, whereas a shader would be a material (BaseMaterial accepts Texture2Ds to color it). I'm sure if you modified the terrain shader, you could have some interesting setup where for certain colors of the splatmap you could use different fragment shader logic. Smooth brush is a good idea. I wonder does flatten accomplish a similar purpose? I guess not as effectively, probably for smooth you would want to maintain hills. For another pretty easy to use terrain system which has a lot more features such as more than 4 textures, I would recommend hterrain if my SimpleTerrain isn't enough for your needs. Hope this helps :)
@elilentiart8025
@elilentiart8025 3 күн бұрын
@@MajikayoGames Thanks for the reply :) I suspect I'm trying to run before I walk here. If I stick with learning GDScript I could potentially implement these changes myself for my own projects.
@aramagon7011
@aramagon7011 3 ай бұрын
Love this really do. Look I've been grinding tutorials on Godot since the beginning of the year. I'm good with modles and assets for games. And I'm I. The middle of making a game with a terrain and I vae tried terrain3d and mterrain and even though terrain3d is amazing the one thing I have been having trouble with is the texturing export and yes it alous for alot of textures. This what toy have made is awesome. As as I do programing aswell just not in the same language so I can imagine the time you spent in making this. A few things though if you could add more texture options and color and the export of the mesh and texture file that would be great. Texture rotation would be nice too because you could blend more of the textures and also have the option of wetness. But other that that I love this simple terrain. I got it yesterday I've played with it and find it much more useful except the parts I've mension. If it was possible for other programs out there to help you with this it's going to make terrain editing in Godot so much better. The one part is using the assets painter programs isn't really much on how to use it with terrain3d and I thing this what you have made has alot more potential. But really good work on this.
@MajikayoGames
@MajikayoGames 3 ай бұрын
Thank you! :) I really appreciate your comment. I'll make note of those suggestions, once I return to working on SimpleTerrain I'll see what I can do. Working on some other projects and tutorials at the moment. For the texture rotation/tiling idea, I have some plans for that in the future. I want to use something called Wang Tiles. I tried auto blending the textures using an anti-tile rotation method but wasn't happy with the results I got. It looked too distorted So I'd probably like to implement Wang tiles to solve the repeating texture problem. More texture slots I have to think about how I could do that. I know there are some examples of terrain plugins with up to 16 textures with a splatmap.
@MajikayoGames
@MajikayoGames 2 ай бұрын
Hey I ended up needing this feature myself so today I added the functionality to export the terrain as a mesh in the terrain settings in the toolbar. After saving as a .mesh file you can drop it into a new scene then in the top left of Godot click Scene -> Export as -> glTF 2.0 Scene. Then you can import that into blender or a 3D modelling program of your choice. It won't have the textures so you would need to export those separately and set up a splatmap etc in blender's Shading tab but hope it's useful to you :)
@trainzmarcel2074
@trainzmarcel2074 3 ай бұрын
actual collider holes? not even zylann could do that!
@MajikayoGames
@MajikayoGames 3 ай бұрын
Yep got correctly collision mapped holes. Those were actually very quick to add. It's supported natively by Godot physics and jolt for the heightmap collision shape. I recommend using jolt. Also, I found running on jolt separate thread eliminated level load stutters and lag for the terrain. I didn't know zylann's didn't have those. I was actually using his terrain system before I decided to write this one.
@trainzmarcel2074
@trainzmarcel2074 3 ай бұрын
​@@MajikayoGameslol i needed jolt because im making a physics based sandbox and my shapecasts kept glitching and going through the ground with godot physics. what a disaster. i specifically need collider holes because i wanted to make an underground lab and zylanns terrain holes are only visual. now i use a big csg block and hill meshes in some areas because it turns out i cant have 16km^2 terrain that runs smooth on medium end devices.
@MajikayoGames
@MajikayoGames 3 ай бұрын
@@trainzmarcel2074 hmm yeah i was thinking about chunking the terrain collider mesh, but because I didn't run into any performance issues i didn't. I don't think it would be too hard to modify my addon to chunk it. Not sure if that would help/work for your use case. And yes i have found godot jolt to be both much more stable and performant. I heard there may be making it the official physics engine soon.
@Stankhole9
@Stankhole9 3 ай бұрын
😍
@MajikayoGames
@MajikayoGames 3 ай бұрын
@artsmit9545
@artsmit9545 16 күн бұрын
How was the chunking done ?can you explain
@MajikayoGames
@MajikayoGames 16 күн бұрын
The chunking is pretty simple, you can see here: github.com/majikayogames/SimpleTerrain/blob/a074a13789bd64e9a11866fb8fb6d27666145642/addons/SimpleTerrain/SimpleTerrain.gd#L302 _create_lod_meshes and _create_chunks functions create them. It just makes the grid of plane meshes. You only need a number of plane meshes to match the number of your LODs, 5 or whatever, and then all the MeshInstance3Ds can share each mesh. Then in _update_lods each frame, I just set the mesh to use for each chunk, higher LOD the closer to the camera: github.com/majikayogames/SimpleTerrain/blob/a074a13789bd64e9a11866fb8fb6d27666145642/addons/SimpleTerrain/SimpleTerrain.gd#L437 Hope this helps. Let me know if that makes sense
@shxbhfhb8549
@shxbhfhb8549 3 ай бұрын
Add spline road ♥️
@MajikayoGames
@MajikayoGames 3 ай бұрын
Sorry not sure what you mean can you elaborate? 🧐😁😄
How Do Games Render So Much Grass?
15:52
Acerola
Рет қаралды 318 М.
Water simulations in 3Ds Max no plugins needed #3dsmax #3dtutorial
0:42
3 wheeler new bike fitting
00:19
Ruhul Shorts
Рет қаралды 46 МЛН
ТАМАЕВ vs ВЕНГАЛБИ. ФИНАЛЬНАЯ ГОНКА! BMW M5 против CLS
47:36
Procedurally Generated 3D Dungeons
10:26
Majikayo Games
Рет қаралды 32 М.
Programming a multiplayer game from scratch in 7 DAYS
18:28
Crouch + Sourcelike Crouch Jump | Godot 4 FPS Controller Tutorial
19:23
How Godot's Transform3D Type Works
24:16
Majikayo Games
Рет қаралды 691
I tried coding my own graphics engine
4:23
Garbaj
Рет қаралды 187 М.
I Made a Neural Network with just Redstone!
17:23
mattbatwings
Рет қаралды 618 М.
Forest Scene in Godot 4 (Alpha 6) - Terrain, Placement & Assets
16:16
GODOT 4 + Megascans // Can It Compete With UNREAL or UNITY?
8:25
StayAtHomeDev
Рет қаралды 41 М.