dev in the making

game development, maya and code by brainzizi

Offside – My RSS subscriptions

with one comment

When I discovered RSS, it really changed the way I surfed and follow news. Before RSS I used to open up Firefox, (wait half an hour ’till it opens up), and open like 20 websites, (wait half an hour again), and see if there’s anything new. I could follow a maximum of 20 or so web sites. Now using Google Reader I’m following a total of 50 web sites. All of them tied to programming, graphics or game design. So I present to you my RSS list. Hope you find something interesting! I’ve included an OPML file with my subsriptions in you want to easily import all the items at the end of the post.

Aaron Stebner’s WebLog
http://blogs.msdn.com/astebner/rss.xml

Another Early Morning
http://www.anotherearlymorning.com/feed/

Beautiful Pixels
http://feeds.feedburner.com/BeautifulPixels

Blender3d.org: Latest News
http://www.blender.org/feed/

Brian Goldfarb’s Blog
http://blogs.msdn.com/bgold/rss.xml

C0DE517E
http://c0de517e.blogspot.com/feeds/posts/default

Catalin’s XNA Experiments
http://www.catalinzima.com/?feed=rss2

Coding Efficiency
http://www.codingefficiency.com/feed/

Cooking With Code
http://blogs.msdn.com/ashtat/rss.xml

Cornflower Blue
http://blogs.msdn.com/etayrien/rss.xml

Danc’s shared items
http://www.google.com/reader/public/atom/user/04653747362202207327/state/com.google/broadcast

Diary of a Graphics Programmer
http://diaryofagraphicsprogrammer.blogspot.com/feeds/posts/default

Gamasutra Feature Articles
http://feeds.feedburner.com/GamasutraFeatureArticles/

GameDev.Net
http://www.gamedev.net/xml/

GameDevBlog
http://www.gamedevblog.com/atom.xml

Graphics Runner
http://graphicsrunner.blogspot.com/feeds/posts/default

Jesse Liberty – Silverlight Geek
http://feeds.feedburner.com/JesseLiberty-SilverlightGeek

Krishna’s XNA Space
http://cid-cdfded0a2593c8e1.users.api.live.net/Users(-3603463498990630687)/Main?$format=rss20

Legalize Adulthood!
http://legalizeadulthood.wordpress.com/feed/

Let’s Kill Dave!
http://feeds.feedburner.com/LetsKillDave

level of detail
http://www.jshopf.com/blog/?feed=rss2

Lost Garden
http://lostgarden.com/atom.xml

Machaira’s Space
http://cid-c6a0309746469d9e.users.api.live.net/Users(-4134251031648887394)/Main?$format=rss20

Method ~ of ~ failed by Tim Heuer
http://feeds.timheuer.com/timheuer

Michael Klucher’s Blog
http://klucher.com/feed/

Nazeeh’s Little Corner on the Web
http://feeds.feedburner.com/nazspace/kFwA

Nerd Herding – The Care and Feeding of Software Developers …
http://blog.calevans.com/feed/

Nick Gravelyn
http://nickgravelyn.com/feed/

Ozymandias
http://ozymandias.com/feed/

Pandemonium
http://bittermanandy.wordpress.com/feed/

Petri’s space
http://cid-2b7007e9ec2ae37b.users.api.live.net/Users(3130010442293502843)/Main?$format=rss20

Pieter Germishuys
http://www.pieterg.com/blog/syndication.axd?format=rss

RandomChaos
http://xna-uk.net/blogs/randomchaos/rss.aspx

Real-Time Rendering
http://www.realtimerendering.com/blog/feed/

Sharky’s Blog
http://sharky.bluecog.co.nz/?feed=rss2

Shawn Burke’s Blog
http://blogs.msdn.com/sburke/rss.xml

Shawn Hargreaves Blog
http://blogs.msdn.com/shawnhar/rss.xml

Shawn Oster
http://blog.enginefour.com/blog/syndication.axd?format=rss

Silverlight Releases Rss Feed
http://silverlight.codeplex.com/Project/ProjectRss.aspx?ProjectRSSFeed=codeplex%3A%2F%2Frelease%2FSilverlight

Ska Studios
http://skasoftware.wordpress.com/feed/

The Daily WTF: Curious Perversions in Information Technology
http://syndication.thedailywtf.com/TheDailyWtf

The Game Dev Guy
http://gamedevguy.com/blog/?feed=rss2

Virtual Realm
http://feedproxy.google.com/mykre

www.enchantedage.com
http://www.enchantedage.com/rss.xml

xkcd.com
http://xkcd.com/rss.xml

XNA Creators Club – News List
http://public.xna.com/Feeds/CcoFeeds.svc/CmsFeed?group=News%20List&format=rss

XNA Team Blog
http://blogs.msdn.com/xna/rss.xml

