dev in the making

game development, maya and code by brainzizi

Posts Tagged ‘Abandoned

Abandoned – Shadow mapping

with 2 comments

I always wanted to implement a shadow mapping technique, ever since my first big game project called Black Sun. Black Sun was going to be a space-simulation (similar to the X series or more like Freelancer), so a lot of open spaces were involved. The most logical shadowing technique to implement in that sort of game was stencil shadows (to me than). Turns out that was a bit too complicated for my skills then (and now). I kept reading about shadow mapping and how easy was to implement it, but I just ignored that then.

Now I managed to implement my first shadow mapping technique. The official name of the procedure I implemented would be Perspective Shadow Mapping (PSM) with Percentage Closer Filter (PCF) and a screen image Gaussian Blur. The scene setup is rather simple. One directional light and the only one that casts shadows. Large ground terrain (Scale about 200 x 200 x 40) with a few models on top (Scale about 1 x 2 x 1 or smaller). The procedure goes a bit like this:

1) Render a depth map of the scene from the lights position.

This sounds very simple but is a key difference in most shadow mapping techniques. The shadow map largely depends on the type of camera you’re using to render the depth map from the light’s view. Depending on the type of projection the camera can be orthographic or perspective. Based on the amount of area it captures it can be trapezoidal, or just plain “capture all”. A lot of optimizing can be done here with the projection settings, field of view settings and the distance from the camera to your focus point. The key thing you’re looking for is depth map precision. If the focus point is too far from your camera’s position, you’ll use only a small part of the limited 32bit precision (or 64bit if your GPU supports 64bit render targets).

2) Render the depth map from your normal camera.

Not a lot you can do for optimization here.

3) Check if the distance to the light is smaller than the depth value for that pixel in the first step. If it is than light that pixel.

Here is where the PCF filter is implemented. PCF means that you take multiple depth samples from the light’s depth map, and average them out. Based on the number of samples the PCF filter can be 3×3, 5×5, 7×7, and based on the sample offsets it can be a grid PCF, rotated PCF or an irregular PCF. I used an irregular 3×3 PCF, which gave me the best results. Do be careful when comparing the depth values that they’re in the same range. Always scale down the distance with your FarClip (or FarClip – NearClip if your near clip is big enough). The reason why I used PCF 3×3 is because you can use Pixel Shader version 2.0 to implement it, while 5×5 or even 4×4 doesn’t fit in a PS2.0 ( hate the 64 instruction limit ). Or at least I didn’t manage to put them in 64 instructions.

4) Take only the lighting texture and blur it by some factor.

And you’re done with the light!

5) Render the normal scene from your normal camera and apply the blurred lighting texture on top of that.

You can optimize the algorithm in many ways. I found out that increasing the shadow depth resolution is costly, and so is blurring a 1024 x 768 texture using Gaussian blur. So I render the lighting map at half size, blur that and resize is back to 1024 x 768 giving it more blur. Also I tried to avoid complicated frustum math, so I just used a PSM with 90 FOV. More on the details and the specific shaders in the next post. Also I’m not at home now, so screen shots a bit later.

Written by brainzizizi

09.07.2009 at 15:42

Posted in xna

Tagged with , , ,

Abandoned – Renderer screenshot batch

leave a comment »

I promised screenshots so here they are:

My game is certainly not the next Far Cry (not because I don’t want to, but because I can’t make that kind of graphics). But it’s gonna run on shader models 2.0, on anything that has a processor and windows. And it’s gonna look “nice”. By “nice” I mean old-school nice. I really want to sell a compelling story line. More on that next time.

Written by brainzizizi

09.01.2009 at 15:11

Posted in xna

Tagged with , , ,

Abandoned – The renderer

leave a comment »

The first couple of screenshots I posted here were done on a deffered renderer. The deffered renderer makes heavy use of multirender targets and doesn’t support hardware antialiasing as well as some transparency issues and what not. I wasn’t happy with it initially because it does cost a lot to initially implement it, but I was hoping to steady out the fps and keep them constant. Everything was ok ’till I didn’t try to implement shadow mapping and shadow map antialiasing. I just coudn’t keep the fps up so I switched to a forward renderer.

Shadow mapping was a breeze, I have like 3 passes all in all. One for shadow mapping, one for point lights and one for combining that and texturing. In between that all there some light texture blurring. Performance is excellent and I’m sticking to this one. Only problem is doing 3 passes for every geometry and the limit in the number of pixel point lights if you’re doing shader version 2.0 per shader. But through some light optimizations and vertex light shading things can turn out pretty well as I’m going to show in a couple of screenshots. I’ll post them later today.

Written by brainzizizi

09.01.2009 at 10:15

Posted in xna

Tagged with , ,

Abandoned – Terrain and lights

