I thought I should release this code, even though it’s still a little warty, because I don’t have time to work on it too much so it might be a while before I get it really
cleaned up, and because I need to release more often to try to
encourage participation.
Download the code here: http://homepages.inf.ed.ac.uk/s0094060/terrain-renderer.tar.gz
The code is a terrain renderer (not generator) [edit: to clarify the code takes a 2D heightfield image as input and as output
provides efficient, renderable 3D terrain.] that implements
optimised, patch-based LOD terrain with detail texture
(though you can choose when you run it to turn LOD on/off,
because the LOD feature still needs work). As it is the terrain
is not bad looking and runs pretty fast.
Take a look at the code and please do add to it and post or send me your additions, changes, comments, advice etc.
It’s released under the LGPL.
The main issues with the code as it is, that people could help to fix, are:
-
Currently TerrainNodePath is a custom class that has a NodePath containing the terrain as a member.
This probably needs to be refactored a bit, I think it would make more sense to have a class TerrainNode that derives from (probably) PandaNode,
and then let the user create one of these nodes and attach it to a NodePath themselves. -
If you say ‘yes’ to both mesh LOD and texture LOD you will notice a horrible change in the colour of the terrain
at the point in the distance where the detail texture stops.
This is because the detail texture is not blended properly
into the terrain and it changes the colour of the terrain, instead of just applying detail to it.
To see the terrain without this ugly bug say ‘no’ to texture LOD.
Need to figure out what the correct blend mode is. This is probably the most important fix that could be made, as
displaying the detail texture across all of the terrain (i.e. texture LOD off) seems to be the biggest performance hit.
- If you say ‘yes’ to mesh LOD you will notice some cracks in the terrain. These cracks appear where a higher resolution patch
joins to a lower resolution patch, and cannot be avoided using the one patch of terrain - one LODNode approach.
To see the terrain without this bug say ‘no’ to mesh LOD.
It looks like Panda3D’s LOD functionality is too simple and generic, and that some more specialised terrain lodding algorithm
is going to need to be implemented for the terrain renderer.
This is a significant task, but it should not be too difficult,
and a potential approach is described well in this article:
http://www.gamasutra.com/features/20000228/ulrich_04.htm
(registration required, but free).
- I haven’t gotten round to programming collision detection for the terrain yet, but it would be good to provide an example of how collisions
with the terrain could be done. A good example would be to prevent
the camera from moving through the terrain and have it slide along the terrain instead.