Тёмный

3D World Generation: #3 (Quadtree & LOD) 

SimonDev
Подписаться 187 тыс.
Просмотров 54 тыс.
50% 1

3D World Generation: #3 (Quadtree & LOD)
This is the third in a series of 3d world generation tutorials, covering my quadtree implementation, terrain level-of-detail, and leading to infinite procedural terrain.
What's covered:
* What are Quadtrees
Go over my quadtree implementation and how I ended up using it for LOD (level-of-detail) on the terrain.
* Optimizations
Some optimizations I threw at the implementation to reduce the framerate drops when generating the terrain.
In the future:
This is intended to be part 3 in a series of tutorials on the topic of 3d world generation. Planning on making this a planetary scale thing in a coming tutorial, so look out for that.
Full source code for the project is available, so if you're interested in fiddling with the code, screwing around with it, or improving it.
Github: github.com/simondevyoutube/
Clip Credits:
Travel Albert: • (Remember to Breathe) ...
Justus2utube: • Lord of the Rings - La...
Edson Flausino Junior: • Video
BBC Studios: • Jumping From Space! - ...
#proceduralterrain #gamedevelopment

Наука

Опубликовано:

 

13 апр 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@simondev758
@simondev758 4 года назад
Like & Subscribe, thanks!
@diegomacias7727
@diegomacias7727 Год назад
Hello, how do you blend the vertices for each plane in the quadtree?
@howl2339
@howl2339 Год назад
@@diegomacias7727 i guess he does not... but I am not sure
@bigmistqke
@bigmistqke 3 года назад
Maaaaan. This channel, what a treasure chest.
@Lycam
@Lycam 3 года назад
One possibility is to check the camera distance from the origin, when it reachs a threshold, move it back to the origin and update the chunks heightmap, so you fake movement and also you need to move the placements. But this way you deal with the problem of precision of the position, when you use the usual 32 bit floats, avoiding other problems when you reach huge numbers.
@kanpekiken2481
@kanpekiken2481 3 года назад
Thank you for these tutorials!!! I hope you never stop
@simondev758
@simondev758 3 года назад
ty, got anything you wanna see covered in future vids?
@yukipuki2224
@yukipuki2224 3 года назад
Wow, your tutorials are so awesome. Very informative, concept are very well explained. Instant subscribe
@coloneljcd6041
@coloneljcd6041 3 месяца назад
Amazing video, didnt even know Javascript was this powerful
@omgnowairly
@omgnowairly 7 месяцев назад
It would be awesome if you could explain 3d Gaussian splatting. I'm struggling and your videos make things so clear.
@isaackershnerART
@isaackershnerART 8 месяцев назад
im working on a very different project and needed to understand quad trees and how to approach it. This vid was soo helpful thanks!
@CarlosWong54
@CarlosWong54 2 года назад
Amazing work Simon thank you 😆
@lukeaaron6946
@lukeaaron6946 3 года назад
This is exactly what I need for my current project. Thank you for sharing!
@simondev758
@simondev758 3 года назад
Np, what are you building?
@lukeaaron6946
@lukeaaron6946 3 года назад
@@simondev758 An open world game that runs well on my phone. I'm particularly interested in having the land change based on climate, rockiness etc instead of biomes
@microspacer
@microspacer 2 года назад
Awesome! True gem!
@sc5shout
@sc5shout 3 года назад
How this quadtree would be combined with a tesselation shader? I've got rendered 64 * 64 quad instances and tessellated them in a shader that when the plane is closer to the camera its inner and outer level increases. Although it works, the world is still quite small and I've no idea if I need to extend my shader code or do some stuff on a cpu side. I've found your videos incredibly interesting, but also I'd love to learn more about tesselation shaders and I cannot find any articles that described this topic as if I were an idiot :( and I don't quite understand them.
@tcharlyy
@tcharlyy 3 года назад
Hi, did you try webworkers for the terrain builder? Maybe it wouldn't fit your need, but instead of spreading the generation in the UI thread, i could allow to process it in an independent thread without freezing the UI. Or maybe I'm totally wrong :-) Anyway, I'm a huge (huge!!) fan of all your video and the way you present them. Thanks for sharing them!
@simondev758
@simondev758 3 года назад
Great idea! Yeah that'll totally work, I actually do it later in the series, I think it's #7.
@AmazingMaxStuff
@AmazingMaxStuff 2 года назад
Great video! I wonder which algorithm are you using for the water?
@simondev758
@simondev758 2 года назад
Pretty sure it's just one of the canned ones with three.js.
@AmazingMaxStuff
@AmazingMaxStuff 2 года назад
@@simondev758 Thank you!
@greatbanni
@greatbanni 4 года назад
Hi Simon, thanks for the videos. This content is really helpful and unique. I wanted to know that if you recreate QuadTree every frame? If yes, wouldnt that be too slow?
@simondev758
@simondev758 4 года назад
No problem, glad you're finding it useful. As for your question, yeah I'm recreating it every frame. Is it the best possible way to do this? Almost certainly no, but it's more than fast enough for showing off the technique, and it's simple to understand. I'm a big fan of profiling to decide when to optimize, and this runs at 60fps easily, so I doubt that the quad tree code contributes much per frame.
@lincolnsand5127
@lincolnsand5127 3 года назад
@@simondev758 Yeah. You're doing it the standard way. It's faster to rebuild the tree than try to adjust it every frame
@LabhamJain
@LabhamJain 4 года назад
Very Nice 'N' Helpful
@simondev758
@simondev758 4 года назад
Thanks, are you working on something related?
@LabhamJain
@LabhamJain 4 года назад
@@simondev758 Nah. But I Like To Watch Javascript Based 3D Modeling, Images, Video
@GarronArgentina
@GarronArgentina 3 года назад
I gave it a try to the github repo and I happily fined out that it is possible use the mouse to rotate infinitely the camera when the cursor is hidden
@simondev758
@simondev758 3 года назад
nice
@fr3ddyfr3sh
@fr3ddyfr3sh 3 года назад
Do you, in general, de-quad areas when they are not close anymore? Is that what you did with the pool? Also, I saw an inmplementation, where the quad remaind the same, and only the noise moved “through” the mesh, when the player was moving. Worked great for an infinite plain, but wouldn’t work for interplanetary rendering I guess.
@simondev758
@simondev758 3 года назад
Dynamic tessellation is definitely something I'd like to add, but hasn't been high on the TODO list. re: second idea, yeah I think I've read about that idea, although I haven't tried it myself. The only concern I have there is that as you move, you want to do it incrementally so that the entire mesh doesn't bounce around. It's an interesting approach though.
@fr3ddyfr3sh
@fr3ddyfr3sh 3 года назад
@@simondev758 thanks. It’s awesome, that you invest the time to reply.
@nomadshiba
@nomadshiba Год назад
do you keep the textures resolution high between different size nodes? because it looks funky when texture resolution changes if it has less reference points i mean the resolution of moisture texture i wanted to access those also on CPU so i can do gameplay stuff based on those too
@simondev758
@simondev758 Год назад
These are just vertex shaded IIRC, I don't touch on textures until a later video.
@diegomacias7727
@diegomacias7727 Год назад
if it generates a noise for a plane with a certain number of segments, how do these vertices join the vertices of the planes adjacent to it?
@SaiponathGames
@SaiponathGames 3 года назад
Good job! Was helpful, even tho I don't do this in JS.
@simondev758
@simondev758 3 года назад
Awesome, yeah I try to explain it in a way that isn't platform specific. What did you end up implementing it in?
@SaiponathGames
@SaiponathGames 3 года назад
@@simondev758 Well, I implemented a quadtree before, I was just trying to get into it even more. FYI, I implemented QuadTree in Godot, it's freely available. github.com/sairam4123/QuadTree-Godot
@simondev758
@simondev758 3 года назад
Nice, haven't tried Godot yet, on my TODO list of things to try.
@SaiponathGames
@SaiponathGames 3 года назад
Don't forget to check it, it's cool. I've been using it to develop my big game.
@SketchpunkLabs
@SketchpunkLabs 4 года назад
I see in the wireframe that smaller chunks are not being stitched together with bigger neighbor chunks. Wouldn't this normally create cracks since the smaller chunks have extra vertices on the edges that wont match up correctly with the edges that have less vertices. Btw, src isnt up on github.
@simondev758
@simondev758 4 года назад
Yep, fixing the seams is on my todo list :) When I get a minute away from the kids, I'll just go over every project and make sure they're all up. Hopefully today.
@xavierperry6140
@xavierperry6140 3 года назад
Yeah, I pretty much came across the same issue. It was impossible to not notice the seams when the camera is closer to the ground, like how a player standing on the ground would see things. Although I haven't quite figured out how to work it out, my theoretical solution for this was to have a transition when a smaller chunk meets a larger one. The idea is that the row of vertices in the larger chunk are the same distance apart where the large chunk meets the small chunk, and the row after it is normal. In that row of squares only, you have 3 triangles per square instead of 2. It's hard to explain in just words, so I left a link to a picture of what I mean: gyazo.com/45369ef94042c0d66c8b1425a587aee5 I haven't quite figured out how to put that idea into code, since it basically alters the foundation of triangle generation that I set up earlier, but that's the idea of it.
@ImSoNotSleepy
@ImSoNotSleepy 3 года назад
I ran into this with LOD planets and would also like a solution
@simondev758
@simondev758 3 года назад
Sorry for the late reply, these reply comments don't seem to show up in the admin dashboard in youtube so I had no idea anybody had asked. I haven't revisited this yet, but off the top of my head I think you need to create a skirt around the quadtree cells. I'd imagine that you could either tessellate the lower resolution cell near the edges, or (easier) just force the vertices near the edges of the higher resolution cell to match their neighbours. This should just require a cell to have the edges of the graph and to use neighbouring cells for guidance when generating.
@alonsovalls4633
@alonsovalls4633 2 года назад
How did you manage to get the chunks match with each other if the algorithm is random
@simondev758
@simondev758 2 года назад
Noise is random but continuous
@DomainDrivenDavid
@DomainDrivenDavid 3 года назад
Hi. I really enjoy soaking your knowledge, gerat stuff! In the seams between each terrain chunk I get a visable seam duo to normals. I am gueesing that it comes from the lack of interpolaton done by the vertex shader since everything is drawn seperatly. If I am not way off, how do you solve this?
@simondev758
@simondev758 3 года назад
So I have it fixed locally, but haven't made the video yet. I'll describe the fix. Assuming you've fixed the actual gaps between different chunks, you've still got lighting discontinuities caused by the normals. You're on the right track, the normals are the issue. The problem is that the normals are generated by generating face normals, and then averaging all the face normals for each vertex. Imagin3 2 triangles that share an edge. The 2 vertices that form that edge, when you calculate the normals, will get a normal that's averaged from the 2 different triangle faces. Then imaging if those 2 triangles had the exact same edge, but you didn't average those normals for the edge vertices, you'd see a lighting discontinuity there. There's a bunch of complexity here because you're calculating different levels of detail, and additionally they're being generated on different threads. What I did was used a stable way of generating normals for those edges, by taking finite differences instead of face normals. It worked pretty well, not 100% sure it's the way to go, but so far it works.
@DomainDrivenDavid
@DomainDrivenDavid 3 года назад
@@simondev758 Oh thanks! I got the normals looking good by generating an extra column and row on each side of the chunk to get the correct normal at the edge of the chunk.
@simondev758
@simondev758 3 года назад
@@DomainDrivenDavid Nice! Are you using different levels of detail too? I tried that approach, but wasn't able to fully get rid of the lighting discontinuities.
@DomainDrivenDavid
@DomainDrivenDavid 3 года назад
@@simondev758 Yes, 88 quads of 100x100. I am no pro tho, so it may very well be that you see lighting discontinuities where I do not. I can link short video if you like.
@simondev758
@simondev758 3 года назад
@@DomainDrivenDavid I'm kinda curious, can you run a test where you reduce the chunk resolution super low, like 4x4, and see if the lighting holds up between neighbouring chunks of different resolutions? Need to make the terrain pretty bumpy. This is how I got mine to show the problems prominently.
@glowiever
@glowiever 3 года назад
how did you stitch the lod difference between neighboring chunk?
@simondev758
@simondev758 3 года назад
I haven't yet, coming in a later tutorial. I swear, I'll actually make one at some point. I actually have the code for some later stages done, but getting around to making a video takes me forever.
@Z_Z.t
@Z_Z.t 3 года назад
Checking chunks for division can be implemented branchless (without if)
@simondev758
@simondev758 3 года назад
Interesting, got some code with the changes? And any idea how much of a speedup that provides?
@Z_Z.t
@Z_Z.t 3 года назад
@@simondev758 instead of using if checking every chunck you can just round position to exact chunk origin and get chunk id (thou to go deeper you must use loop). Example: floor(x*chunksizex)/chunksizex - gives x origin of the chunk that contain that x coordinate. Dividing again by chunksizex will return chunk number from 0 x
@Z_Z.t
@Z_Z.t 3 года назад
I dont know by how much exactlcy it speedup, because I were doing something simillar before these tutorials on GML
@CruelCrusader90
@CruelCrusader90 4 месяца назад
hey, newbie game dev. i got a question, and maybe you can make a video on this. why is there so much emphasis on triangles but majority of the systems like grid partitioning is done with right angle triangles which creates squares. wouldn't equilateral triangles and a hexagon grid system be better? i did see your latest video and i think it was a bit of an oversight but even then, your explanation of wasted computational power on the clusters of quad pixels was far less then the right angle triangle compared to the equilateral triangle. (edit: the time stamps at 13:10 vs 13:40 in your latest video - When Optimisations Work, But for the Wrong Reasons) maybe its the simplicity of the code when writing a square grid system compared to a hexagon system?
@evankhaledhosni
@evankhaledhosni Год назад
Hey SimonDev! I cloned the repo for this, but I am noticing it is not infinite. The terrain is huge, but you can reach the end of it. Is there an easy fix for that?
@simondev758
@simondev758 Год назад
I think in this video I was working towards a planet for a later video, so the structure isn't appropriate for infinite size.
@akashmishra811
@akashmishra811 Год назад
Hey I want to draw a line between 2 points in terrain .....line does not attach with terrain ..how to solve this ??can u plz help ..
@markuscwatson
@markuscwatson 8 месяцев назад
All in JavaScript?
@crazyboyandyomama
@crazyboyandyomama Месяц назад
Is this on WebGL, WebGPU, or threeJS?
@howl2339
@howl2339 Год назад
Are there compute shaders in three.js?
@simondev758
@simondev758 Год назад
WebGPU just landed in a recent version of chrome, so yeah as of now it's available.
@perfectionbox
@perfectionbox 3 года назад
google maps and nasa whirlwind (open source c#) use threads.
@simondev758
@simondev758 3 года назад
Thanks! I'll check those out. This series also integrates threading later, I think around #6.
@billclinton4913
@billclinton4913 2 года назад
Are there no seems ?
@simondev758
@simondev758 2 года назад
I deal with them in a later video
@yutian4226
@yutian4226 3 года назад
like
@closingtheloop2593
@closingtheloop2593 Год назад
hiw did you solve the crack problem
@ezequielgarrido51
@ezequielgarrido51 3 года назад
All of this is running on the CPU instead of the GPU? If so, why? Shouldn't ThreeJS optimize for that? Is it not its responsibility?
@simondev758
@simondev758 3 года назад
Not quite, Three.js is a wrapper over WebGL. Its' responsibility is to make that easier, add additional functionality like texture/model loading, scene management, that sort of thing. There's really nothing that will "move" things from the cpu to the gpu except you, the programmer. Writing these for the cpu is just easier, making this all run on the gpu is totally doable but adds an extra layer of complexity to these tutorials.
@ezequielgarrido51
@ezequielgarrido51 3 года назад
@@simondev758 Thanks, that clears it up. Follow up question, where exactly do you need to implement changes to make it run in the GPU? In the custom shaders you're writing?
@simondev758
@simondev758 3 года назад
@@ezequielgarrido51 In WebGL2 yeah, you'll write it in the vertex shader to deform the mesh.
@ezequielgarrido51
@ezequielgarrido51 3 года назад
@@simondev758 Thanks!
@esosaosayamwen9152
@esosaosayamwen9152 2 года назад
Do you have the source code?
@simondev758
@simondev758 2 года назад
It's all on github: github.com/simondevyoutube
@killpidone
@killpidone Год назад
Isn't this an octree not a quadtree since it's in 3d?
@simondev758
@simondev758 Год назад
Octree divides 3d space into 8 children, along each axis. This only takes xz into account.
@killpidone
@killpidone Год назад
@@simondev758 gotcha thanks for the explanation
Далее
치토스로 체감되는 요즘 물가
00:16
Просмотров 1,1 млн
Giving Personality to Procedural Animations using Math
15:30
The ONE Texture Every Game NEEDS
9:00
Просмотров 248 тыс.
How I Learned Procedural Generation
5:36
Просмотров 253 тыс.
Spatial Hash Grids & Tales from Game Development
19:08
Просмотров 112 тыс.
A new way to generate worlds (stitched WFC)
10:51
Просмотров 511 тыс.
When Optimisations Work, But for the Wrong Reasons
22:19