Posted by Roy Triesscheijn on 28th December 2010
Lately I’ve been very interested in ‘the 3D stuff’. And because of this I’ve been reading into Deferred Rendering.
Catalin Zima explaind deferred rendering very nicely, by comparing it to traditional rendering methods:
In the Single-Pass lighting method, each object is rendered, and all lights affecting that object are computer in one shader. [snip]. Since everything is done in a single shader, which has a limited instruction count, this technique is only suitable for a small number of lights [snip]. In some games, which only need a small number of lights, such as an outdoor daytime environment, this may prove to be a good choice. The disadvantages of this technique are the small number of lights, and the fact that shading operations may be wasted on surfaces which will be hidden in the final image.
Another method is the Multi-Pass lighting. Here, for each light, objects which are affected by the light are drawn with the current light’s shader. This causes a very high batch count (number of individual Draw calls), which in the worst case is equal to the number of lights multiplied by the number of objects. The problem of shading hidden surfaces still remains. And some operations are repeated many times each frame, such as vertex transformations.
Deferred Shading approaches the problem in a different manner. First, all objects are rendered without lighting computations. Instead, the objects output a set of attributes for each drawn pixel, such as position, normal, specular intensity, etc. After this, each light is applied on the final image as a 2D post process, using the data written in the previous pass. Because all objects use the same shader (the one which outputs the attributes), the engine management is greatly simplified. We no longed need to sort the scene objects based on the material they use. The number of draw calls is reduced to the number of objects + number of lights. Moreover, lighting calculations will only be done for visible pixels (the ones that make it into the final image).
Catalin has an excellent tutorial on deferred rendering, unfortunately some of the code no longer works, because it was written for XNA2.0.
Fortunately (for you) I’ve converted the entire code base to XNA4.0 as a learning exercise.
The code is a bit shorter now, (especially setting effects is so much easier in XNA4). And thus should be slightly easier to understand. The code includes everything that Catalin’s original source code examples included. The camera can be moved using the keyboard (arrows, or w-a-s-d to move, z and x to zoom) or using the Xbox controller.
The source code can be downloaded here: http://www.roy-t.nl/files/DeferredLightingXNA4.rar
As a little benchmarking tool, I’ve already turned of VSync and FixedTimeStep for you. On my modest machine (AMD Athlon GP9400 Quad Core, 4GB ram, and an AMD HD4850) I could easily render 600 lights at 60fps+. (However this looks ugly). The default settings (103 lights) runs at 380~400 fps.
Here’s a screen-shot how it should look (again by Catalin Zima)

Anyway, have fun with it.
Tags: bump mapping, Deferred Lighting, Deferred Rendering, Deferred Shading, HLSL, Lighting, Normal mapping, Shaders, specular mapping
Posted in Blog, General Coding, General Gamedesign, XNA | 29 Comments »
Posted by Roy Triesscheijn on 20th December 2010
So not too much big going on lately, but a couple of small news-bits might be enough to fill up this post
.
-I’ve dropped the work on my ‘rotating tetris’ idea, I made my gf play the first two prototypes and it seemed just too confusing or too boring once it was dumbed down a bit. Oh well, I’m happy I actually made a prototype first this time.
-In search for something to keep me occupied for a longer time, I’m working on creating a deferred rendering engine for XNA4.0, I’ve find deferred rendering a lot more logical than the normal way of rendering, especially writing lighting shaders seems to be a lot more easy because the required data is a lot more structured. I sometimes wish though that HLSL was an object-oriented language, since a lot of the lighting code for different types of light is duplicate. A nice XNA4 compatible way of getting there is StichUp by Tim Jones, but I don’t think this goes far enough. Anyway for now I don’t want to get a complicated parser project in the way of writing a deferred render engine. Oh btw, to really get me started I began converting Catalin Zima’s excellent deferred rendering tutorial to XNA4.0, I ran into a few small problems (as usual) but luckily I was able to fix this with a little help of Catalin.
On some more fun news, the new XNA Developers Survival Kit (XDSK) II is out. And it includes 3 of my tutorials (MVC in games, Farseer Physics Platformer Tutorial and the Arcbal camera snippet) . Ok I kinda snail-mailed Nelson Hurst for inclusion, but I was very pleased to find out that he actually knew of my tutorials.
Well that’s all for now, I’ll be mostly working on Calculus and the Deferred Rendering Engine the rest of this vacation, oh and celebrating Christmas, new year and my birthday of course!
As usual I will sent you my seasons greetings using a lol cat:

