Monday 4 July 2011

Improved Grass Rendering using a Quad-tree

So nice to finally get back to the blog after being away on holidays for a bit. While Vanuatu is a beautiful place its internet and computer access leaves a lot to be desired. But never the less a break away from the computer to sip cocktails is probably good for me.
I have just had some great success improving the efficiency of my grass rendering. Previously adding 1,000,000 pieces of grass across my 1 square kilometre of terrain would bring the frame rate to its knees, crawling along at barely 30fps. And a clear linear relationship between the frame rate and the number of grass was apparent.
It turns out that my algorithm was very badly CPU bound and although most of the 1,000,000 pieces of grass were not visible at one time, the algorithm to determine grass visibility was just taking forever. Note to self don’t try to do 1,000,000 sphere to view frustum calculations every frame.
So alternatively I created grass patches that represented all of the grass in a 2 meter by 2 meter area. This resulted in approximately 200,000 patches spread across my terrain which each contained a small list of locations and these were added to the quad tree of the terrain.
Using the quad-tree structure to determine visibility removed a lot of the work performed previously in the simple brute force method. Once a grass patch was determined to be visible all of its grass locations were added to a global visible grass list and sent to the shader as previously rendered.
The downside of this method was that I found that it was more noticeable if an entire patch popped in and out of visibility compared to previously where only a couple of pieces here and there popped in and out at any one time.
My solution was to modify the fog colour algorithm and use it to fade out the alpha of the grass the further it got from the viewer. Then once the entire patch is almost completely transparent it is free to pop in and out of visibility without it being noticed by the player.
It proved to be a very effective solution and I think it gives a very nice depth of field effect as well. The extra efficiency allowed me to not only render the 1million pieces of grass at over 100fps but also found that increasing the number of grass no longer had a linear penalty. I now have in excess of 200,000,000 pieces of grass spread across my terrain and still can render on average at about 100fps.

Monday 30 May 2011

PhysX SDK 3.0 released

Nvidia has released the latest version of the PhysX SDK 3.0. For those not familiar with PhysX, it is a physics engine originally developed by Ageia for their range of physics extension cards.
In 2008 Ageia and PhysX were bought by Nvidia and they extended the engine to be able to run on CUDA enabled geForce graphics cards. The idea behind PhysX is that it allows some of the complex Physics calculations of games to be handled by the GPU rather than on the CPU and hence balancing the workload between the two. It is an extremely powerful physics engine and my favourite bit is that it’s absolutely free to download.
This latest release of the SDK is a significant re-write and exposes not only a number of new features but improves how some of the old features perform and also removes some legacy features.
There is improved multi-threading support, improved multi platform support with a unified code base, a reworked vehicle model, completely driverless, and many more features.
If you are looking to include a physics library to your game then I seriously recommend taking a look at the PhysX SDK. I have used the 2.x versions of the SDK in my brainstorm engine previously and I can’t wait to get up and running with 3.0.
Check out the Nvidia developer website for more information: http://developer.nvidia.com/physx-sdk-V30

Thursday 26 May 2011

Interesting Site: d3dcoder.net

d3dcoder.net is one of my favorite game programming sites. It is run by Frank Luna, author of three of my favorite game programming books. If you haven't read them yet then you need to get to Amazon.com or your local bookshop and find a copy as they are definetly worth a read by anyone serious about their DirectX game programming.
I credit Frank's books for helping me make my game engine what it is today, with much of what I learnt from them implemented in my 'Brainstorm' engine.

     













d3dcoder.net is the support site for all three books (soon to be 4 books with the upcoming release of his "Introduction to 3D Programming with DirectX 11") and contains the source code you need to follow along with the book including answers to activites.
There is also a very active forum full of other game programmers who are happy to help with any issues or questions you might have. I hope you check it out and you might see me over there under the screen name 'Brainstorm'

Wednesday 25 May 2011

G’day & Welcome!

I want to welcome and thankyou for finding and reading this my first entry of this new blog. My idea in starting this was to help me document my progress in some of my game programming projects as well as share with the world my ideas, opinions and stories with everything to do with game programming. Most of what you’ll find here is targeted at the single developer, small team, student or hobbyist.
I hope that you find this blog entertaining and educational and that you continue to come back, drop me a line or tell your mates about it.
Until next time, live long and program
The Little Aussie Game Programmer