We’ll start this post of by creating a very simple Scene manager. This is one of the aspects that I’d like the community to get involved in as there are so many differents ways of managing a Scene. We’ll just be using a simple list of models and rendering each one.
In the “Core” folder of the “ProjectVanquish” project, add a new class called “SceneManager”. Add the following namespaces:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using ProjectVanquish.Cameras;
Create a few variables:
ContentManager content;
GraphicsDevice device;
FreeCamera camera;
IList<Model> models;
This will hold all of our models so we can iterate through them. If we were to create our own Model class, we could then add in things like visibility tests, so we can only render those that are visible.
Create a constructor:
public SceneManager(GraphicsDevice device, ContentManager content)
{
this.content = content;
this.device = device;
camera = new FreeCamera(device, new Vector3(0, 10, 0), Vector3.Zero, device.Viewport.AspectRatio, 0.1f, 1000f);
models = new List<Model>();
}
We now have the start of a simple Scene manager, but we need to be able to add models to it. Add a new method called “AddModel”:
public void AddModel(Model model)
{
models.Add(model);
}
This method will add a Model to our list. We aren’t testing to see whether the list already contains the Model, as this is only a simple Scene manager.
Next, we’ll add the rendering methods:
public void Draw()
{
device.DepthStencilState = DepthStencilState.Default;
device.RasterizerState = RasterizerState.CullCounterClockwise;
device.BlendState = BlendState.Opaque;
foreach (Model model in models)
DrawModel(model, Matrix.Identity, camera);
}
void DrawModel(Model model, Matrix world, FreeCamera camera)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (Effect effect in mesh.Effects)
{
effect.Parameters["World"].SetValue(world);
effect.Parameters["View"].SetValue(camera.View);
effect.Parameters["Projection"].SetValue(camera.Projection);
}
mesh.Draw();
}
}
We have sorted out our Model rendering, but we haven’t updated our Camera. Create a new method called “Update”:
public void Update(GameTime gameTime)
{
camera.Update(gameTime);
}
In this method we call the Cameras “Update” method, which in turn will update the Camera. That’s all for the Scene manager. As I said at the start, it’s a very simplistic approach, but I’ve included it so we can actually start rendering some models.
Go back to the “DeferredRenderer” class, add a new namespace:
using ProjectVanquish.Core;
Now we can declare our new “SceneManager” class:
private SceneManager sceneManager;
In the constructor, we’ll instantiate our new object:
sceneManager = new SceneManager(device, content);
Remember early on in the project when we were creating the skeleton structure of the project? We added a comment into the “Draw” method of the “DeferredRenderer” class. We can now replace this comment with the following:
sceneManager.Draw();
We also added a comment in the “Update” method, so we can also replace that with the following:
sceneManager.Update(gameTime);
Great! We’ve now included our Scene manager in the Deferred engine. But wait! We have an “AddModel” method in the “SceneManager” class, but we won’t be able to access that from our “ProjectVanquishTest” project due to the protection level of the class. This is easy to fix. We’ll create an “AddModel” method in the “DeferredRenderer” class which will call the “SceneManager”s method:
public void AddModel(Model model)
{
sceneManager.AddModel(model);
}
We’ll add a property for the Camera so that the “DeferredRenderer” class can access it:
public FreeCamera Camera
{
get
{
return camera;
}
}
Build the solution to make sure that there are no errors. Head over to the “ProjectVanquishTest” project and open the “Game1″ class. Locate the “LoadContent” method and under the TODO comment, add the following:
renderer.AddModel(Content.Load<Model>("Models/Ground"));
Building the solution will show no errors, but we’ll need to add the “Ground” Model to our “ProjectVanquishTestContent” project. Roy’s source code contains this Model, in the “DeferredLightingContent\Models” folder. You will need 4 files. Firstly, the “Ground.X” file. Then there are 3 JPG files, all starting with “ground_”. Extract these 4 files to your “ProjectVanquishContent\Models” directory. In Visual Studio, right mouse click the “Models” folder in the “ProjectVanquishTestContent” and click “Add” then “Existing Item”. Open up the “Models” folder and click “Ground.x” and then click “Add”.

Once the Model is added to the project, we need to change the “Content Processor” to our “ProjectVanquishContentPipeline.ContentProcessor”. To do this, click the “Ground.x” item and view the “Properties”. The “Content Processor” is the fourth item in the list of properties. Click the drop-down arrow and locate the “ProjectVanquishContentPipeline.ContentProcessor” and click. Expand the “Content Processor” items so you can see all of the items for the processor. Locate “Normal Map Texture” and type in:
ground_normal.jpg
Then, locate “Specular Map Texture” and type in:
ground_specular.jpg
We’ve now configured our Model to use our “Content Processor”. If you build and run this code, you will should see a large black screen, but the Debug textures are now appearing. This is because we have not implementated any lighting.

Well done! In the next part, we’ll look at implementing Directional lighting.