Smooth darkness

Smooth lighting

I couldn’t resist the urge to implement the so-called smooth lighting which is also used by other voxel worlds. Basically it is an interpolation of the lighting values that gets received by a vertex. At first, I implemented some very slow naive algorithm, but I soon discovered the splendid article on Ambient Occlusion from 0fps. It also explains how to correctly interpolate your lighting values. The added benefit is that you get ambient occlusion for free. It looks really nice, and realistic in a scary way.

 

Introducing… the darkness

It is a dark place out there, especially at night. I’ve made some huge progress on the engine the past few weeks. I threw away my threading code and started focusing on getting some rendering features working. Instead of using threads, I currently just use a work queue where maximum one task is executed per frame. After some clean ups I will identify the critical sections and create a more robust threading/worker system. But for now, it works well enough apart from some hiccups.

While implementing the lighting code, It took me some effort to get the flood fill algorithm working across chunks. The problem with chunks is that you have to think twice, because there are a lot more (literally) edge cases :-)

Some scenery

Yes, I’m still working on this. Some screenshot of the latest version of the terrain generation:

I’m planning to port the whole thing to Javascript. I’m not sure which path I will take to accomplish that, but I think that will be the easiest way for most people to enjoy this game. But before I can do that, I have to clean up my code. There are still parts which I don’t fully understand. And Java is a language which allows me to easily refactor stuff.

The advantage of having periods where you don’t touch your code for a long time is that you will get fresh insights on it. The downside is that it takes more time to pick up where you left. I am quite happy with my terrain generator, but I think it lacks some pretty trees…

Having fun with Emscripten

Recently, I discovered a toolkit called Emscripten which basically allows you to compile your C and C++ code to JavaScript. I thought that would be impossible or at least very slow. But I was wrong. That compiled code is fast! It can run near native speeds if optimised well. It supports SDL and OpenGL ES out of the box, and they demonstrate this with a lot of included examples.

This made me think… do I have some C++ SDL game lying around ready to convert? Yes I have. Oemfoeland 5 is a perfect fit for this, and for the past few weeks I spent my free time on converting it to JavaScript. I had to do a lot of refactoring though, because I have a lot of nested mainloops. You are not allowed to call SDL_delay, and you have to organise your event loops such that it can be called by JavaScript asynchronously. A lot of swears later, you can see the result here: Play Oemfoeland 5 in your browser!!!

Please let me know if this works for you. It probably still has some small bugs, but the basics should work. I also ported the complete Level Editor. I still have to find a way to allow saving your own levels. It would be awesome to be able to share your own designs and play levels from other people. Suggestions on this part are also appreciated.

Have fun playing Oemfoeland 5!

Terrain generation

To generate the terrains of Oemfoeland, I use Simplex noise. A noise function gives always the same result for a given set of coordinates. You can do a lot of interesting things with this noise. With some tweaking on the numbers, you get landscapes like these:

These landscapes are very promising, I lost some time myself exploring this endless world. It’s very addicting! It’s an infinite sea with islands, coasts, bays, grasslands and mountains. Now it’s time to add some real content and gameplay. The next big thing on my list is physics. Now you just fly through the world without any collision detection or gravity.

Revision 2011

I secretly submitted the demo Voxeland (a non-interactive version of Oemfoeland) as a PC demo competition entry with some nice music at Revision 2011. It currently only works on Windows, sorry. (Mac and Linux availability are for my next showcase.)

You can press G anytime to stop the camera. You can navigate the infinite world yourself by using the keys W, S, A, D, Space and C. You can also place and destroy blocks by clicking your right and left mouse buttons.

Download Voxeland (28 MB)

Have fun!

Chunk management and transparency

It has been a long time since I last updated this blog. This is because I didn’t make any progress for some months. Some problems that were difficult to solve and transparency bugs stole a great deal of my motivation.

Transparency is a real bitch when you are developing a 3D scene. When looking through some transparent blocks, half of my chunks were not rendered at all! This week, a colleague pointed out that you have to render all your transparent objects at the end. You also have to sort them from far to near and render them in this order. I tried the first remedy and yes, it worked! Sorting, on the other hand is more difficult and only remedies the fact that you cannot see some other transparent objects. I will solve this issue later.

Another motivation killer was the fact that I didn’t like the performance of my virtual world. I have some separate thread that loads chunks into a VBO in a queued fashion but it gives me huge performance hiccups. Another performance eater was the visibility optimizer. What it does is this: it removes all faces that are facing a solid object, as you cannot see them anyway. Every time I loaded a chunk from disk, I recalculated those extra data. To solve this performance hit, I just save an extra file containing the visible faces with each chunk. The result was very noticeable, but I still have the VBO construction spikes.

By the way, I still didn’t had time for creating my own textures. I think that I first want the engine to be stable enough before I can begin to think about fancy stuff like this.