Sunday, 28 June 2015

GSoC Week 2 : Adding Noise Functions for creating Procedural Terrain

This week is all about implementation of different noise functions in Heightmap class. I have covered the basic implementation of a noise function earlier and also added the c bindings. This week I will be extending my work by implementing Simplex Noise. I will be writing a detailed blog on an explanation on the Simplex Noise algorithm but here I will just go through the work that I did so far.

Basically I added two main functions that will generate noise based on the Simplex Noise algorithm. One is raw noise function that will calculate the noise from the simplex grid and return a value between -1 and 1. Other function is octave noise which will add multiple passes of raw noise with higher frequency and lower amplitude in each successive pass. The noise functions are adapted from Stefan Gustavson's implementation of Simplex Noise.


Here is the screenshot for the final output that is generated by the noise functions. The above terrain is created by applying ten octaves of Simplex noise with frequency being doubled and amplitude being reduced to half at each successive pass. Though results are not satisfactory for now, but they are reasonable enough to move on to the next milestone that will use the terrain.

To sum it up, the current API call for generating landscape using pseudo random noise function is soy.textures.Heightmap(texture_width, texture_height, frequency). Here increasing frequency means that more gradient points are added in the free space which are then normalized to give a look of a smooth terrain. I am still working on it and will keep adding improvements to it.

Friday, 12 June 2015

GSoC Week 1 : Start of the coding period Part 2

So to give some idea about heightmap, here is an example which I have written using Python in Pysoy. It basically generates pseudo random texel values over the required texture. I have created a four vertex mesh and applied the textured material while mapping the texture over it using the uv coordinates. Here I am just coloring texels with eight bit greyscale values.


By changing the smooth attribute we can toggle between the abrupt pixelation to smoothly varying interpolated colour values which is just like a blurred image.


So this is what a heightmap would look like, although after implementation this would create the most unrealistic and terrific looking terrain. As we can see that light colour values will create hills and other elevated areas and darker values will create valleys. This was just a test and the final implementation would be much better.

For now, PySoy has an API call for getting heightmap data from PNG or JPG format images and it passes it over as eight bit grey-scale values. My task for the rest of the week is to implement my small test code in LibSoy where all the processing happens. For this I need to implement another method in Heigtmap class which can take some numerical values like dimensions of heightmap and couple of other variables as parameters.

A code snippet from LibSoy (Language : Genie)

As you can see that there is a noise function which is being called inside the heightFieldData method. This is where the pseudo random texel values are assigned. The above method need to have corresponding C bindings in PySoy so that it can be called from there. Another step was to add the required bindings for this.

Writing binding was bit tricky but not as tough as I anticipated. Actually I just added a few lines of code to the present bindings for Heightmap API. The most important part of it was to parse the parameters and pass the function as a g object, the rest is taken care by the LibSoy libraries.

With this done, I am almost in the beginning of week two and already pushed this much of work. By the way, I am also getting a hang of Mercurial, which is a version control system written in Python. It is similar to Git and easy to use. With the completion of week one, I have a clearer view of things lying ahead. Next step would be to implement the different noise functions. 

So stay tuned to know more about the upcoming week. 

Thursday, 11 June 2015

GSoC Week 1 : Start of the coding period Part 1

First of all I am new to writing blogs, so I might be unstructured with expressing my work progress and thoughts here. Secondly I am also a bit busy with my undergraduate research work, so I am stealing time from where ever I can get and the result is delayed blog entry. But from now onward I will try to be regular and will post weekly updates. So with that said, finally I got some time to jot down my progress for the first week and experience of this adventurous journey.

My first milestone is all about adding custom pseudo random height-map generator to PySoy. Well this would be a beginning for creating a terrain editor but for now I just want to make sure that a playground for procedural landscape building can be set up. So for this, I need to implement a basic Simplex Noise generator for two dimensional surface which will give us our elevation data.

So the first step was to fix the landscape_example which is the only example demonstrating the API calls for Landscape and Heigtmap. So after a couple of days of extensive testing and understanding the code flow, I finally found that the Landscape class which is inherited from Scene class are having mutex conflict. The render function from Scene class which calls the render_extra function from Landscape class are having a mutex conflict on the account for having same name for the mutex variable. Apparently the mutex was defined publicly and the Landscape class was not able to get a lock while updating the landscape.

And here comes my first commit, though I just solved a tiny bug but it taught me the real work-flow of the above two classes. Unfortunately the landscape example was now working but not as expected, there was no landscape in fact. Well later I came to know that a code push from another student in the Scene class, created a minor graphics anomaly which I solved after some trail and error.

Voila! The landscape example is now working perfectly fine. And here is a screen shot.
So now I just have to start working on the noise methods for automated heightmap generation. I will cover the later half of the week in my next blog entry. So keep reading my blog to know more about my progress.

Saturday, 6 June 2015

Got Selected for Google Summer of Code(GSoC) 2015


It is a bit late for the news, but my proposal "Terrain Engine for Generating Procedural Terrains" got selected by Copyleft Games in GSoC'15. It all started back in February 2015 when I was looking for a nice organization which can get me engaged in computer graphics and game development. Apparently Copyleft Games was the only organization which was involved in this and of course the C and Python programming language tags were one of the main attractions.

About GSoC:
It is a global internship opportunity for students that offers stipends to write code for FOSS projects. Through GSOC, accepted student applicants are paired with mentors from the organization, thus gaining exposure to real-world software development scenarios and other opportunities. In turn, the participating projects are able to more easily identify and bring in new developers.

About organization:
Copyleft Games is building a 3D cloud based game engine which will eliminate the hassle of downloading and installing games. It will also save a lot of memory and processing power of consoles and handhelds. Along with this, it will also promote the culture of multiplayer social gaming with its network libraries.  



About the project:
My main aim is to integrate an efficient terrain engine that will produce nice procedural terrains whenever needed. This will also call for a lot of optimization with level of details technique and polygon count reduction. Another important aspect of the project is texture mapping over the generated terrain. A terrain would not look complete with just a monotonous material over it. With just the right keywords, we can just change the type of terrain from hilly to plains, from mountainous to plateau, from forests to desert. This magic will be done by controlled pseudo random generators and terrain specific texture mapping and blending.

After all of this is done, the final stage of project will include some procedural tree generation. Well this would be a hard nut to crack, just reading the theoretical part of procedural tree generation will give you nightmares. Although I am quite excited to reach to that state, but still it is a long way to go.

About me:
I am an open source enthusiast and like developing 3D simulations and games. This is the first time when I am participating in GSoC and sadly the last time as I will be graduating within the next few months with no scope of higher studies for now. But hopefully I will continue my love for FOSS and keep contributing, or maybe mentor some of the projects in future.