Getting started with SunBurn – part 1
Today I really dug in with Synapse Gaming’s SunBurn lighting/rendering engine for XNA Game Studio and I’m really happy with this product. At first I was afraid that this was one of those packages that required a lot of special code and would wind up with your game engine being highly dependent on and structured around their framework. Thankfully this system is actually really minimal in terms of what you have to do, yet incredibly powerful in its results.
That said I’m not a big fan of their educational material, in terms of getting started. It’s all fantastic for showing the capabilities or for programmers who are good at dissecting code, but I’ve always preferred a “build up” approach that shows how to start from scratch and learn the technology and that’s exactly what I’m going to do here. So without further introduction, let’s get to it.
Let me start by saying that I will be using SunBurn 1.2.4 as that’s the latest version I have installed right now, but since I’m using the forward rendering it should be compatible with older versions as well. I’ll also likely upgrade as time goes on (I believe 1.2.5 is out now), but I don’t anticipate any issues.
Also, make sure you are all installed and ready to go. Use the New Project window in Visual Studio to create one of the SunBurn project templates. Make sure it builds and runs, and that you can see the pretty pictures. Once you’ve done that, delete that project and let’s get to work.
First create a new Windows game project with XNA Game Studio 3.1. Once created we need to add a reference to the game project. Right click on the project and hit Add Reference. Scroll down to SynapseGaming-SunBurn-{Version} where {Version} is whatever version you have installed. For me that’s Community but it might be different for you.
Next let’s gut the Game1 class. We want to pretty much strip out anything that isn’t of use to us to keep things nice and clean. Here’s what I gutted mine all the way down to:
public class Game1 : Game
{
private readonly GraphicsDeviceManager graphics;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void LoadContent()
{
}
protected override void UnloadContent()
{
}
protected override void Draw(GameTime gameTime)
{
base.Draw(gameTime);
}
}
That’s all you need to get started for this tutorial. Now let’s start adding in the basic SunBurn system. First add these fields to your Game1 class:
private readonly LightingSystemManager lightingSystemManager; private readonly RenderManager renderManager; private readonly SceneState sceneState; private readonly SceneEnvironment environment; private Matrix view, projection;
The LightingSystemManager and RenderManager are the core of the system. Most of your interface will be through the RenderManager but the LightingSystemManager is required for anything else to work. The SceneState provides data to the lighting system (as well as you, if you want to use it) and the SceneEnvironment sets up various parameters for things like bloom and fog. Lastly we have a couple matrices representing our camera’s view and projection matrices.
Next let’s update our constructor a bit. We need to create our GraphicsDeviceManager with a few specific property values as well as create our SunBurn system.
public Game1()
{
graphics = new GraphicsDeviceManager(this)
{
// Minimum requirements for dynamic shadows
// (if disabling shadows these can be dropped to PS_2_0/VS_2_0).
MinimumPixelShaderProfile = ShaderProfile.PS_3_0,
MinimumVertexShaderProfile = ShaderProfile.VS_3_0,
// Used for advanced edge cleanup.
PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8
};
Content.RootDirectory = "Content";
// Required for lighting system.
Components.Add(new SplashScreenGameComponent(this, graphics));
// Create the lighting system.
lightingSystemManager = new LightingSystemManager(Services);
renderManager = new RenderManager(graphics);
sceneState = new SceneState();
environment = new SceneEnvironment();
}
You’ll also note we create and add a SplashScreenGameComponent to the game. This is part of SunBurn and is required for the game to run.
Next we can move to our LoadContent method where for now we’ll just create our matrices:
protected override void LoadContent()
{
view = Matrix.CreateLookAt(
Vector3.Zero,
Vector3.Forward,
Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.PiOver2,
GraphicsDevice.Viewport.AspectRatio,
.1f,
1000f);
}
Next we make sure to unload our system during UnloadContent:
protected override void UnloadContent()
{
renderManager.Unload();
lightingSystemManager.Unload();
}
And finally we implement our Draw method to use our SunBurn rendering:
protected override void Draw(GameTime gameTime)
{
// Check to see if the splash screen is finished.
if (!SplashScreenGameComponent.DisplayComplete)
{
base.Draw(gameTime);
return;
}
sceneState.BeginFrameRendering(
view,
projection,
gameTime,
environment);
renderManager.BeginFrameRendering(sceneState);
renderManager.Render();
renderManager.EndFrameRendering();
sceneState.EndFrameRendering();
base.Draw(gameTime);
}
The first thing we do is make sure our splash screen is done displaying. If it’s not done, we call down to base.Draw to have the game draw our components and return out of the method. Once it is done, you see that we call into our SceneState to begin drawing the frame, passing in our camera matrices, the GameTime, and the SceneEnvironment object we created. Next we tell our RenderManager to begin rendering using that SceneState, followed by actually rendering the scene and then ending the frame.
And that’s it! Hit F5 and you should get a wonderful little grey box. It’s grey because the default fog color is grey and since there’s nothing else in the scene, that’s what you’re seeing. We’re going to stop here now that you have a basic SunBurn skeleton set up. In the next part, we’ll load in a model for drawing.
Download: BasicSunBurn_01.zip
Possibly Related Posts
(Automatically Generated)Extending SunBurn with physics
Getting started with SunBurn – part 3
Split screen in SunBurn
Getting started with SunBurn – part 2
Catching Exceptions on Xbox 360

Looks and sounds pretty cool just wish they had a free demo version I could check out.
FYI: This part of the tutorial works with the Sunburn Framework.