While surfing the DarkSpore forum, I came across a recent post by MaxisDave, one of the three graphics engineers on DarkSpore. He took a little time to share with us the rendering behind the game – specifically the lighting elements that will make up our battlefield on the various planets. So take it away, Dave:
Hi,
My name is David but folks at Maxis call me “DLS”. I’m the lead engineer on Darkspore and one of three graphics engineers on the project (Hi Alec and Ryan!).I thought you guys might like a little tour of the rendering (specifically the lighting). Darkspore uses something called a “deferred renderer” which is fairly new and very different from Spore, but becoming much more common in games.
I’d like to try to explain a little bit about how our deferred renderer works in a way that (hopefully) everyone can understand. In the process, I’d also like to show you some of how we draw the environment in Darkspore. All the images you will see are taken from a running debug build of the game (on a Friday night before I went home for the weekend – because I’m that dedicated ). Ready?
Let’s have a look at one of our environments, Zelem’s Nexus, in our editor. This is the enviornment that we have been showing in demos (so far), so you might have caught a glimpse of a little bit of it already:
But not like this! This is a bird’s eye view of the start of the level. You will never see this in a game, but it is a handy view for me to show you some lights. So, let’s look at it with the debug light volumes turned on:
All of those wire balls are “point lights” – if you are not familiar with the term, you can think of them as light bulbs that are represented each by a single point in space and a sphere (the area they affect). They are only one of the types of lights we use. Our other local lights are spot lights and line lights, and we also have something called global lights, but let’s keep things simple!
Now, let’s have a look at the green light at the top of the energy bridge.
See that green light on the ground that seems to be coming from the energy bridge? That’s from the light that I circled in the bird’s eye view – a light that our artists placed. Our artists can place hundreds of these in a level to add subtle and dramatic lighting. Now, let’s see how that light contributes to our scene:
This is screen shot of our diffuse light contribution. Think of it as a picture of just the light without anything else (without any of the objects – kind of like a light “skin”). You can see the light illuminating the ground. The light seems brighter here than it does above because the diffuse light is “modulated” (multiplied) by the color of the objects above (which are dark and bring the lights apparent contribution down).
There is also a different type of light – specular light. Let’s have a look at that:
Here is a picture of just the specular light contribution. As you can see, only shiny areas that reflect the light are visible here. This type of light is added to the scene. Now, let’s have a look at how the lighting works. First, we need something called, “normals”. So let’s have a look at those:
Colorful, like candy – eh?
Now, this is a little math-y. These guys are three component vectors (x,y,z) pointing perpendicular to the each pixel on the surface of the objects you see.
Think of it as a little arrow pointing away from the surface that bends back and forth with the roughness of the surface.
Since it would be hard to see the hundreds of thousands of arrows, we draw them as a color where red is x, green is y and blue is z. So, for example, where you see red, the arrows are pointing along positive x.
Ok, I’ve got one more thing to show you, and then we’ll talk about how the light is calculated using these funny normals.
This is called a “depth buffer”. Things that are dark are close to you, and things that are light are far away. We use the depth and screen coordinate of each pixel to find the position of the surface under the pixel in the level. We will need that position for our light calculation.
Ok, let’s talk about how the lighting is calculated using these normals and positions. But first, I must warn you – I’m not an artist. So please forgive my simple diagram:
Ok, now imagine that the long black line is the surface, and the green arrow is the normal (perpendicular to the surface at a point). That other funny black thing that looks like a rocket ship is actually my version of an eyeball. The eyeball is looking down the dark purple arrow towards the base of the normal, which is the point on the surface that we are trying to light. The blue arrow points to the light (that set of yellow lines that resembles a sun), and the light purple arrow represents the bounce from the dark purple arrow as if it were bounced off the surface like a billiard ball.
Got it? Ok – so the closer the blue arrow (pointing to the light) and the green arrow (the normal) are together the brighter the light will be. The closer the light is to the point on the surface, the brighter it will be. Finally, the stronger the light is (say a 100 watt bulb instead of a 40 watt) the brighter it will be. This all goes into the calculation that produced the “diffuse light contribution” picture.
Now, the closer the light purple arrow is to the blue arrow, the more the light is bounced directly back to your eye. Combine that with how “shiny” your surface is, and you have the “specular contribution” image above.
Here’s how shiny the artists made things in Zelem’s Nexus:
The whiter something is here, the shinier it is. Have a look at the “specular contribution” image again, and I bet you can see the relationship.
Ok, here is the image again with the global lights turned off so you can see the diffuse and specular lighting contribution from the local point lights clearly:
At this point you might be asking about that energy bridge. It looks lit doesn’t it? Actually, it is not. It is simply drawn and then glow is added. Here’s the glow buffer before it is blurred and added back to the scene:
You can clearly see the bridge in it, so it is really glowing. That’s what makes it look lit.
You may have noticed that it is missing from many of the screen captures that I showed you before. Since it is technically unlit (or really self-illuminated), it is not affected by the lights and not written into the light buffers.
Well, I think that at least gives you a taste. There are lots of other things going on, like projected lights, lights on effects, shadows, shadow casting lights, animated lights and the list goes on and on, but we have to leave some surprises for you to look forward to.
Thank you for reading this. I hope you enjoyed it!
-dls (aka MaxisDave)