Diamond Square | Procedural Generation | Game Development Tutorial

  Рет қаралды 25,249

White Box Dev

White Box Dev

Күн бұрын

In this video, I explain what diamond square is, how it works, and how to implement it.
0:00 Introduction
0:11 What is diamond square?
0:38 How does it work?
6:58 Implementation
11:08 Demo
🔗 Demo:
whiteboxdev.github.io/bundles...
🔗 Source:
github.com/whiteboxdev/exampl...
🎬 Game Development Tutorial Playlist:
• Game Development Tutorial
#gamedev #tutorial #defold

Пікірлер: 58
@WhiteBoxDev
@WhiteBoxDev 11 ай бұрын
After reaching the 2nd square step at 4:45, I make a handful of manual arithmetic mistakes. I'm sorry about this! Thank you to the people who did the math and commented. My solutions of should actually be . Similar situation with the 2nd diamond step at 5:34. Please follow the algorithm as explained and your answers will be correct. Disappointing mistake.
@gralcio
@gralcio 2 жыл бұрын
If I remember Tarn's presentations correctly, " in the mid-point" is how DF generates local heightmaps starting with high-level world gen constraints at edges.
@DobinSergei
@DobinSergei 11 күн бұрын
It would be nice to add one rule to algorythm. Before all make a mask of bytes, with sizes of map. Using on it a diamond sqare algorythm, with height range = 0..1, we get natural looking areas. Now, we do default diamond square generation of map. But we using not constant rougness, instead we control it with our premade mask. It makes more interesting heights variation. With smaller regions more rough heights variation, and with more steep and smooth plains and hills overall.
@Zicrus
@Zicrus 2 жыл бұрын
1:20 I think the 2nd step is called the diamond step, because it creates a diamond formation, and the 3rd step is the square step. Then the name, diamond square, also makes more sense, since the diamond step is before the square step. It is also what it says on wikipedia.
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
Definitely up to interpretation. In my mind, the first step makes more sense the "square" because we are pulling data from the four square corner nodes into the center node. The second step pulls data from the four diamond corner nodes into the center node. But yes you are correct, most sources will swap the names. It's a good thing semantics aren't as important as the logic.
@Seraph120
@Seraph120 3 жыл бұрын
Keep up the great work. Your style is of explaining is very thorough. That's not something everyone just does or can do right.
@prowokator
@prowokator 3 жыл бұрын
Really like how you go through the "code", its great as the concept doesn't get shadowed by the coding language itself. Subbed fo sho!
@_gamma.
@_gamma. Жыл бұрын
All of your tutorials are awesome, wish there were more!
@apaskiewicz
@apaskiewicz Жыл бұрын
This is fantastic. Thank you so much for this video.
@mikamulperi
@mikamulperi Жыл бұрын
Thank you! Very clear and understandable video.
@MisterRuneex
@MisterRuneex 3 жыл бұрын
Love how you structure your videos. Makes them easy to follow - plus the subjects are very interesting! Keep it up, with your video quality you only need the KZfaq algorithm to show one of your videos once on the front page, and your views and subs will skyrocket ;)
@awesomegamedev
@awesomegamedev 2 жыл бұрын
Nice video! And the algorithm is very cool and simple to probably fit into one of my future "Game in 10 minute" videos Watched this, "Cellular Automata" video, and will be sure to watch the remaining two (and upcoming algorithmic videos:) Subscribed!
@thenaturalpeoplesbureau
@thenaturalpeoplesbureau 3 жыл бұрын
in my terrain gen, i made an option to calculate diamondSqr and then use the different colors to either; add, subtract, multiply or divide each other. So one RGB map from DSqr can generate many different options - although the original colormap can also be used. But the best results i get with divide and multiply, nice river flows emerge and cliffs.. Plasma Fractal is the best terrain gen algo in my opinion.
@danixadem
@danixadem 2 жыл бұрын
Great video. Please keep posting new videos like that one !!
@Sketchaphone
@Sketchaphone 7 ай бұрын
Thanks for demoing all these different techniques. It's really useful to compare the difference in terrain generation methods for my use cases
@WhiteBoxDev
@WhiteBoxDev 7 ай бұрын
No problem, they were fun to make.
@llpBR
@llpBR 6 ай бұрын
I was looking for a different algorithm to make my maps. I've created one from my mind and necer thought it was a cellular automata also. This one is way simpler and effective. I'll try and it!
@MikeDSutton
@MikeDSutton 3 жыл бұрын
Great video, well explained. One suggestion though is in your demo applications, when changing things like the random scalar value that the map is re-generated with the same seed as the current one. This way the behaviour of the variable can be more easily determined in isolation. This is more like the left click behaviour, which doesn't modify the randomness, and only changes the seed.
@ninobrouwers1818
@ninobrouwers1818 3 жыл бұрын
Great videos man! you really manage to cut your topic into smaller pieces which you each give a a thorough and in dept explanation. What I love, is that your explanations are so thorough that it already gives enough information for me to first try recreating the algorithm without having to look at your coding. And then when something doesn't work in my code I can watch the rest of your video to see what you coded different. Much better then the kind of you tube videos where you just copy over the code and mess with it till it works!!!
@WhiteBoxDev
@WhiteBoxDev 3 жыл бұрын
Awesome, good to hear!
@mattzrsimon
@mattzrsimon 3 жыл бұрын
Very nice video!
@thatrealguylogan
@thatrealguylogan 2 жыл бұрын
wow, thank you so much for this tutorial and going through the process!
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
No problem!
@thatrealguylogan
@thatrealguylogan 2 жыл бұрын
@@WhiteBoxDev Hey one question at 4:45 you say we repeat what we did before and get the average again, but when I add 2+4+6+5 and divide by 4 for (x) the average for me was 4.25 instead of 6 as you show, do you know what the problem is that I have missed?
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
@@thatrealguylogan You're correct, it should be 4 instead of 6. I made a mistake there, good catch.
@francescocarbone8466
@francescocarbone8466 10 ай бұрын
Best work.
@darkfrei2
@darkfrei2 3 жыл бұрын
Many thanks! Very helpful, very easy to understand!
@darkfrei2
@darkfrei2 3 жыл бұрын
I've made by myself: kzfaq.info/get/bejne/aMddhdSYz6uRgWw.html
@WhiteBoxDev
@WhiteBoxDev 3 жыл бұрын
You're welcome! Awesome to see you applied it yourself.
@darkfrei2
@darkfrei2 3 жыл бұрын
Another one, with interpolation: kzfaq.info/get/bejne/r7ydiM6btKuUmmQ.html
@cazpfitl
@cazpfitl Жыл бұрын
pretty cool
@burtenplays
@burtenplays 2 жыл бұрын
I'm having a little issue with there being visible diamond patterns in the generated map but as for that its the closest I've gotten so far and its probably just me rewriting it in java. The code explanation along with the example code helped me out as I had tried learning from other sources and they were just nightmare to understand. I watched your other vids as well and look forward to seeing more. *edit Never mind, I got it. Had to rewrite it from a potato level vs trying to understand and port code from a different language and it is flawless. This also means I fully understand it something I struggled with for far too long. Thanks again!
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
Great, glad you got it to work. Yep, procedural generation algorithms can be difficult to grasp intuitively, so no worries there.
@sithmaster
@sithmaster 2 жыл бұрын
I really like it! May I ask as an artist how granular this could get? Wondering about resolution size (like lets say create 4k maps), scaling of terrains, height resolution for grayscale (8 bit, 16bit) VS performance. All best.
@aazimmermann
@aazimmermann 2 жыл бұрын
Any ideas on how we can tile the tile segments generated by the algorithm where each tile is unique?
@sergodobro2569
@sergodobro2569 9 ай бұрын
Respect to pseudocode!
@Inevitablerizzler
@Inevitablerizzler 2 жыл бұрын
This is what notch used in his ludumdare game Minicraft
@aleksandersabak
@aleksandersabak Жыл бұрын
5:11 I did the math myself and it seems like you miscalculated the values. For example average of the corners of the x square is (2 + 4 + 6 + 5)/4 = 4.25, but you show 6. I think this is because instead of dividing by 4 you kept the division by 3 from the previous step, getting 17/3. This seems to also work for other values. Is it right?
@WhiteBoxDev
@WhiteBoxDev 11 ай бұрын
Hi from six months in the future. Sorry for not replying back then, must have missed your comment. Yes, you are correct, I made some arithmetic mistakes while doing the calculations manually. I'll post a standalone comment about this. Thank you.
@aleksandersabak
@aleksandersabak 11 ай бұрын
@@WhiteBoxDev No worries! It was an enlightening video nonetheless, and I enjoyed implementing and playing with the algorithm you presented.
@Defiler86
@Defiler86 Жыл бұрын
Great videos, and do enjoy the language agnostic breakdowns. But something I don't get in this is height_map_size = 2^n+1. What would n equal, and how would one go about figuring out determining a map of a fixed size? (I may just be missing something, but hoping for a clarification.)
@WhiteBoxDev
@WhiteBoxDev Жыл бұрын
2^n+1 simply refers to the number of tiles on your grid, in other words your map size. The algorithm requires the map to conform to this. Why? Because of the way it calculates its diamonds and squares, shrinking smaller and smaller as the algorithm continues. It is just how the math checks out. N can be any value you want it to be. We can interpret n as the number of diamond-square iterations that are required in order to assign a value to every tile on the map. For example, if n = 2, then we will have 2 diamond steps and 2 square steps. Consequently, the size lengths of this map would be 2^2+1, or 5. In total, our map would then be 5x5, or 25 tiles.
@Defiler86
@Defiler86 Жыл бұрын
@@WhiteBoxDev Thanks for the breakdown on it. The length will always be odd, and makes sense in hindsight. (Been stuck in my head to use even numbers on dimensions.) n is the number of iterations the map will go through, and to insure a determined dimensions of the map just requires a little forward math. 2^5+1 would be a length of 33 with 5 interations, and produce a map of 1089 tiles (33^2).
@GaryMcwr
@GaryMcwr 3 жыл бұрын
Is there a reason why the only subtitles option for the video is Korean?
@hatac
@hatac 7 ай бұрын
What happens if the four corner values are the same? I presume you get a flat sea bed, 'swamp', plains or plateau. This gives a uniform sea level. How would you get a highland lake or pond? I presume that would require another algorithm with added passes.
@gingy3778
@gingy3778 2 жыл бұрын
Awesome tutorial! However, may I ask you a question? I’ve got the terrain generating as expected, but I would like to make a map with many continents, a huge world. So, how can I generate a map with a smaller scale? As the maps in your video, and the ones I’ve been able to generate are very “close up” on the islands if you know what I mean, zoomed in. Is there a way to reduce the size of the noise to smaller scales? Anyways, thanks!
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
Sounds like Fractal Noise is the algorithm you want. It allows for infinite worlds and is easily customizable. See my video here: kzfaq.info/get/bejne/kJydatd339qppqs.html
@gingy3778
@gingy3778 2 жыл бұрын
@@WhiteBoxDev great thanks!
@gingy3778
@gingy3778 2 жыл бұрын
@@WhiteBoxDev as you mention in that video, you need a simplex noise library. I’m using gamemaker, and so having trouble finding an appropriate library. By chance, would you know one which would be suitable?
@gingy3778
@gingy3778 2 жыл бұрын
@@WhiteBoxDev I’ve been searching and still am unable to find a proper library.
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
@@gingy3778 I don't know much about Game Maker, but I see it maybe uses its own scripting language? If that's the case, you could ask in the Game Maker forums or Discord if anybody knows of a library for Perlin Noise. If not, you could try porting an existing implementation over to Game Maker's language.
@theb1524
@theb1524 3 жыл бұрын
please remove the empty English transcript so we can at least use auto captions in English. Great Video btw awesome work!
@WhiteBoxDev
@WhiteBoxDev 3 жыл бұрын
Auto captions weren't an issue for my other videos, but for some reason they're not showing up here. I didn't add any extra transcripts, so not sure what's going on. I'll look into it a little more.
@maxdukhovskoy1406
@maxdukhovskoy1406 2 жыл бұрын
7:22 if height_map_size is 5, then how would height_map_size - 1 = 3?
@WhiteBoxDev
@WhiteBoxDev 2 жыл бұрын
I was speaking to the current iteration of the algorithm shown in the image. It is already on the second step. On the first step, you are correct that chunk_size will be 5 - 1 = 4.
@jamesmunroe6558
@jamesmunroe6558 11 ай бұрын
You lost me at 5:23. "The math for calculating each of these values is the exact same as before." Only with our new squares, we have the average of the corner values for x as (2+4+6+5)/4 = 17/4 + R, for y as (4+8+5+4)/4 = 21/4 + R, for z as (6+5+5+4)/4 = 20/4 = 5 + R, and for w as (5+4+4+1)/4 = 14/4 = 7/2 + R. Am I missing something?
@WhiteBoxDev
@WhiteBoxDev 11 ай бұрын
Yes, you are correct, I made some arithmetic mistakes while doing the calculations manually. I'll post a standalone comment about this. Thank you.
@jamesmunroe6558
@jamesmunroe6558 11 ай бұрын
@@WhiteBoxDev OK thanks, I'm glad I wasn't off the beam - I was worried I'd messed up. I'll stay tuned for your comment so I can complete the exercise.
Fractal Noise | Procedural Generation | Game Development Tutorial
19:35
Brian Bucklew - Dungeon Generation via Wave Function Collapse
26:32
Roguelike Celebration
Рет қаралды 42 М.
Better Mountain Generators That Aren't Perlin Noise or Erosion
18:09
Josh's Channel
Рет қаралды 315 М.
The Lightning Algorithm - Numberphile
12:24
Numberphile
Рет қаралды 541 М.
Cellular Automata | Procedural Generation | Game Development Tutorial
15:22
Minecraft terrain generation in a nutshell
25:49
Henrik Kniberg
Рет қаралды 148 М.
Lazy Flood Fill | Procedural Generation | Game Development Tutorial
13:32
Делаю процедурную генерацию в Unity
13:15
How Procedurally Generated Terrain Works
6:24
TheHappieCat
Рет қаралды 135 М.
Dungeon Generation in Gun Game
8:18
Firebelley Games
Рет қаралды 64 М.
Спутниковый телефон #обзор #товары
0:35
Product show
Рет қаралды 2,2 МЛН
Самый дорогой кабель Apple
0:37
Romancev768
Рет қаралды 309 М.
Мой инст: denkiselef. Как забрать телефон через экран.
0:54