leave a comment »

Not yet done, just uploading a few pics for my friend to see, so I thought I’d share.

Written by brainzizizi

08.28.2009 at 15:09

Posted in xna

Tagged with ,

Abandoned: Terrain 3 and Skydome

leave a comment »

The diffuse shader is done on the terrain, and I have a system for the texturing. You can now put patches of grass and asphalt anywhere on the map. The amount of grass or asphalt texture on that point is determined by a texture lookup to a texture map which kinda looks like this:

texture_map

The green pixel determine where the grass pixel are going to be, and the blue ones where the asphalt is going to be. I also passed the grass and the asphalt textures along with their detail textures to the shader, but after drawing that the framerate fell to about 50. So I removed the grass and asphalt detail textures and made them use the normal ground detail, and the framerate rose to 100 again. The terrain diffuse system looks kinda weird at this point because there’s no shadowing so surfaces get lit irregularly, and the skydome is finished. No that’s not atmospheric scattering on the screenshots, I just have a DayColor and NightColor and lerp between those 2 with the sun y position. This looks almost as good at atmospheric scattering and is like 10 times faster. Enjoy the screenshots!

Written by brainzizizi

08.21.2009 at 08:31

Posted in xna

Tagged with , , , , , ,

Abandoned: Terrain 2

leave a comment »

I had to rewrite the terrain all over again. Twice. The inability to draw mountains was hanging over me like an axe, and this morning it hit me hard. I had to have mountains!

First I was following this great article from Catalin Zima here: http://www.catalinzima.com/?page_id=85, and got the whole terrain rendering from a heightmap on the GPU. Nice. But one drawback to that. It required pixel shaders 3.0. And my game isn’t going to be the next Far Cry, in fact, I’d probably use shaders 3.0 just for the terrain. So as I was free from one axe, another started hanging over my head.

So now I’m using modeled terrains and no axe yet. This works better for lightning and artists (me). I’d post some new pics but I’m too lazy. Tommorow!

I just hope your day was productive as mine was!

Written by brainzizizi

08.19.2009 at 16:42

Posted in xna

Tagged with , , ,

Abandoned: Terrain

leave a comment »

I’m building a little game called Abandoned, and I’ve just taken the first step and built the terrain. I used Shawn’s excellent article about detail textures found here. It’s just a simple terrain, but the colors and the fog settings have a huge impact of the atmosphere in the game. Even though it’s flat, I’ve built the vertices and indices as a little grid, maybe I decide later to have a heightmap or something. I’ve encountered one problem so far, and that’s poor texture quality. Then I remembered something about mipmaps and turned on their generation on the content pipeline options, and the problem disappeared. The result:

I wish to share my terrain generation function that I’ve been using for a while now (I probably stole it from somewhere, I just can’t remember where). It’s good for heightmaps and flat terrain alike. The size is an int because its the number of rows and columns, size of CellSize in the terrain grid.

void Build(int Size, float CellSize)
{
Debug.WriteLine(“Building ground vertices and indices. Size: ” + Size + “, CellSize: ” + CellSize + “.”);
vertices = new VertexPositionTexture[(Size + 1) * (Size + 1)];
indices = new int[Size * Size * 6];
for (int i = 0; i < Size + 1; i++) { for (int j = 0; j < Size + 1; j++) { VertexPositionTexture vert = new VertexPositionTexture(); vert.Position = new Vector3((i - Size / 2.0f) * CellSize, 0, (j - Size / 2.0f) * CellSize); vert.TextureCoordinate = new Vector2((float)i / Size, (float)j / Size); vertices[i * (Size + 1) + j] = vert; } } for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { indices[6 * (i * Size + j)] = (i * (Size + 1) + j); indices[6 * (i * Size + j) + 1] = (i * (Size + 1) + j + 1); indices[6 * (i * Size + j) + 2] = ((i + 1) * (Size + 1) + j + 1); indices[6 * (i * Size + j) + 3] = (i * (Size + 1) + j); indices[6 * (i * Size + j) + 4] = ((i + 1) * (Size + 1) + j + 1); indices[6 * (i * Size + j) + 5] = ((i + 1) * (Size + 1) + j); } } vb = new VertexBuffer(GraphicsDevice, (Size + 1) * (Size + 1) * VertexPositionTexture.SizeInBytes, BufferUsage.None); ib = new IndexBuffer(GraphicsDevice, 6 * Size * Size * sizeof(int), BufferUsage.None, IndexElementSize.ThirtyTwoBits); vb.SetData(vertices); ib.SetData(indices); Debug.WriteLine("Finished building ground vertices and indices.");} [/sourcecode]

Written by brainzizizi

08.18.2009 at 10:41

Posted in xna

Tagged with , , , ,