Saturday, November 29, 2008

Entity List, and Lightmaps in Ogre

I'm going to make an effort to update this blog at least once a week, as I believe constant updates are good for showing people what's going on with the project, as a 'history' of the course of development, and also as a way for me to think out loud.

Ok, steady progress on all fronts. A few more bugs fixed/features added, including a much needed entity list (well, tree really):


This is useful because in a large map you can forget where entities are. Clicking on an entity in the list focus you on it, letting you edit its details without finding it in the world. It also faces you in its direction, so if you want to get to it, you just need to press 'forward' until you are as close as you want.

The tree uses CEGUI's Tree class, which required a few workarounds, in particular a patch to the Lua scripting module to support TreeEventArgs (submitted to CEGUI). Taking into account a previous patch to CEGUI, this means we really should start bundling CEGUI, at least until upstream releases a version containing the patches. If anyone can volunteer to help with this on Windows that would be greatly appreciated.

Also, there is progress on the experimental Ogre branch. We now have both the normal ('diffuse') textures combined with the lightmaps, giving us the correct appearance for scenery, pretty much how it looks in Sauerbraten in fact:


The current method for doing this is to generate three sets of texture coordinates, for each of the 6 orientations of a cube (opposing orientations are combined), and storing them in the buffer object. We then blend the lightmap and diffuse textures using appropriate Ogre texture units. This should probably be done using a custom shader, as eihrul explained Sauerbraten does, as the diffuse coordinates are trivial to calculate in 'realtime', in a shader.

In fact writing a custom shader might be unavoidable. As you can see in the screenshot, we have a shadow that looks different, cast by the floating white object in the center of the screen. This is a dynamic shadow generated by Ogre. While it has the same orientation as the lightmap shadows, it combines poorly with them, as the two shadow types combine (that is, by walking into a scenery shadow, you cast a shadow inside that area). The solution is to combine the shadows in a non-linear manner; a 'minimum' operation seems right, so that if either type of shadow is present, or both, you get the same shadow result (of course it isn't that simple, but that's the general idea, I think). It appears that this requires a custom shader, as standard Ogre texture units don't support this sort of thing. This is somewhat regrettable as it means either using Cg or writing separate GLSL and HLSL shaders, both approaches of which have their drawbacks. I'll do some testing to see which is better.

No comments: