Thursday, February 16, 2012

Time to learn and teach again

I am on a mini break right now. I'm testing and optimizing the engine to get it ready for heavy duty lifting so I'm not adding explicit new features for about a week. I optimized it down to 14 / 2.4 ms (two key values in milliseconds, the lower the better). Found an experimental way to make non-animated trees have zero impact on scrolling speed.

I also continued my experiments with making the engine do stuff it was no designed for. I'll talk about that soon. I am also preparing to bring back scheduling. Once the main scheduler is back, all tasks should be re-enabled one by one in a fairly fast succession. The target is to get the game at comparable levels to its 2D version by (the end of) March.

I am preparing to bring back the LL3DLGLD series, this time with the subject of shaders and more didactic than ever!

I also did some research in getting the game to look more modern. Increasing the poly count is out of the question, so I though I should investigate some effects. Here is bump mapping:

The bump map was produced by grayscaling the texture and converting it to a normal map without the actual geometry of the object involved, so it is far from ideal, but the result is not that bad. Here is parallax mapping:

I like bump mapping result better, especially since parallax mapping is darker, but it gives good results on closeup view:

The only problem is that using these effects makes everything look dark. I was showing you the light side of the object, but here is the dark side:

Unacceptable for an outside scene. After a lot of investigation I found the cause for this: Irrlicht is limited to two lights when using these effects. And I can't figure out a way to create and outside scene lighting only with two lights. 

Before I continue, let me show you another bump mapping sample, this time with a normal map created based on geometry:

Not perfect, the little circular bumps on top being particularly bad. Anyway, I only spent 5 minutes creating this map and it works as a proof of concept.

I also discovered this effect:

This effect accentuates the actual polygon structure of the object, but unlike flat shading, the margins of polygons are rounded and the shading is made to be uniform on each individual face. Not very useful, but cute!

So what can we do about the two lights limitation? I think the only solution is to take some third party shaders and use them. I found some but they don't seem to work for me. Probably because I don't know a thing about shaders.

I probably won't be able to maximize the potential of the engine without using shaders eventually, so I guess the path of least resistance is to learn and master shaders.

So if you are interested in learning shaders, keep an eye out for the continuation of the series!


  1. Hey man, you wanna build some MUSCLE MAN?!
    Srsly why you no answer my mail?

    1. What muscle?

      Now you are being just random.

      Please be patient, I don't hang around all day just checking my inbox.

  2. Very common mistakes in cg that makes everything unrealistic is lack of atmosphere fog, and SKY lightning (it must be light blue ambient lightning).

  3. If you decide to "learn" Shaders (which you should) they will help you alot, for instance you could use them to help with your terrain slicing - instead of rebuilding chunks when changing the slicing layer you can just discard the fragments higher than a certain point by passing it in as a uniform thus allowing your chunks (assuming your using a chunk system for terrain) to be taller than one block, which means a reduction in draw calls. This will be a huge boost to fps and is something I do on my own project.

    1. Would something like this be possible with shader model 1/2?

      PS: Why the quotation marks around "learn".

    2. 'Cause no one can really learn shaders, they are a mystery to all :). And it should be possible in sm1/2.

      If you do try it be aware that you'd have to have a secondary buffer so that would "cap" the terrain slice so that you cant see through the discarded fragments. This buffer would be a lot quicker to update though as it only needs to contain the tops of the cubes at the current slice. And vs the reduction in draw calls I believe it is well worth the pain.

    3. After I get the hang of shaders I might try that technique out of curiosity at least.

      But anyway, terrain draw calls are negligible when compared to item draw calls. I spent zero time optimizing terrain, but inordinate amount of time optimizing items.