Nav links

Sunday, 13 November 2005

Skybox seams

After learning about skyboxes for the first time only a few days ago, I decided it would be a useful addition to my 3D fractal generator FractalPeaks. Rather than controlling a fractal hovering in space, the skybox would be an easy way of surrounding the fractal with a realistic world. After following the great Microsoft Beginning Game Development tutorial I had a functional skybox, but I wanted higher quality original graphics.

In addition to Terragen, which is a great free program for generating skybox textures, you can download prepared texture collections specifically for skyboxes. DirectX is happy with both .tga and .jpg file types; I used the latter because they are smaller.

One thing to watch out for is the appearance of seams at the edge of the skybox textures. I didn't have a problem with the original sample, but one I downloaded had some pretty ugly borders. After trying the recommended procedure of setting the texture clamping, which in Managed DirectX is done like this:

device.SamplerState[0].AddressU = TextureAddress.Clamp;

I had no success.so then I tried:
device.SetSamplerState(0, Microsoft.DirectX.Direct3D.SamplerStageStates.AddressU, 3);
to overlap the textures. Again that failed.

I then thought of resizing my textures from their original 768x768 to a power of 2 that computers seem to like so much. At 512x512 the seams were completely gone. It doesn't look too much worse, so that's a pretty good outcome. After reading a bit more about textures, I believe that this problem usually only occurs with older cards. As I want my software to be usable by everyone I'll make sure to keep an eye on this in future.