Fog, shaders and 3D model scripting

Work on the new 3D model rendering is progressing at a good pace. It is turning out to also involve a lot of work on Doomsday Script improvements. Notably, this is now entering the territory of XG 2.0, where Doomsday Script bindings are added for accessing game world objects.

One of the recent scripting improvements was Process::scriptCall(): a way for native C++ code to conveniently call Doomsday Script functions. This utility takes care of converting common argument data types from C++ to the Doomsday Script equivalents. This is used in the model renderer for callbacks that get called when a model is first taken into use by an object and when the object receives damage. The model may then change its appearance as a reaction. In the planned XG 2.0, all the game world objects will be available for scripting in a similar manner.

The model renderer is now smart enough to handle multiple shaders and a large number of textures. The net.dengine.client.renderer package defines a couple of generic shaders for different purposes. The shaders declare a number of variables that can then be manipulated via scripts. It will also be possible for model packages to define additional shaders, for truly custom visual effects (this may actually already work; I haven’t tried it out).

Since the limit on the amount of model textures was lifted, models are now free to define additional texture/skin variants (called “materials”). For instance, a model could use a secondary material when it gets frozen. The materials can still share texture maps, so only one instance of each texture is kept. Internally, Doomsday collects all the textures of a model onto an atlas. This will then allow drawing the entire model efficiently using a single texture.

The new model shaders now support fog that matches the fog seen on world surfaces. This was a bit more work than one might expect because elsewhere the fog is still being drawn using the old OpenGL 1 fixed-function pipeline. Going forward, this kind of things will be calculated manually in shaders for all surfaces, not just models.

I still have a bunch of things on my to-do list regarding 3D models. For example, there are more scripting related improvements (such as triggering animations via scripts), providing functions for calculating which direction damage was received from, mipmapping, and cube map textures. This is now entering more of a late fine-tuning phase, though, so I’m thinking about spending some time on other topics, also.