XNAinspired
http://xnainspired.com/feed/

Ziggyware.com
http://www.ziggyware.com/news-rss.php

Ziggyware.com XNA Articles
http://www.ziggyware.com/articles.rss.php

OPML file on pastebin: http://pastebin.com/f6c8cc804

OPML file on megaupload: http://www.megaupload.com/?d=4IGSP2AX

Written by brainzizizi

10.12.2009 at 07:49

Posted in private

Tagged with , ,

GameOfLife – Source code

leave a comment »

O hai! Last time I’ve posted I promised you some code so here it is.

GameOfLifeGPU is a simple project to implement Conway’s Game Of Life algorithm on a GPU. I’m using a 400×300 grid with edge wrapping, loading premade patterns from 400×300 content files and a simple mechanism for switching between those premade patterns. I’m also using a QuadDrawer class which you can find somewhere on Ziggyware.

GameOfLife.cs:


using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.IO;

namespace GameOfLifeGPU
{
 /// <summary>
 /// This is the main type for your game
 /// </summary>
 public class GameOfLife : Microsoft.Xna.Framework.Game
 {
 GraphicsDeviceManager graphics;
 SpriteBatch spriteBatch;
 private QuadRenderer quadDrawer;

 private int width = 400;
 private int height = 300;
 private RenderTarget2D gridRT;
 private Texture2D texture;

 private Effect clearEffect;
 private Effect updateEffect;

 private string currentTexture = "gliders";

 private KeyboardState keyState;
 private KeyboardState oldKeyState;

 public GameOfLife()
 {
 graphics = new GraphicsDeviceManager(this);
 Content.RootDirectory = "Content";

 quadDrawer = new QuadRenderer(this);
 Components.Add(quadDrawer);
 }

 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
 graphics.PreferredBackBufferWidth = 1024;
 graphics.PreferredBackBufferHeight = 786;
 graphics.PreferMultiSampling = false;
 graphics.ApplyChanges();

 IsFixedTimeStep = true;
 IsMouseVisible = true;
 TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 10);

 base.Initialize();
 }

 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
 // Create a new SpriteBatch, which can be used to draw textures.
 spriteBatch = new SpriteBatch(GraphicsDevice);

 clearEffect = Content.Load<Effect>("Effects\\clear");
 updateEffect = Content.Load<Effect>("Effects\\update");
 gridRT = new RenderTarget2D(GraphicsDevice, width, height, 1, SurfaceFormat.Color);

 texture = Content.Load<Texture2D>("glider");
 }

 /// <summary>
 /// UnloadContent will be called once per game and is the place to unload
 /// all content.
 /// </summary>
 protected override void UnloadContent()
 {
 }

 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
 oldKeyState = keyState;
 keyState = Keyboard.GetState();
 if (keyState.IsKeyDown(Keys.Space) && !oldKeyState.IsKeyDown(Keys.Space))
 {
 string[] textures = Directory.GetFiles(Content.RootDirectory);
 for (int j = 0; j < textures.Length; j++)
 {
 textures[j] = Path.GetFileNameWithoutExtension(textures[j]);
 }

 int i = Array.IndexOf(textures, currentTexture);
 texture = Content.Load<Texture2D>(textures[(i + 1)%textures.Length]);
 currentTexture = textures[(i + 1)%textures.Length];
 Window.Title = "GameOfLife - " + currentTexture;
 }

 base.Update(gameTime);
 }

 /// <summary>
 /// This is called when the game should draw itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Draw(GameTime gameTime)
 {
 GraphicsDevice.SetRenderTarget(0, gridRT);
 updateEffect.Begin();
 updateEffect.Parameters["Texture"].SetValue(texture);
 updateEffect.Parameters["GridSize"].SetValue(new Vector2(width, height));
 updateEffect.CurrentTechnique.Passes[0].Begin();
 quadDrawer.RenderFullscreen();
 updateEffect.CurrentTechnique.Passes[0].End();
 updateEffect.End();

 GraphicsDevice.SetRenderTarget(0, null);
 texture = gridRT.GetTexture();
 GraphicsDevice.Clear(Color.Black);
 spriteBatch.Begin();
 spriteBatch.Draw(texture,
 new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight),
 Color.White);
 spriteBatch.End();

 base.Draw(gameTime);
 }

 }
}

Just simple pattern switching code in the Update region and the draw mechanism in the Draw region.

Content\Effects\clear.fx:


struct VertexShaderInput
{
 float4 Position : POSITION0;
};

struct VertexShaderOutput
{
 float4 Position : POSITION0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
 VertexShaderOutput output;
 output.Position = input.Position;

 return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
 return float4(0, 0, 0, 1);
}

