I Tried Creating a Game Using Real-world Geographic Data

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Sebastian Lague is one of the people in the world that really makes me wonder if I'm the same species as him.

👍︎︎ 291 👤︎︎ u/nomadthoughts 📅︎︎ Nov 02 2021 🗫︎ replies

I get so excited whenever I see that Sebastian Lague has posted a new video. It's the perfect stuff to watch while drinking a big cup of coffee and just sitting there captivated.

👍︎︎ 131 👤︎︎ u/Sholloway 📅︎︎ Nov 02 2021 🗫︎ replies

I have no idea why i clicked on the video, but I sure watched it until the end - the editing, voice, and the clarity of the project was astounding - not to mention how he flawlessly adds stuff to the game. Not sure if you made this video or you just reposted it here, I thank you for making me discover it! Insta subscribe

👍︎︎ 70 👤︎︎ u/overkill87 📅︎︎ Nov 02 2021 🗫︎ replies

Just noticed I spelled his name wrong - should be Sebastian Lague. Too late to edit it now - maybe a mod can fix it?

👍︎︎ 50 👤︎︎ u/DinkyDev 📅︎︎ Nov 02 2021 🗫︎ replies

This guy always works on interesting stuff, and his video editing is great. Truly a treat every time.

👍︎︎ 15 👤︎︎ u/accordingtobo 📅︎︎ Nov 02 2021 🗫︎ replies

I've done this before with USGS DEM data, it's super fun to be able to make realistic maps basically for free. Learned a little about GIS on the way while trying to align the land usage map with the DEM.

👍︎︎ 14 👤︎︎ u/the_Demongod 📅︎︎ Nov 02 2021 🗫︎ replies

This would be a great little game for elementary schoolchildren.

👍︎︎ 4 👤︎︎ u/peon47 📅︎︎ Nov 02 2021 🗫︎ replies

Sebastian is a legend!!!

👍︎︎ 4 👤︎︎ u/whidzee 📅︎︎ Nov 02 2021 🗫︎ replies

Did something similar a few years back but skipped the spherical part and made it a Flat Earth parody game.

