Showing posts with label directx. Show all posts
Showing posts with label directx. Show all posts

Thursday, March 20, 2008

Adding Detail Map - Looks Fuzzy

To counteract the blurriness of the terrain, I'll apply a detail map. A detail map is just a plain texture with some details like cracks and bumps. The detail map will be applied 32 times over the terrain, here's what the result looks like (before and after):

closenotfuzzy closefuzzy

It looks a bit more realistic, but it seems to be really noisy and fuzzy when I fly towards it (that is when I fly using the camera controls, not in real life - I didn't take any crystal meth or anything). Here's what it looks like from far away (before and after):

notfuzzy fuzzy3

It's easiest to see the fuzzy noise on the black pit to the right. It's hard to tell from the images but it's worst when you move toward the terrain; pixels on the detail map seem to move about and make it look something like there's interference on a TV channel. When I release my game I'll just include a superficial aerial with it - problem solved.

A lot of these sort of problems can be fixed with manipulating some of the parameters (like how many times the detail map is repeated over the terrain). There are already tons of parameters I've arbitrarily picked and I just run the project to see what it looks like, then change them again - which takes up a bit of time. I'm thinking of writing some sort of Reflection-based ParameterManager class so I can easily cycle through all available parameters at run-time and save/load sets. I'll put that on the back-burner though because my terrain performs horribly at the moment so I'll do some optimisation with Continuous Level Of Detail (CLOD) next time.

Terrain Texturing

After I put in the camera rotation code from my last post, the teeth-like artifacts disappeared. I find graphical programs a real bitch to debug so I'm pretty happy to totally block from memory that they ever existed... what was I talking about? Oh yeah, texturing the terrain.

Instead of colouring the vertex based on how high it is, we'll texture it. With height-colouring it was simple to go from black to white, it's just as easy going from one texture to another - the technique is pretty much the same but the start and end colours are retrieved from a specific point on each texture. Blending is done as before, if the point is nearer the higher texture, the point will be closer in colour to the pixel from the higher texture and vice versa for the lower texture. Here's the result of applying 4 textures (earth, grass, rock and snow) to my terrain:

0 1 2 3

texturedterrain

It looks more realistic, but a little bit blurry. The pit on the right looks black instead of earthy because I started blending off with a black colour as a base, I think it looks ok.

Wednesday, March 19, 2008

Proper Camera Rotation

In order to have a better look at the weird artefacts on my terrain, I tried to add a mouse & keyboard controlled camera. Matrix.RotationYawPitchRoll doesn't seem to work for me - if I rotate my camera 90 degrees about the Y axis (yaw) looking to my left then try to rotate about the Z axis (roll) so the view spins clockwise it actually rotates around the X axis (pitch) and ends up looking up and down.

(I suppose I should've said on the first post that I'm writing the game in Managed DirectX with C#).

Anyways, I had this problem before when I was good at geometry so I was sure I could do it again. Unfortunately years of boozing have destroyed any remnants of my secondary school geometry and the results of my sin/cos calculations were that I should go get my old computer out of the shed and get the old code. Here it is if anyone has the same problem:

private void Rotate(float yaw, float pitch, float roll)
{
// We'll create 3 matrices for the combined rotation
Matrix yawMatrix = new Matrix ();
Matrix pitchMatrix = new Matrix ();
Matrix rollMatrix = new Matrix ();

_localMatrix.Translate(_position);

// Reset it's orientation vectors to make sure they're all
// sqare against each other and unit length
_look.Normalize();
_right = Vector3.Cross(_up, _look);
_right.Normalize();
_up = Vector3.Cross(_look, _right);
_up.Normalize();

// The pitch rotation will be done about the x axis (right)
pitchMatrix.RotateAxis(_right, pitch);
// The yaw rotation will be done about the y axis (up)
yawMatrix.RotateAxis(_up, yaw);
// The roll rotation will be done about the z axis (look)
rollMatrix.RotateAxis(_look, roll);

// Rotate the local axis about these matrices so we can tell
// how the object is now oriented after rotation

// Rotate the _look and _right about the yaw rotation
_look.TransformCoordinate(yawMatrix);
_right.TransformCoordinate(yawMatrix);

// Rotate the _up and _right about the roll rotation
_up.TransformCoordinate(rollMatrix);
_right.TransformCoordinate(rollMatrix);

// Rotate the _look and _up about the pitch rotation
_look.TransformCoordinate(pitchMatrix);
_up.TransformCoordinate(pitchMatrix);

// Store this in the local matrix for translation when rendering
_localMatrix.M11 = _right.X;
_localMatrix.M12 = _right.Y;
_localMatrix.M13 = _right.Z;

_localMatrix.M21 = _up.X;
_localMatrix.M22 = _up.Y;
_localMatrix.M23 = _up.Z;

_localMatrix.M31 = _look.X;
_localMatrix.M32 = _look.Y;
_localMatrix.M33 = _look.Z;
}

First post!!!!!

Hello! I'm writing this blog for purely selfish reasons - I've wanted to program games since I was a kid but have only once finished a project: a Nibbles clone with death sequences in DOS (I'll put up the exe if anyone's interested). A friend suggested that a blog can help so hopefully some sort of guilt for updating this blog will override my incredible laziness. He's got a game engine in development too and has made a lot of progress, it looks fantastic and you can see it on his blog - feel free to make me feel better and undermine him and his engine :)

So what'll my game be then? I don't know yet, but my ambitions are high - basically I'd like a procedurally created universe with super-intelligent AI with a combined RPG/FPS/Flight/Driving/Adventure gameplay that's fecking awesome. People will become addicted to my game and it will create world peace. Oh and I'll get the ride off of some hot groupies. But I've got to start somewhere, so here we go - a terrain (bit of land) generated with fault formation (raise sections of the land randomly) and lit with height lighting (the higher the whiter). These are real terrain basics so I won't go into detail (unless someone needs it).


Looks ok for a first go, but there are these weird artefacts, kinda like teeth, no idea what they are...
Until next time!