technique Technique1
{
 pass Pass1
 {
 VertexShader = compile vs_1_1 VertexShaderFunction();
 PixelShader = compile ps_1_1 PixelShaderFunction();
 }
}

Content\Effects\update.fx:


texture Texture;
sampler2D TextureSampler = sampler_state
{
 Texture = <Texture>;
 ADDRESSU = WRAP;
 ADDRESSV = WRAP;
 MAGFILTER = POINT;
 MINFILTER = POINT;
 MIPFILTER = POINT;
};

float2 GridSize;

struct VertexShaderInput
{
 float4 Position : POSITION0;
 float2 Texcoord : TEXCOORD0;
};

struct VertexShaderOutput
{
 float4 Position : POSITION0;
 float2 Texcoord : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
 VertexShaderOutput output;

 output.Position = input.Position;
 output.Texcoord = input.Texcoord;

 return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
 float4 cell = float4(0, 0, 0, 1);
 float4 alive = float4(1, 1, 1, 1);
 float4 dead = float4(0, 0, 0, 1);

 float2 pixel = 1.0f / GridSize;

 float n = 0.0f;

 // count neighbours
 n += tex2D(TextureSampler, float2(input.Texcoord.x - pixel.x, input.Texcoord.y - pixel.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x - pixel.x, input.Texcoord.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x - pixel.x, input.Texcoord.y + pixel.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x, input.Texcoord.y - pixel.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x, input.Texcoord.y + pixel.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x + pixel.x, input.Texcoord.y - pixel.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x + pixel.x, input.Texcoord.y)).r;
 n += tex2D(TextureSampler, float2(input.Texcoord.x + pixel.x, input.Texcoord.y + pixel.y)).r;

 if (tex2D(TextureSampler, input.Texcoord).r == 1.0f)
 {
 if (n == 2.0f || n == 3.0f)
 cell = alive;
 else
 cell = dead;
 }
 else
 {
 if (n == 3.0f)
 cell = alive;
 else
 cell = dead;
 }

 return cell;
}

technique Technique1
{
 pass Pass1
 {
 // TODO: set renderstates here.

 VertexShader = compile vs_2_0 VertexShaderFunction();
 PixelShader = compile ps_2_0 PixelShaderFunction();
 }
}

The algorithm kicks in the update.fx. Space cycles the premade patterns and you can make your own patterns by inserting your own 400×300 images. Check out the premade patterns. Wrapping edges were so easy to do. Easy like writing ADDRESSU = WRAP;  ADDRESSV = WRAP;. In the CPU version they are a bit more complicated. So here you go. Simple and easy. Here’s the complete project in a zip file (73kb), which you can download from MU or RS:

http://www.megaupload.com/?d=PMV3OPJF

http://rapidshare.com/files/290162624/GameOfLifeGPU.zip

EDIT: I’ve corrected a typo in the LoadContent method. The starting texture name shouldn’t be “gliders”, but “glider”. Please correct this in your downloaded project file also.

Written by brainzizizi

10.08.2009 at 07:14

Posted in xna

Tagged with , ,

Offside – Semester started

leave a comment »

As soon as the semester starts I got a mental blockade as far as programming goes. Last I did in like 30 minutes was Conway’s game of life on the CPU and the GPU. It’s easier to do on the GPU if you know what you’re doing. I’ll post the source as soon as I have some time.

Written by brainzizizi

09.20.2009 at 09:01

Posted in private

Tagged with

Offside – WordPress deleting my pics?

leave a comment »

In the last post I uploaded a pic of a door, and WP deleted it. Just throws a file not found. This wouldn’t be weird if it didn’t happened the last time a posted a pic and then included it as a 1×1 gallery in the post. Awful.

Written by brainzizizi

09.14.2009 at 21:54

Posted in private

Tagged with ,

Offside – Texture filtering

leave a comment »

You always wanted to know what’s the theory behind the MinFilter, MagFilter and MipFilter in your shaders? Check out another one of Shawn’s awesome posts. It’s awesome!

http://blogs.msdn.com/shawnhar/archive/2009/09/08/texture-filtering.aspx

Written by brainzizizi

09.08.2009 at 19:30

Posted in Uncategorized

Tagged with , , , ,

Abandoned – Shadow mapping screenshots

leave a comment »

You can see that I’ve soften the shadows quite a bit, I think it’s better this way. Also there’s an artifact due to resizing the lighting map to screensize. The screen edges are single colored, if there’s more shadow on the top edge pixel than light, the whole edge will be in shadow. But I’ll think some kind of UI will hide that well. Also this is a sneak preview of my door model. Next time when I’m doing a model I’ll record it ( like the guys @Overgrowth ), so I can show you my work process.

mudbox 2009-09-08 05-46-15-50

Written by brainzizizi

09.08.2009 at 03:50

Posted in xna

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 , , ,