👍︎︎ 5 👤︎︎ u/BloodyPommelStudio 📅︎︎ Nov 02 2021 🗫︎ replies
Captions
hello everyone one rainy afternoon i was looking through a few of my many unfinished projects and came across a little idea i started several years ago where you play as a pilot flying around and delivering packages to people all over the globe taking a closer look i found the controls were slightly unrefined to put it politely and though my geographical knowledge is quite terrible i could hardly fail to notice the mysterious sudan shaped hole up here in africa i thought it might be fun to revisit this idea but i've decided to start again from the beginning rather than try fixing up this buggy old project so let's begin by making the earth i have borrowed some sphere generation code from this old tutorial series of mine on procedural planets it's not terribly interesting the main part is just this function for generating a flat plane mesh pointing in some specified direction then there's this bit which uses that function to generate six faces pointing in these directions to create a nice little cube and we can control the resolution of that finally there's this tiny function which takes each point and normalizes it which just means dividing the vector by its own length which causes all the points to be the same distance from the center transforming our humble cube into a perfect sphere at least in theory but it seems that either maths has finally broken or i've made a typo [Music] here it is this should be a plus all right much better although if we're in a nitpicky mode we might be bothered by the fact that these points are a lot more clumped together at the corners of the faces than in the centers fortunately some clever person has come up with this fancy equation and i'll quickly plug that in instead as you can see that just spreads the points out a little more evenly which is maybe not a huge deal but it helps me sleep better at night the next thing i did was download and stitch together this very beautiful height map of the world and i was interested to learn that a lot of this data comes from an old space shuttle mission and the basic idea is that radio waves are bounced off the surface of the earth and the height of the terrain calculated from how long it takes the waves to return this has been combined with data from many other sources to fill in gaps and also to include a map of the ocean depths measured in part by ships bouncing sound waves off the ocean floor so now we just need to be able to convert any point on our sphere to a latitude and longitude and then we'll be able to reach the corresponding height value from the map [Music] and being able to convert in the other direction as well is almost certainly going to be useful at some point so i've been fiddling with sines and cosines and swapping numbers around until i finally ended up with these two functions and just to test that they're definitely working properly i used them to make this little animation of the height map wrapping itself up into a sphere and then unfurling into a flat plane again [Music] with that confirmed to be working i've then projected the height map onto that nice sphere we made earlier and using the height information we can then push the vertices in or out to create this very vertically exaggerated little model of the earth [Music] i find it fascinating looking at the terrain that lies beneath the oceans like this gigantic mountain range sneaking through the middle of the atlantic as someone with a very rocky foundation in geology i've been reading in amazement about how this is at the boundary of two oceanic plates which are drifting apart at a blistering pace of several centimeters per year and how the rift that forms between them gets filled by magma welling up from below causing the underwater mountain to spread out over time it's got me very excited about the prospect of doing a tectonic plate simulation sometime i think that would be a lot of fun it's also interesting to me how all these islands just look like one solid landmass i'm kind of curious how deep the water actually is around here and i guess we can find that out i'll go into the world shader quickly and it's currently just reading the height from the height map which gives a value between zero and one and it colors the terrain between black and white based on that there's also some lighting stuff that i've left out here for clarity but let's convert that height value to meters so i know the lowest point in the map is about 11 000 meters below sea level somewhere here in the mariana trench and the highest point is around 8 000 meters up in the himalayas mount everest is almost 9 000 meters but some of the extreme values have been lost since i've squashed the entire world into a measly 130 million pixels going back to the shader i'll calculate the height in meters and then if the current height is above sea level we can output a different color for that pixel [Music] so let's pick a color here i guess green makes sense and with the sea level set at zero meters we can see all these little islands dotted around then i'll just start lowering the sea level and we can see the island starting to join together and get an idea from that how deep the water is so here's what things would look like if the oceans happen to be about 80 meters shallower i'm not quite sure what i actually want to work on at the moment so i guess i'll just keep messing about until inspiration strikes [Music] i eventually decided to make this simple little player controller so we can fly about and explore the world when you're working with the spherical world though it's important to test what happens at the polls because that's where things tend to go a little pear shaped and sure enough we can see the camera is starting to get a mind of its own so that's going to need some work after some fiddling around i now have this bit of code for the player and this here for simply following along with the camera i've also been spending some time in blender struggling to make this little airplane which i'll bring into the game and let's take it for a quick test flight around the antarctic i noticed there's a strange hole up here in the ice which i guess must be where they stick the south pole alternatively it could be just another bug in my code but i like the first theory better anyway i hope you don't mind indulging my newfound enthusiasm for geology again because i've just been learning about how that south american plate we saw earlier is colliding over here with something called the nazca plate which is being forced downwards resulting in this amazing trench all along chilean peru that same collision is also responsible for compressing the south american plate all along its western edge pushing up of course the andes mountains geology is very cool significantly less cool unfortunately is my gpu so an important optimization is something called frostum culling where only the objects whose bounding boxes are actually within the viewable region of the camera have their mesh data sent to the gpu but as you can see because i made the sphere out of just six chunks it's having to send a lot of data that's obviously not going to end up on the screen so i've been making some small tweaks to the sphere generation code to allow each face of the underlying cube to be split into multiple subfaces so now if we run this again you can see it's able to do a much better job of culling the parts of the planet that are out of view and my gpu is already sounding a lot happier another rather obvious optimization is to simply reduce the number of vertices for example here's a chunk that i've reduced to about 60 000 vertices but because of that it's lacking a lot of detail now i'm currently drawing this with a little test shader that just outputs the normal vector of the surface as a color the normal vector tells us which way the surface is facing and that information is mainly used to calculate how much light would bounce off that surface into the camera which lets us apply some simple shading like so now there's only one normal vector per vertex so the detail of the shading is limited to the resolution of the mesh but it doesn't have to be what we can do is take our height map and write a little compute shader which runs this code here for every pixel in the texture and all it's doing for each pixel is calculating the world's positions of the four adjacent pixels from which we can calculate the direction of the terrain going northwards and eastwards and then the cross product of those tells us the normal vector of the surface at the current pixel so after running that code the alpha channel of the height map still holds the height of the terrain between 0 and 1 like before but in the red green and blue channels we now have this normal information [Music] to actually make use of that let's go back to our shader and we can read in the normal vector from the texture like this and use that for the shading instead so for comparison here's the old per vertex normals and here's our newly generated normal map then here's the old shading and now with the new normals you can see we get a lot more detail essentially for free the next thing i did was find a nice color map of the earth and these are actually available for each month which i thought was quite interesting to see i have taken one of these and used it to give the terrain a splash of color [Music] what i'd like to figure out next is some way of displaying the countries possibly with outlines or maybe some sort of highlighting of the one you're currently over i'm not quite sure yet so i've downloaded some country data it's basically just a big list of points defining the outlines of all the countries and i wrote a little script to load that in which was a very straightforward task that i nonetheless managed to bungle in a number of creative ways but here at last are the countries of the world this data set actually came in three different levels of detail i'm using the medium one so you can see if i zoom in here it is fairly detailed but these small islands over here for example are defined by just a handful of points the next thing i've gone and done is load in some cities from another data set i don't know how exhaustive this data set is but that's 7 324 cities plotted here in case you're curious i'm a bit confused why we have cities in the antarctic though that seems a bit fishy so let me bring up the details here this is apparently vostok with a population of 25 i presume it's some kind of research outpost but let me look that up quickly so i've learned it is indeed a russian research station lying at the southern pole of cold right by the southern pole of inaccessibility which is not the most enticing address i've ever had i will also mention this wikipedia article takes a very dramatic term halfway down anyway after that brief diversion i have now mapped this data to a sphere using that function from earlier so what i'd like to do now is take these debug lines and turn them into a texture so that they can be drawn onto the terrain in the game so i've written up this rather inefficient compute shader to do that essentially for each pixel in the texture it loops through all of the countries and checks if the current pixel is inside the bounding box of that country and if it is it then loops through all the line segments in that country's outline and keeps track of how close the pixel comes to the nearest line segment which it measures using this function over here and once it's done all of that it calculates the strength of the line and writes it to this country data texture to test that i've made the world shader simply draw the texture onto the terrain which gives us this i think it looks fairly decent although in places where the lines go over steep terrain it does look a bit iffy so there's probably a better approach that could be taken but sadly i don't know what that is anyway i'd still like to highlight countries when the player is flying over them and i have a slightly convoluted plan for doing that which i hope is going to work the first step that i've been working on here is to loop through all the countries liquided with the outline but this time we're checking if the pixel is anywhere inside of the country polygon and if it is then the index of the country gets written to that pixel in the country data texture the algorithm for checking if a point is inside a polygon is something i just found online but here's what that code looks like in case you want to know back in our world shader we can now read the country index of the fragment of terrain we're currently drawing from the green channel of the texture and to visualize that we can just divide it by the number of countries we have to give us a color between black and white and here's how that looks [Music] okay we're slowly getting somewhere what i've done next is make yet another compute shader which has this buffer holding a time value for each country which is when the player last visited that country then this code here runs every frame and it calculates first of all where the player is on the country data texture and then it reads from that the index of the country that the player is flying over and finally it sets that country's last visited time to the current time let's make one more trip to our world shader where we can now access that buffer of country visit times we can then use that to figure out how long it's been since the player visited the country we're currently drawing and that information can be used to highlight recently visited countries like so i did say it was convoluted i've been trying this out and it does actually seem to be working which is a very pleasant surprise so with that test successful i've been experimenting with some different ways of integrating it with the actual world shader one idea i thought was interesting was drawing all the countries in greyscale except for the one you're currently flying over which would be in color [Music] when flying over smaller countries though this does often leave a lot of the screen gray which can be a bit dull so i might experiment with something more subtle like just brightening the colors of the country you're flying over i've also been working a little on how the oceans are drawn so here i've clamped all the heights at sea level to get a nice flat surface we can still get the depth information though and use that to blend between a deep and shallow watercolour the results of this do look a bit strange in places but i think it's okay for now then i'll borrow this snippet of code from one of my previous projects to add a specular highlight where the sun reflects off the water that does make the water look very smooth though so i'll take these two wavy normal maps and scroll them across the surface using a technique called tri-planar mapping which is something i covered in my old procedural moons and planets video in case you want to learn more about that in any case that allows us to easily break the light up as though we're bouncing off little waves on the water surface [Music] i'd also like to add a sort of cartoonish foam effect where the water meets the land to do this we need to know how far away from the shore any point in the water is so starting with a mask of the world i have written a little compute shader where each pixel looks at the pixels immediately above and below itself to try update its own distance from the land at first only the pixels right next to the land can be updated but over many iterations we can fill in all the vertical distances then we do another pass which does the same thing but horizontally and together that gives us this nice little distance field i also computed the distances inside the land which we don't need but i just wanted to see what it looked like here is the computator i wrote for generating this it's quite slow which is partially my fault but it's also just a fairly slow algorithm this here is the gpu side of the code and here is the cpu side of it i have heard of a much faster technique called jump flooding which i'd really like to investigate at some point but for now we can map this distance field onto our sphere and then the idea is to take the sine of the distance plus the current time to make these little sine waves that radiate out from the land with a bit more fiddling we can add some noise and scale it down like so to get these tiny little cartoony foam lines which i'm quite fond of the oceans do feel very empty at the moment so i've been spending some more time in blender making this little boat model i then used my old path tool to make some simple little loops for the boats to follow and here one goes something that looks a bit strange though well apart from the boat being about 150 kilometers long is that the boat's not disturbing the water at all so i've tried writing a computer that draws circles at the front of the boat and then slowly diffuses them over time by repeatedly blurring the texture for some reason i expected this to look like a nice foamy wake which it really did not having thought about it some more i think simulating the wake of a boat could be an interesting and challenging project all by itself so for now i'll just try do something super simple instead i've been playing around with this built-in trail render effect but i was struggling to get it to do exactly what i wanted so i decided to write my own trail renderer and now several hours later i am struggling to get that to do what i want instead great progress it's currently behaving rather mysteriously you can see the result at the moment is very weird but if you leave it running for long enough it suddenly has a change of heart and starts sort of behaving i'm not sure what that's about but i've kept working on it and i've eventually got it doing more or less what i want although i am pretty sure by now i could have just done this with the built-in version and saved a whole lot of time anyway i found these nice foamy textures online and used them to create this admittedly slightly strange looking little effect but an entire afternoon has already disappeared trying to make these trails and i think it does look better with them than without so let's just call it a success and move on i should really be thinking about adding some actual gameplay but the trouble is just that i'm having too much fun creating the world and i really want to make some little clouds next so a little while ago i managed to get my old cloud shader working for spherical worlds and i've been considering using that but i think i actually want to try something different here in my most recent video i learned a bit about gpu instancing for efficiently drawing many copies of the same object and i've been playing around with that some more today trying to make cloud shapes out of lots of little spheres after some more experimentation i've come up with this little compute shader which runs for every cloud particle we want to spawn all it does is pick a bunch of random candidate points on the surface of a sphere and evaluate this fractal noise function at each of them the point that has the highest noise value then becomes the spawn point for that particle and this should result in the particles spawning in distinct clumps hopefully at least vaguely resembling clouds over here is the supporting code for that stuff like the fractal noise function generating the random points and so on then there's also this part of the compute shader for updating the clouds what's going on in here is first of all if the particle is within some threshold distance from the player it gets appended to this render buffer which is a new trick i learnt that we don't have to submit all the particles we have for rendering then if the particle is really close to the player i thought it'd be fun if it actually reacts to the collision and gets knocked out of the cloud alright let's try it out so this is not quite what i had in mind but no need to despair yet because it might just be a matter of finding the right parameters for that fractal noise function let's maybe try increasing the noise scale to something like 10 instead and this is actually already looking a lot better we have some distinct cloud shapes and there are some lonely particles floating around by themselves but that's okay let's also try flying through one of these clouds and that feels pretty satisfying it maybe looks a bit odd but i like it now i have an idea for maybe making these look a bit more cloud-like which is simply to blur them so i've made a separate camera which draws the clouds into their own special texture where we can apply some processing just to them here is that texture and i've dug up some old gaussian blur code i wrote to make these nice and blurry something else i want to try is also rendering the particle's normals into this texture and blurring those as well so now we can have another shader whose sole purpose in life is to combine the output from the main camera with our cloud texture and i've experimented over here with giving the cloud some simple shading using those blurred normals let's see what that looks like okay i wasn't expecting that it seems to be rendering the inverse of the clouds so i must have got some numbers back to front somewhere one second okay i've fixed that little issue so now we can try increasing the blur strength and i'll adjust the number of blur iterations as well maybe something like this i think that looks interesting but honestly i might actually have preferred how it was looking before the blur although i do like the subtle shading we get from those blurred normals so i actually have an option here to blur only the normals and leave the alpha channel of the texture alone which holds the shape mask [Music] the style is kind of growing on me and i think if i can get some shadows working for the clouds that would help tie them in better with the rest of the scene with the way i'm rendering them though i think i might need to handle the shadow calculations myself which is something i've never actually done before it's always just been magic happening in the background so i've been experimenting a bit with shadow rendering i have this little test scene here with a directional light and a camera here's what our camera sees but the idea behind shadows is to actually draw the scene from the point of view of the light source we can then do some matrix maths to transform that in a way that lets us see from our camera where the objects would be blocking the light now you might be concerned about the shadows appearing upside down but don't worry i've quadruple checked my maths and it's definitely correct in the end i found the answer to this issue in an obscure forum post in a comment posted two years after the question had already been answered thank you for your service captain science with the correction made here is how the transformation looks now pretty good we can of course change the direction of the light source and it's not without some issues still but mostly working and here it is with the clouds i decided to blur the clouds in the shadow render even though i ended up leaving the actual clouds unblurred because that looked a bit softer and nicer now i should mention there's a lot more than this to a proper shadow implementation involving depth buffers and various ointments for shadow acne and other such issues this is really just a quick hacky thing i try to get working for the clouds alone now with some clouds in the game i couldn't resist quickly trying to integrate the atmosphere shader from one of my older videos so i dropped that in and it really didn't get along well with my cloud system i can't even really tell you what's going on here but i did manage to patch it up in the end here's what that looks like [Music] as you can probably tell i also changed the game camera a bit so that you can actually see the atmosphere otherwise it would have been a little pointless [Music] okay so the original idea was that you're a delivery pilot so with the cloth simulation in mind from the last video i thought about trying to simulate a little parachute for dropping the packages [Music] but after some not so promising tests i decided to just make a simple animation for the parachute instead [Music] i have now put that into the game so we can fly around and deliver packages to our heart's content i've also switched back to the top down view here because this way it's a lot easier to see where the packages are actually going so all that remains to be done for now at least is to tell the player where the deliveries need to be made so that you're not just flying around aimlessly so i've made this super simple ui which just gives the player a random country and a random city within that country then when you deliver the package you'll be evaluated on how far away from the city atlantis which is done using this tiny function let's try it out so starting off we can choose between brazil lesotho and togo and i've decided to head to lesotho since we're in the neighborhood and also it's a fairly small country so even though i don't have a clue where the city of masaru is it's not really possible to be too far wrong at least let's make our next delivery to madagascar this time i've never even heard of the city let alone know where it is so i'm going to make a wild guess and say it's somewhere on the south coast nailed it [Music] so like most of the little games i've made i think this was a lot more fun to create than it would be for anyone to actually play which is fine but i have been thinking about how the gameplay could potentially be spiced up a smidgen one thought was having other aircraft you need to dodge or possibly even pesky package pirates pursuing you through the skies could be interesting i'd of course love to hear if any of you have thoughts on how this could be made more fun to play now you probably noticed something a bit disconcerting happening with the lighting just there i was struggling to make the game look good at night obviously if it's just very dark then that's really annoying to play so for now i've just made the sun kind of awkwardly follow you around but if i do end up revisiting this project in the future i'd love to add things like city lights at night and maybe there could be giant lighthouses illuminating the oceans or something silly like that i suppose one could even just attach a giant spotlight to the aeroplane another thing i'd love to experiment with more is the clouds the cloud formations obviously aren't terribly realistic or interesting but perhaps one could spawn the particles and maybe even move them based on historical weather data i think it'd be really cool to see huge cyclones forming and so on maybe i should just do an entire project on weather simulations that does sound very complicated but maybe some kind of simplified toy version would be feasible and still pretty interesting [Music] one nice side effect of this project for me has been getting more of an appreciation for geology and geography in general even something as simple as just knowing where different countries are in the world i used to be really bad at but now slightly less bad [Music] i still have a lot to learn though coming up in a second you'll see me trying to guess the location of bogota and i thought the one place you probably wouldn't build a city is way up in the mountains so i chose a spot down here but no it's two and a half kilometers up high in the andes mountains anyway this has been a really long video so if anyone is still out there listening to me rambling thank you very much for watching i hope you enjoyed the video and i'd love to hear by the way where in the world you're watching this from alright that's all from me for now so until next time cheers [Music] you
Info
Channel: Sebastian Lague
Views: 2,694,012
Rating: 4.9722996 out of 5
Keywords:
Id: sLqXFF8mlEU
Channel Id: undefined
Length: 31min 37sec (1897 seconds)
Published: Tue Nov 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.