How I Made The World with SINE

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] could you ever imagine that such a world could be created from just one simple sine function indeed here the sine function is taken as a noise function and based on it using the sphere tracing technique the terrain water and Sky of this democene are generated so let's talk about procedural terrain generation in this video and of course take a closer look at how to create such a mysterious planet so the generally accepted approach to procedural terrain generation is to apply Some Noise function to the plane noise functions such as purlin simplex wavelet and others are widely used as noise and let's apply Some Noise function to our plane that is we will shift each point of the plane in height according to the values of the noise function and as you can see we got a nice result and it really looks like some kind of terrain but to make this terrain more realistic the principle of superposition of waves is used and for this a function called fractional Brownian motion is applied the essence of this function is as follows we form a new noise value but with a doubled frequency and accordingly with a halved amplitude and this new value is added to the previous one and such a step in the fbm function is usually called one octave let's then increase the number of octaves and we see that with the growth of octaves our relief acquires more and more detailed features and becomes really like real mountains and if we apply some lighting and shadows to the resulting terrain then we get an excellent result and even a fairly realistic picture of the mountains and if you want a more varied terrain then use a combination of the fbm function along with the noise function but using the standard noise function seems like a trivial task and since all these functions are continuous I decided to do some Challenge and try to generate a world based on the also continuous sine function well let's see what can come of it so for this project in Python using the pygame and motor GL modules an application class was created in which the opengl context is initialized here we form the vertices of two triangles for the plane of our screen form a Vertex array and send it to the input of the opengl pipeline and as you can see a minimum of code is required to write a template for working with opengl so then with the help of the vertex Shader our vertices are sent to the rasterization process to break our plane into fragments and then the fragment Shader is used to determine the color of each pixel on our screen and in the fragment Shader at the moment the basic code for working with the sphere tracing technique is written that is we have a simple Ray marching Loop functions for calculating normals and simple thong lighting and also a function for creating a camera and if you want to learn more about the sphere tracing technique then I suggest watching a video about procedural Graphics first so in the map function assigned distance field for the sphere is defined and if we run the program we will see a nice sphere as an initial example but we don't need a sphere since we will work with a plane and then let's use a separate function to find the distance to the horizontal plane and shift it down by two units and now we have a plane from which we will make a new world and since I wanted to create something mysterious and alien I chose a color space with a predominance of Dark Shades of Gray so I'm working in a left-handed coordinate system and our plane is in the XZ plane and therefore all further manipulations will be carried out with x and z coordinates that is we will change the distance to the plane based on these coordinates according to the values obtained from some noise function so as I said above the noise function will be based on a simple sine function that is we will apply the sine function to each coordinate and let's just add these values if we run the program we will see that our plane has turned into endless Hills and it is already much more interesting to engage in further terraforming and for example let's change the amplitude and frequency for our noise and as a result our Hills Have Become higher and more spaced but in general this does not change much and therefore let's talk about how to significantly improve our Terrain and then using the example of another Shader I propose to consider this aspect in more detail so here we have our noise function and here we will see how this noise looks in 2D and now we see our noise in the form of a height map and here we can clearly see the repeating periodic pattern that we saw in the form of hills and here we apply the fractional Brownian motion function in this function we use the principle of superposition of waves that is we sum up the effects of noise that we get by the number of given octaves at each iteration we get noise and as a rule with reduced amplitude and increased frequency and then we add with the previous noise value but if we look at the result then the whole picture has not changed much we just got a slightly different shape in the place of the former Hills then we can use one trick let's write a matrix for 2D rotation and now on each octave we will rotate the coordinates of the point by some angle and in addition we can add or subtract the previous result and so we got a not ideal but acceptable result now the islands do not repeat in shape and look quite diverse and then let's use this fbm function in our initial Shader so as you remember in our scene we just had Hills obtained using the sine function but now we will apply our fbm function to this picture with some initial settings that you can choose yourself and with this approach we got the generation of the terrain really much more realistic but we will not stop there and let's create something else well here comes the creative work and I then suggest subtracting some noise and also activating a little camera movement and in general our mountains and terrain are almost ready but still some periodicity of patterns can be traced and here we can apply another interesting trick to diversify this mysterious planet since we are creating everything from a sign let's apply the function of the sign itself to the final result and as you can see some natural looking Ledges have appeared in the terrain and this is another good step towards the diversity of our world so now we can see how we went from a simple plane adding a sign-based height offset using the fractional Brownian motion function in some tricks we came up with a very interesting terrain generation without using the standard noise functions but our image is far from perfect because a simple lighting model was used so let's improve our image using slightly more Advanced Techniques and you can see more about them in the corresponding video on the channel so let's start with the fact that it would be nice to add the sky and something like the Sun or the moon this will perfectly complement our world by the way the sky is also created using our fbm function which in turn uses the sine function as noise the next step is to add a fog effect this is a great tool to add a sense of depth and make any landscape more atmospheric further despite the Fong lighting used we can additionally use Shadows I use the soft Shadows function which also becomes one of the elements of giving realism but the use of Shadows greatly hides the details of the terrain they become almost invisible and for this case you can apply another Advanced shading technique this is a function to get ambient occlusion and now we have the Contours of the relief that was not visible due to the use of Shadows and thus our image has become many times better and more realistic and by the way one more unique element such as water can be added to our world to do this using a separate function we find the distance to the plane that oscillates according to the sine function and in order for water to appear in our scene we use the minimum function for the distance values to the terrain and to the water and as you can see we got something like water which actually looks good in contrast to the rest of the terrain but we can still improve this result and for this we will apply our noise function to the water but with a small frequency and depending on the time value and now we have living waves on the surface of the water and again thanks to the sine function but for this water you can also add one more element and let's add the distance to the terrain value to our distance to the water and look at the result and in this case our water became textured a kind of bump mapping effect it looks really unusual and goes well with the fact that we are doing an alien Terrain and finally if it seems to you that there is still some repeating pattern then let's do the following just multiply the fbm value of the function by some value of our noise and we will get another effect so if we look at the difference we can clearly see that the whole Terrain in the water is greatly transformed and we have quite smooth areas as if they were exposed to water erosion for a long time and frankly it turned out to be a pretty cool effect so as you can see once again mathematics can become a good tool in creativity even with the help of the simplest function you can create a whole mysterious and wonderful world or Planet which can rightfully be called a sign [Music]
Info
Channel: Coder Space
Views: 182,477
Rating: undefined out of 5
Keywords: moderngl, moderngl python, noise generation, opengl, opengl python, procedural generation, procedural terrain generation, pygame, python, python opengl, python opengl 3d, python opengl tutorial, raymarching, raymarching python, sine function, sine function python, sine wave, sphere tracing
Id: u1pRapBEHlU
Channel Id: undefined
Length: 9min 34sec (574 seconds)
Published: Wed Nov 30 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.