Tuesday, December 13, 2011

Interim Update - More Detailed Terrain


I thought it was time to introduce a more visually appealing terrain model into Edge. I've been recently using World Machine 2, which is an excellent terrain development application. After learning a few steps I was able to produce the map shown in the video below. I think it makes quite a difference, so thought an interim update was in order. To me the whole point of developing a high performance scene renderer / game engine is to have something great to look at afterwards, if you're going to put maths into motion, it might as well look good.

LOD and rendering performance for a detailed terrain (approx 4x4km), GTS450, 512MB VRam

The scene shows roughly a 4x4km terrain patch which will serve well as an island map and be ideal for the implementation of the sea (you can probably see where the beach and sea will meet). Eventually Edge may branch out into huge terrains, and this is a step in that direction, but for now I prefer to concentrate on implementing localised features.

From video time index 0:52 the higher LOD (Level Of Detail) terrain patch can be seen, morphing seamlessly into the lower LOD patch (I've highlighted the patch so you can see what's going on more clearly). Although the low LOD terrain currently has 16 meters between vertices, it's overlaid with a map containing lighting information for 1 meter intervals, which adds significantly to the scene dynamics and I think is quite effective. The video also shows the high detail transition (1:46) around a very irregular patch. At the end of the video there are 3 stills showing the FPS (top right) looking across the whole map, from mid map and a close up of the ground detail (the video recording software fixes the FPS to 30 while recording, hence the stills).

The next steps are to fill the land with trees, rocks and general vegetation (using improved textures), build a village near the beach area and implement the sea and shadows. The next blogs should show this progress, although maybe not exactly in the order listed here.

Thursday, December 1, 2011

Tech Demo 2 - Trees, Rocks, Grass and Shadows

This demo shows the progress made in filling the landscape with natural objects such as foliage and rocks



2x2km high res texture terrain showing GPU & CPU instancing, shadows and long draw distance.

Looking at the video time index:

0:06 6,000 Low LOD trees and 200 high LOD tree trunks and 200 high LOD leaf canopies are introduced. Turning on the 6,000 low LOD trees gives a performance of approx. 850fps. During early development up to 500,000 trees where tested which gave a performance of 60fps with the large terrain also rendered. This opens up the distinct possibility for effective high detail real time physics simulations once nVidia PhysX is implemented.

0:14 Rocks are rendered (approx 200 over a 200x200m patch) via CPU instancing to allow for collision detection.

0:20 Grass meshes are rendered, approx 2500 over a 140x140m via GPU instancing (no collision detection required). I think there needs to be larger grouped patches of grass, perhaps further apart. Analysis of the top modern engines show a greater degree of local terrain undulation adds greatly to the perceived detail in the scene. At this point the engine is performing well and it's just down to an artistic touch now.

0:46 - 1:04 Shows animated grass and leaf canopies swaying in the wind. This adds slightly to the load on the GPU, but makes for a more dynamic scene. The canopy animation is exaggerated to show the effect.

1:53 An overhead view of the Shadow class ready for implementation, showing high quality shadows tracking with the camera. These shadows have a draw distance of approx 200m as opposed to about the 50m commonly seen, or even the amazing 30m seen in a recently anticipated and well received game engine.

1:56 The video ends with a track back revealing the whole terrain with trees drawn up to the 2km boarder. Many of the most modern engines use fog and / or hills in the case of indie engines, or generally mountains, high rocks or hilly terrain in the case of top quality engines to realistically reduce the draw distance to a few 100m for at most. In some cases the draw distance is increased by the sparse use of alpha blended textures for grass, bushes and tree canopies for example, to reduce the overall render load.

This represents a significant step as it involves quite a few concepts, all of which must be optimised to maintain rendering performance.

The first concept to consider is GPU instancing. Generally when a mesh is rendered the data defining the structure is sent to the graphics card every time it is drawn (a draw call), that is once every frame for each drawn mesh. So if you have 6,000 trees (as shown in this demo), that's 6,000 separate draw calls  per frame. This would have a significant impact on performance.

It is now possible via GPU programming (Shaders) to pass 2 data streams to the GPU. One containing the data for the mesh structure and one containing data on how to repetitively draw the same mesh with various differing properties, such as position, scale, rotation and colour for example. As you can manipulate the mesh in this way, you can also add animation to simulate grass or leaves blowing in the wind, all with a low performance impact. This method is used primarily for tree canopies and grass as other meshes such as characters, projectiles and cameras can realistically pass though these objects (basic collision detection is tested for on the CPU and not normally the GPU - at the moment). Mesh instancing can be particularly tricky to implement as the fault intolerent GPU streams are sensitive. Edge goes a step further an implement a method to actually create GPU instancing from a mesh loaded from the hard drive, again particularly tricking to get working as a re-usable class in a re-useable DLL, something rarely seen in current engines.

Another concept is CPU mesh instancing, as opposed to GPU mesh instancing (described above), CPU mesh instancing involves a source mesh being loaded into memory and then redrawn with differing parameters (scale, position, rotation, textures) in separate draw calls. The advantage here is, as the mesh is processed on the CPU it is exposed to the 3D graphic drivers' collision detection algorithms. It is therefor useful for scene objects such as rock and tree trunks with which characters, projectiles and the camera will interact.

As the camera moves through the scene all these components must be managed with  LOD (Level Of Detail) scene management. This operation is many-fold. Far off objects. such as low LOD trees must be turned off and replaced with higher LOD tree trunks and canopies as the camera approaches them. Tree trunks and rocks must be switched on and grass must be destroyed from out of distance grids to the rear and built in within distance grids to the front, quite a complex set of operations.

