Tuesday, November 8, 2011

Screens of the day 19 - C'mon baby light my fire

I was supposed to finish the option dialog but instead I tried to add some effects to the game to eliminate the blandness.

Currently objects are very bland and uniform as you could see in my last video (3D Engine Preview #1). All objects look the same. Always. If I remove the textures you get the same result as if I was using only ambient shading: an outline filled with one single color. Textures help you make out what the actual shape of the objects is, but it is not enough.

So I tried adding light at first. Using the default point light from Irrlicht I did not get too far:

  • lighting is surprisingly binary: you either have some levels of lighting or your entire object is black. I would like a model where the general visuals of my scene are preserved, but some areas are made slightly more dark or light.
  • the shape of the spot light caused a lot of troubles: object close to the light were extremely bright and shinny, while object far were too dark. There was a sweet spot where lighting looked perfect, but this area was relatively small.
  • even when object were not to bright, they had a small area that was extremely shinny.
So the only good thing I got out of this (except for experience) was working stencil shadows. Unfortunately I have special needs for my game with the large number of objects and all and shadows are a huge performance hog. I can only use shadows if I reduce object count a lot (about 20 times). Otherwise  it is either too slow or the scene refuses to render. An Irrlicht only allows you to add shadows to animated meshes, so I had to create animated dummy scene nodes with a single frame instead of normal nodes for shadows to be visible. To my surprise this did not turn out to be a performance penalty.

Then I tried to "fake" lighting by using some directional lights. These light are a strange beast and the effect is in no way believable, but it is a huge improvement over the blandness of flat shading. The effect is not realistic but more of an artistic choice. I still need to fine-tune the parameters a lot and see if I can fix shadows because directional light broke shadows.

Next I'll try spot lights. But I have a feeling I will get the results that I want using shaders. This raises an interesting issues because DirectX uses HLSL while OpenGL uses GLSL. If I don't create two sets of equivalent shaders I am loosing one of my back ends.

In the following video you can see the the effect, together with a larger assortment of items (some of the items are not textured yet; the better to see the shading):


  1. whoops! i must invert the normals on that shelf... if we ever use that "rustic" model :D

  2. Yes, I tried that but did not manage to fix it. Damn you Blender and your steep learning curve :).