Sports Fiction - 24/04/16 Visual Performance Programming
Greetings all. This development progress log is regarding recent works in improving the performance of Sports Fiction's land generator. I believe this is the first time showing the generator's produce.
In the previous few posts I introduced a number of goals and principles for providing value for players, a variety of game modes to suit different parts of the target audience and states of mind given the context of playing alone or with friends locally or on the internet. I provided a few of my notes relating to research of online social media and its role in video games, and concluded the posts with a brief introduction of competitive game modes and their maps under development.
The current development session was spent focusing on graphics and performance in DirectX 9.0; quite different from the previous session focusing on gameplay.
My main focus for Sports Fiction will always be its gameplay, but it will also be nice to enjoy the game in a decent looking gameworld. To get the game ready for early access, I need to get its map generator's performance up to par to ensure the experience is as lag free as I can make it without sacrificing too much visual quality.
I will start this development log with details of my goals for the graphics and performance of the game. Then I will discuss specific techniques recently tested. Then I will conclude with some examples of the early land generator so far.
Graphics and performance
I would like to provide players with as many rendering options as I can construct for tweaking game's rendering system. I am building the rendering and lighting system for the game to best suit its nature, and to force myself to learn more about rendering.
I am aiming to have this Windows based game work on budget gaming PCs, whilst providing options for more detailed visuals on medium to top level gaming PCs. If the goal was solely to develop the best looking game possible, then I would not spend much time working on gameplay or budget gaming performance.
By focusing on creating a game that can be enjoyed on budget hardware or dated hardware, I will have to compromise on detail and visual quality; however, there are a number of techniques I have developed over a number of years which will ensure the game still looks cool on average systems, and can give any top level PC setup plenty to do if you want to improve the graphics beyond the standard.
It would be silly on my part to put a great deal of work into presenting something without providing sufficient options for you to be able to experience it. A number of options will be made available for you to configure the experience in order for it to function; reducing issues which may cause lag thus making the game unplayable.
Graphics Options
An option screen is being constructed, the graphics section of which is being broken down into two modes; basic and advanced.
Basic Graphic Settings
The basic graphic settings will contain sliders, check boxes and lists which will control how much the engine will focus on gaming performance. On one hand the engine can be set to focus on filling the view with as much detail as possible without affecting the structure of the game, on the other hand the engine can be set to focus on filling the view with as little detail possible, again without affecting the structure of the game because certain gaming entities must not change in appearance.
There is a significant increase in performance when you reduce the amount of visuals on screen. Performance is further improved by reducing the amount of animation and special effects performed on entities which have no interactive attributes or little impact on gameplay.
The challenge in developing this part of the engine comes with determining how simple a scene can be allowed to look. Reducing the visuals too far will make the visuals look out of theme. Visual reduction is significant here because of the goal having this game perform on budget hardware.
Besides the engine priorities, you can also select the resolution of the game in basic mode. It seems you will be able to do this without the game being reset; however the scene will need to be reloaded. In the worst case scenario I will also have to reload the physics simulation due to DBPRO resetting DirectX resources when the display mode is changed. For this reason and for other reasons it seems Sports Fiction will not run in exclusive full-screen mode; only full screen desktop. I never liked playing games in exclusive screen mode anyway so I will not miss it.
Some players will be interested in having much more control over the visuals to best suit their hardware and style of play. For these players an advanced graphics settings component is being developed for the menu screen.
Advanced Graphic Settings
There are a number of sections being developed in the advanced graphics settings component, the names of which have not yet been decided; but I will introduce the types of settings you will find.
General rendering settings include rendering resolution, CPU/GPU usage, multi monitor settings, brightness, contrast, smoothing and saturation.
Other rendering settings being provided will allow you to control how much optional visual content is permitted to be rendered, and how far away such visual content is allowed to be positioned within each rendered frame.
In a previous update I discussed the development of in game sites which determine what content should be loaded according to the player's point of view in the game universe and any nearby player.
Quote: " The standpoint of the player is being used to determine what sounds, images and geometry belong near the player and other nearby players. This is to be performed as they all move through different parts of the worlds. The physics simulation is required to load collision data and interactive entities near the players, while the rendering process is required to load what the local player is likely to be able to see from their current position."
The distance and detail of such entities can be tweaked in the advanced graphics section of the option screen.
You will not be able to adjust the view distance of interactive gaming entities or obstacles but many of the visual effects and detail entities can be compensated for improved performance. You can increase the rendering distances to improve the visual quality if you would like to show off your graphics hardware. This concept will be discussed further in the next section of this development post.
Render Distance Falloff
Render distance falloff is a property I am developing for the engine which handles how detailed the DirectX 9.0 visuals are allowed to be, according to how far away from the player the details are positioned.
Some entity classes have had level of detail programming implemented to reduce the polygon count and draw call count the further away from view such entities are positioned. These entities eventually get taken out of visibility before being removed from memory when no longer required.
As shown in the following screenshot, the stones closest to the first person camera have more definition than the ones further away. The settings used in these Direct X 9 screenshots are for illustration purposes; the levels of detail will be handled differently in the final product, and any Direct X 11 alternative.
At the moment the transition between included and excluded visuals is instantaneous, they do not fade in or out gradually. DBPro provides an instancing system which allows you to duplicate objects without using up a significant amount of additional RAM, but this also means any object fading within a single instancing group are all faded together; the effect of fading out distant objects will require a extra work.
Rocks are not the only entity class which require a different level of detail according to their distance. The terrain is also set up with its own LOD system. Any Blitz terrain object has such LOD features built within its API, any custom terrain has a set of alternative meshes providing different levels of detail.
This is the same for some of the trees in the system, however most large trees currently have just one level of detail at present. In the final product I would like to provide more optional levels of detail, especially for forests and jungles.
Trees are tricky because they are also obstacles; players must be able to hide behind trees without worrying about opponents having their view of the obstacle removed or reduced between them.
Depending on the tree shading system being used, since there are a number of tree rendering techniques and resources by Evolved Software and Gothasoft being used so far, there are a number of ways in which trees can be reduced in detail according to their distance from the player.
As shown in the following screenshot I have illustrated how we can use low poly trees in the scene renderer without losing much quality.
Since Sports Fiction has open world features; to get it to work on budget hardware, low poly trees will be required. I can increase the polygon count used to form trunks and branches as I see fit. I can also increase the amount of leaves shown. Most of these decisions will likely be made after fully testing the gameplay in various sports. Building the rendering system from scratch helps provide enough flexibility to tweak where I see fit.
At some point I will be testing some of Matty's billboard functions to see how I can draw a distant tree on a few polygons, but the rendering performance has been slightly better than expected so far on budget hardware, so this can wait.
Grass has been the primary focus during the last development session. There was never any major grass plugin for DBPro, so I had to build something from the ground up, since placing a million blades of animated grass along a surface in an open world simulation on budget hardware is not going to happen without at least a little organization in Direct X 9.
The grass system consists two rendering techniques, one which is shader based, something I developed last year which I have not yet put into the real game. The pixel grass shaders will be added in after a bit more work on other more crucial areas of the game. The pixel shaders will be more crucial for grass in the distance, and from high altitudes whilst the player is in flight or climbing mountains. I also built a nice pixel shader which renders medium distance and some close up grass effects on flat surfaces.
The second grass technique is 3D mesh based which is what I will discuss in the next section, something I first worked on a few years ago, and once again a few weeks ago to incorporate multiple levels of detail and for streaming the grass into the simulation.
Streaming Grass
There are two main game map classes in Sports Fiction, open and closed. The open maps are used in the main game to represent the surface of a planet or regions in outer space. These are broken down into sections allowing the players to travel from region to region. Closed maps have borders, the players cannot travel to other regions by going past the edge of the map. Closed maps are used to seal off open areas or are used in competitive matches or PvE challenges to provide a more precision in design.
The open maps are so vast that it is not possible to load them all at once, and in some cases it is not possible to store them in raw form locally; for this reason it is necessary to stream content into the simulation, transferring content from storage to be loaded into view. Storing all the blades of grass in standard objects is just not practical because of the amount of disk space it would take up. The streaming process is used to load some of the grass from disk, and calculate the rest of the grass in real time.
It is not necessary for me to make the grass generator perform its job during gameplay, since I can bake the grass entities to a compressed format to be later loaded into action as players move throughout the world. But making the grass generator a real time effect would be beneficial for stability and for reducing the download size of the finished game; the more I can generate in real time, the less I have to pack into install files, the faster the download speeds.
Progress so far
So far the performance of the grass is much better than I expected early on, and looks better than it deserves to look given the amount of work yet to be done. I have reduced grass rendering distance quite a bit, but I expect the pixel shaded grass to come in and improve the look of the terrain in the distance later on. I am confident I can get 40-60 FPS on budget hardware since I am peaking at 45 FPS in an un-optimized engine on below average hardware. Top hardware should produce 200-300 FPS given the same scenes. Building the rendering system from scratch helps provide enough flexibility to tweak the performance where I see fit.
The grass currently consists of 3 types of meshes.
One mesh contains real blades of grass which is to be animated by a vertex shader. This high detail grass object is instanced across the surface of the terrain. I have not yet developed its pixel shader which will be required to make the grass slightly reflective when wet, and somewhat more detailed when zoomed in.
The second mesh represents medium detail. It consists of stretched planes and polygons to be animated much like the leaves on trees.
Third mesh represents low detail, it features the least amount of polygons of the three.
The second and third meshes are not instanced, these are independent entities with their vertices aligned to the surface of the terrain.
Issues so far
• The medium and distant grass polygons have layering issues which cause nearby blades of grass to rub out blades of grass behind them, making grass in the distance look like there are blades of grass floating in mid air. A search for the best transparency mode and ordering settings may lead to the solution when I get around to working on the grass in future
• I need a way to use fewer instancing resources when using the high poly grass in Direct X 9.0
• Editing the vertices in one instance will affect the appearance of all other instances in the same group; for this reason the hi poly grass entities can only be accurately placed on the terrain if they are kept small, which also increases memory usage.
• Dropping distant polygons may interfere with gameplay, particularly in long range combat sports or battles where players or robots hide behind plants.
• Wind effects will be difficult to apply on instanced grass blades since these all share the same shader instance; the wind will blow in the same local direction which will not take into consideration the random rotation of the high poly DX9 grass instances. Wind effects will be a nice supplementary feature for golf, archery and other range sports.
• Terra forming the grass during gameplay is not feasible; this is not a requirement because of grass baking, but would be beneficial if I can come up with a way to terra-form the grass with no lag.
• Calculating grass normals takes roughly 2 to 3 seconds on a terrain which spans about 1KM square. This lag is too long for gameplay, but this is not a major concern because normal calculation is only important for hill and mountain grass; runtime calculation is a bonus rather than a necessity.
• A pixel shader is required for lighting and environmental reflection on the grass blades close to the rendering camera view, not to mention shadow mapping on high level hardware.
• The rendering RAM usage peaks at 600 MB, which is a bit much. I can reduce this by reusing more of the content with instances. This needs to be lowered down to around 250-300 MB because I need the extra RAM for the character animations and preloaded renderer content.
I will post a number of screenshots of me playing around with the system in its infancy.
Next development task
I will now be getting back to work, focusing on the displacement and vector effect functions. These effects are going to be used to generate much of the game's dynamic entity visuals and player constructions. I will post the next development progress update relating to such topics.