The shadows you can see towards the end of the video have been developed and tested, they just need the final implementation and testing in the engine. 

The video ends with a full view of the terrain with far distance trees distributed with a moderate to high density, showing the engine performance even with a large terrain and long draw distance. All these trees are also animated and swaying in the wind.





Monday, November 28, 2011

Intro - Tech Demo Fast Terrains


Welcome to the Edge 3D Engine development project. I decided to start this blog to introduce anyone who was interested in fast 3D rendering concepts to current and new developments in the field. The idea is to build up a set of features that can be used to demonstrate and develop an application or game using the best methods and concepts employed in modern game and rendering engines. The engine is being developed as a C++ DLL, C++ Library and Dot Net DLL which can be imported and used easily. I decided to go down the dot net route also to open the technology up to a greater audience. A demo download will be available once the current phase of testing is complete.

As I enjoy the principles of 3D technology and real time optimised processing I became quite  interested in 3D game technology. I've used and reviewed a lot of 3D game engines and started experimenting in the technology about 3 years ago. About a year ago it became obvious that for indie (Independent) developers, access to fast and powerful engines was an impossibility. For this reason I decided to develop a fast rendering engine and use it as a framework to introduce current and new technology that anyone can use.


2x2km high detailed terrain rendering at approx 1350 fps (nvidia 450GTS - mid range card)


The video above is a basic introduction to the capabilities achieved so far. The initial scene shows a 2x2km landscape without trees, foliage, rocks or shadows, but with high definition ground textures and the blending of sand and grass based on an underlying map. Significant optimisations have been made in the terrain engine as pretty much all modern engines use a chunk system by which the camera is surrounded by 4 to 9 high LOD (Level Of Detail) terrain patches or chunks. Typically each chunk has a resolution of 256x256 and as most modern games use a 2m resolution (Skyrim & Crysis for eg), this represents an area of 225m to 750m of high res terrain around the camera. As the camera moves. LOD chunks behind are replaced with one's of less resolution, and lower resolution chunks in front are replaced with higher ones. This is a tried and tested method and is the subject of ongoing academic and white paper research topics in the pursuit of faster, more detailed systems. This high definition over a large area is not really required and is a legacy of brute force methods developed as GPU efficiency has increased. As each chunk is fixed to a 256x2m resolution, the closely spaced triangles that make up the terrain model are effectively lost to the eye, the further they are from the camera they are.

Looking at the video time index:

0:32 The high resolution ground textures can be seen (later a cliff rock texture will be included for the steeper slopes). 

0:58 The transition in LOD on the hill in front is shown in the wire-frame mode (which defines the polygons of the model), and later the solid textured mode to show the seamless transition. 

1:31 You can see the very smooth transition from the dynamically lit low LOD to the high LOD terrain patch, particularly on the sandy section to the left and middle. A striking terrain undulation is used here (often avoided in modern technology) to show the effect clearly. There is a plan to artificially embed the high LOD shading (of the subtle undulation) in the low LOD terrain model, making this transition almost undetectable and increasing far off detail without any real impact on performance.

This approach uses a new method of a patch traveling with the camera, building detail in steps of 4m instead of 256m. This effective means only one high LOD patch is drawn at any one time, reducing the load on the GPU (Graphic Processing Unit). The scene is rendered in a window (generally slower than full screen mode) @ 1024x768, GPU is GTS450 with no anti aliasing or isotropic filtering. This is particularly significant as the base FPS (frames per second) on modern engines, drawing such a terrain is approx 500 fps on a mid range GPU, the baseline for Edge is 1350 fps, which means more detail can be added before the 30-60fps minimum is hit. (more fps means more details can be added before the engine can't provide an adequate fps performance).

There are alternative methods to implement this, but all the ones I've examined so far are slow as they rely on a bottle neck in current GPU technology. The Edge engine circumvents this.

I will be introducing the various concepts and technologies required for a effective game / scene renderer in this blog, and below is a current status snapshot.

Features that have already been researched an implemented are: 
  • Fast and detailed terrain rendering (with dynamic lighting).
  • Huge terrain support with very far draw distance (demo shows 2km).
  • Fast terrain height determination formula.
  • Dynamic sky with drifting clouds.
  • Very fast GPU based tree and foliage renderer (models can be loaded from HDD).
  • Static Mesh Loading with optional custom shaders.
  • Mesh instancing (reuse one mesh from memory with differing parameters).
  • LOD control for Level of Detail switching.
  • Load custom shaders for 2D & 3D GPU programmed effects.
  • HUD text and sprite elements.
  • Debug output file.
  • Texture loading.
  • Accurate render timer.
  • Direct access to 3D Device for custom coding in C++.
Features that have been researched, tested and are ready for implementation are:
  • Fast GPU shadows.
  • Animation for characters.
Features that have been researched, tested and require some further development are:
  • Water (similar to Crysis, Two Worlds 2 and Skyrim standards).
  • 2D post process filters, such as bloom and depth of field. 
 Features that will be researched an implemented are:
  • Physics (probably nVidia due to the GPU hardware acceleration model).
  • Network support (probably Raknet, the proven industry standard).
  • Pak files to compress and encrypt game assets.
  • Path nodes and path finding functions.
  • Scene editor.
  • Scripting (if in demand and probably Lua script)

This comprehensive list represents all of the components required to make an effective scene renderer or game. I hope you found this interesting and enjoy the details to come, it should get more interesting as the demo scene develops :)