Seasons Greetings!
Tags: Deferred Rendering, lolcat, News, Seaons Greetings, XDSK2, XNA
Posted in Blog, General Coding, General Gamedesign, Personal, XNA | 2 Comments »
Posted by Roy Triesscheijn on 3rd December 2010
I’ve written a new tutorial about MVC in games, and sgtconker.com was so kind as to redact and publish it.
Here’s a small excerpt.
MVC stands for “Model View Controller” and has been an architectural pattern in software engineering for quite some time now. MVC allows decoupling between what ‘the program is supposed to do’ and how this is made visible and controlled.
In MVC the three main responsibilities of the application are handled by three separate parts.
-The model houses the actual business logic. The model is totally decoupled from the controller and view.
-The view observes the information from the model, and if needed request an update of the information. Data from the model is lightly massaged, formatted and then presented.
-The controller controls the application by mapping different kinds of input to public methods available on the model. The model itself always has the final responsibility of doing something with the request made by the controller. In many form-based applications the view and controller are hard to distinguish from each other.
Using MVC will allow you to reuse your complex model in different scenarios. Want to prepare your program for a different kind of input? Just write a new controller. Want to visualize your data in another way, just write a new viewer. In a good application controllers and viewers can even be changed while the application is running.
The tutorial includes a full ‘game’ where the theory is put to practice. You can read the full article here
Tags: Development, Gamedesign, MVC, sample, theory
Posted in Blog, General Coding, XNA | 1 Comment »
Posted by Roy Triesscheijn on 1st December 2010
Once you’ve create a SVN repository you can easily create a TRAC environment. If you followed the previous guide you should be all ready to go!
1.
Create a new SVN repository in “C:\SVN\Test”, see your SVN tool’s documentation (usually you will just execute svnadmin create C:\SVN\TEST” in the command prompt “).
2.
Now in the command prompt (remember to run cmd.exe) type the following:
“tracadmin C:\TRAC\ProjectDir initenv ProjectName sqlite:db/trac.db svn C:\SVN\Test”
Basically this command means the following: “I want tracadmin to do initenv in environment C:\Trac\ProjectDir using database sqlite:db/trac.db (the built in sqlite database) add svn repository C:\SVN\Test”.
Your new environment has now been created!
3.
To server this environment you have to execute the following command:
“tracd –port 8080 C:\TRAC\ProjectDir”
You should now be able to connect to http://127.0.0.1:8080 and see your TRAC environment.
For more security you can also use basic-authentication, this tells TRACD to use an Apache style .htpasswd file. You can see here how to create a .htpasswd file. Once you have this, you run tracd like this:
“tracd –port 8080 –basic-auth=”projectname,C:\Path\To\.htpasswd,” C:\TRAC\ProjectDir” (mind the quotes around the arguments for basic-auth).
You will need an admin user to be able to get admin rights when logged in. For that use this command (username should match the one in the .htpasswd file).
You can now add an admin users to your project like this:
trac-admin C:\TRAC\ProjectDir permission add bob TRAC_ADMIN
Does this seem like an awful lot of work? Don’t worry. I’ve created a program in .NET4.0 that will do almost all this for you! I call it Visual Trac Manager. And you can download it here! I will do a follow up post later on it to reveal some details.
Tags: .Net4.0, SVN, TRAC, Visual Trac Manager
Posted in Blog | 1 Comment »
Posted by Roy Triesscheijn on 1st December 2010
Now there are a lot of howto’s on how to install Edgewall’s TRAC, especially on their own website, but still it took me days to properly install TRAC on Windows. I had numerous nasty Python errors, and finding a SVN (subversion) repository system that worked properly with TRAC was quite a nightmare, because of this I present you this guide.
1.
Before you can install TRAC you have to download and install python from python.org the current version of TRAC (0.12) works with either Python 2.6 or Python 2.7. However there are no SVN bindings for Python 2.7 yet, so in this guide we assume that you’ve installed Python 2.6 in the folder “C:\Python26″.
After you’ve done this you should add the folder “C:\Python26″ and “C:\Python26\Scripts” to the PATH environment variable. If you don’t know how to do that, then please read this guide carefully.
2.
Because TRAC has actually numerous dependencies it’s very hard to install it using the TRAC Windows installer, which unfortunately isn’t aware of any of these dependencies. Luckily there is brilliant program for Python that is called easy-install/setup tools. You can download it from here. Just use the Windows Installer, it should automatically find your python directory.3.
Now we can actually install TRAC. Do this by starting the command prompt (in Windows Vista/7: go to the start menu and type “cmd”, it should appear. In Windows XP go to start, choose run type “cmd” and press OK).
Now in the command prompt type “easy-install TRAC==0.12″. After this is done run “easy-install fcrypt” to install an add-in of the UNIX crypt functionality which is used by the TRAC daemon.
4.
Now we have to install SVN. We need a specific version of SVN that has bindings for TRAC. For this how-to download the subversion installer from alagazam.net. Download the Subversion Windows Installer (Setup-Subversion-1.6.13.msi) and install it.
5.
Now download the Python bindings (svn-win32-1.6.13_py.zip) from alagazam.net. Extract the zip-archive and copy the folders libsvn and svn to “C:\Python26\. Now search both folders for files that start with an underscore (‘_’) and that end with ‘.dll’. Duplicate these files and change their extension to ‘.pyd’.
To elaborate: you should have now have the file ‘_core.dll’ and the file ‘_core.pyd’, etc…
6.
Congratulations, you have now successfully installed TRAC and SVN.
See the next post for tips on creating a TRAC environment, and how to run the TRACD daemon (so people can actually use your TRAC environment). Serving and creating SVN repositories is a bit out of scope, but take a look at the svnadmin create command and at svnserve.
Tags: bugtracking, guide, how-to, python, subversion, SVN, TRAC
Posted in Blog, General Coding, Tips | 1 Comment »