• Advertisement
Sign in to follow this  

making a skybox?

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

does anyone know of tutorial that teaches how to make a skybox in your game that doesn't require any programs. i searched all around google and couldn't find anything. thanks in advance. [Edited by - baddogj on October 24, 2004 9:30:05 AM]

Share this post


Link to post
Share on other sites
Advertisement
Try gametutorials.com, they have a skybox example in the DX section. Later on you may want to speed up your skybox rendering using cubemaps ..

good luck

Share this post


Link to post
Share on other sites
thanks for the posts. could someone possibly email me the tutorial at gametutorials for making a skybox as i am not able to download it. thanks in advance

Share this post


Link to post
Share on other sites
if any of you are wondering, my email adress is jdwilliams3@comcast.net if some of you don't know

Share this post


Link to post
Share on other sites
Quote:
Original post by Mille
Later on you may want to speed up your skybox rendering using cubemaps ..


erm... how so? not that something like an old-fashioned skybox would need much of a speed boost anyway, but the only advantage of using a cubemap comes into play if you also want to use it for cubemapping on objects. else its just a fancy but useless thing to do. except you want to say that clipping a few unused quads and sending one quad instead of 2 strips or 6 quads is making any difference when looking at the fillrate its eating one way or another.

Share this post


Link to post
Share on other sites
Is there something more to making a skybox then simply texturing a big box then centering it on your scene? Because thats what I do but I see so many questions about them it sounds like its harder then just that.

Share this post


Link to post
Share on other sites
I found the tutorial slightly helpful. It suggests making a huge cube centered on the camera. It dawned on me I could just make a tiny cube centered on the camera, render it first and then clear the depth buffer with a statement like this: glClear(GL_DEPTH_BUFFER_BIT); . It's only an illusion (not real rendered geometry) anyways. If you have some generic texture loading code (like me) that does things like automatic mipmap generation, you may want to bypass that as a mipmap is pointless and a waste of memory. This is especially true with detailed skybox textures. Also, you should disable lighting and other effects.

As far as overhead is concerned, you can disable the skybox when the camera is in a room without windows, etc.

If anyone has any other ideas, or disagrees with me, I'd love to know about it. This is new to me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Trienco
Quote:
Original post by Mille
Later on you may want to speed up your skybox rendering using cubemaps ..


erm... how so? not that something like an old-fashioned skybox would need much of a speed boost anyway, but the only advantage of using a cubemap comes into play if you also want to use it for cubemapping on objects. else its just a fancy but useless thing to do. except you want to say that clipping a few unused quads and sending one quad instead of 2 strips or 6 quads is making any difference when looking at the fillrate its eating one way or another.

The benefit doesn't come from sending one quad vs. 6 quads, it comes from only having to set one texture and then make one draw call rather than have to set 6 textures and make 6 draw calls. API calls and texture changes are relatively expensive and avoiding them is in general a good thing, though in this case it's probably not going to make a huge difference. If you're CPU limited though (as many games still are) it will be slightly faster than making 6 draw calls.

The biggest cost of rendering a skybox is fillrate so in general you want to clear your depth buffer at the start of the frame using specific API clearing calls (rather than drawing a full screen quad) which sets up the hierarchical z buffer on modern cards then draw your scene (in roughly front to back order) and then draw your skybox last with it's z value set to the maximum z. Doing it that way gets you early z rejection on pixels where the skybox is hidden by other objects which saves fillrate. Drawing the skybox first without writing z, whilst it's a nice simple approach, means you write every pixel with the skybox colour and then overwrite many of them with your scene and so wastes fill rate.

As usual, these sorts of optimizations are not worth worrying about until you've profiled and identified this area as a bottleneck. If you do find yourself fill rate limited though it can be worth arranging your sky box rendering like this.

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnewport
The benefit doesn't come from sending one quad vs. 6 quads, it comes from only having to set one texture and then make one draw call rather than have to set 6 textures and make 6 draw calls.


true, but if the hardware has cubemapping it should also support pretty big textures to store most or all sides of the box. would also just mean one draw call, but besides that: how many skybox are you drawing per frame so that its really making a difference?

Quote:
The biggest cost of rendering a skybox is fillrate so in general you want to clear your depth buffer at the start of the frame using specific API clearing calls (rather than drawing a full screen quad) which sets up the hierarchical z buffer on modern cards then draw your scene (in roughly front to back order) and then draw your skybox last with it's z value set to the maximum z.


also true in theory, yet it seems at least my rad9800 is taking exactly the same time to clear the color buffer as it takes to render a cubemapped quad. not so true for the z-buffer, where clearing it IS much faster than overwriting it. anyone with experience on nvidia cards? feels a little like ati thought "no need to make it efficient, game programmers just draw over it anyway" or something like that.

Share this post


Link to post
Share on other sites
Packing the 6 skybox textures into one ordinary texture is perfectly possible but why bother? There's no way to pack 6 squares into one power of 2 texture without wasting space. Far easier to just use a cube map that is designed to pack 6 faces of a cube into one texture with maximum efficiency.

The main reason to clear the z-buffer using a clear call rather than rendering a quad is that it is the only way to set up the hierarchical z-buffer correctly (it is also very quick but that's really just a side benefit). If you've got a sky box there's no point clearing the colour buffer at all - you're going to end up writing every pixel anyway. The reason for drawing the sky box last is that you get early z rejection thanks to the hierarchical z-buffer that way - the hardware can early out on pixels that it knows will be hidden by geometry that's already been drawn. In a typical scene much of the skybox will be hidden by terrain and objects in the world so that can be a significant fill rate saving.

Share this post


Link to post
Share on other sites
Sky-boxing is a simple thing to get written but I found one problem with it. I have an island in the middle of the ocean (flat); the ocean obviously needs to extend to the horizon otherwise you see a gap between it and the skybox. So how do you bridge the gap between your map and the infinite distance to the skybox? I got it working but it's not great! Wondered if anyone else has tun into similar problems ever?

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnewport
Packing the 6 skybox textures into one ordinary texture is perfectly possible but why bother? There's no way to pack 6 squares into one power of 2 texture without wasting space. Far easier to just use a cube map that is designed to pack 6 faces of a cube into one texture with maximum efficiency.

The other thing I forgot to mention is that using a cube map you get the correct behaviour for filtering at the edges automatically (adjacent faces filter with each other across the boundaries) which is harder to arrange if you manually assemble textures into a larger texture - you will have to duplicate pixels from other faces around the edges of each face to get the correct filtering.

Share this post


Link to post
Share on other sites
Quote:
Original post by d000hg
Sky-boxing is a simple thing to get written but I found one problem with it. I have an island in the middle of the ocean (flat); the ocean obviously needs to extend to the horizon otherwise you see a gap between it and the skybox. So how do you bridge the gap between your map and the infinite distance to the skybox? I got it working but it's not great! Wondered if anyone else has tun into similar problems ever?

Clever use of fog is your best bet - in real life the mechanisms that cause objects to 'fog out' in the distance are exactly the same as the mechanisms that give the sky it's colour (blue on a clear day, greyish on an overcast day, reddish orange at sunrise and sunset, etc.). It's the combination of in-scattering and out-scattering due to the atmosphere that gives the sky it's colour and that also makes objects fade out in the distance - 'clear sky' is just the black void of space viewed through a lot of atmosphere after all.

If you want to have a seamless blend of your scene into your skybox you want your skybox to look right at the horizon (generally a fairly uniform haze - clouds also 'fog out' towards the horizon) and then you want to fog your scene to the same colour in the far distance before it clips out. You can pick an approximate fog colour and use traditional fixed function fog or you can be a bit cleverer and use a pixel shader that uses the skybox texture as the colour to fog to at each pixel to give completely seamless blending.

Share this post


Link to post
Share on other sites
does anyone know of an online tutorial of making a skybox in opengl that you can just copy and paste?

Share this post


Link to post
Share on other sites
baddogj,

By the sounds of it you are in the early stages of learning about skyboxes etc... I am assuming you have seen the skybox tutorial that these other blokes refered you to at gametutorials.com so if you are still unsure, i think you should stick to basics! Just 'draw' a really big box (made up of 6 quads) around your scene using your OpenGL commands, and render the correct textures to each face (quad) so that it all matches up etc...
This gives you your skybox. So no real cut and paste job needed here, you obviously know how to draw your OpenGL quads, i am sure you have come across texturing. You'll be right. Remember the best way to learn is to try and nut it out yourself first! Good Luck!

Cheers.

Share this post


Link to post
Share on other sites
i don't mean copy and paste the code, i mean the tutorial, because i am not able to download anything like at gametutorials. i am just having trouble understanding how you texture the inside of a cube.

Share this post


Link to post
Share on other sites
its that my father is seriosly experienced with network security, and he blocked me from doing downloading of any sort so that he doesn't risk getting a virus on his computer.

Share this post


Link to post
Share on other sites
Quote:
Original post by baddogj
i don't mean copy and paste the code, i mean the tutorial, because i am not able to download anything like at gametutorials. i am just having trouble understanding how you texture the inside of a cube.

If you texture that outside of a cube you also texture the inside. So in otherwords just texture the cube as you normally would.

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnewport
If you've got a sky box there's no point clearing the colour buffer at all - you're going to end up writing every pixel anyway.


hmm.. for some reason the first time i read your last post i thought you were suggesting to. reading it again you were of course talking about the depth buffer *cough*.

and now i will have to try something, as id like the lower face of the box to align with the water level which gave me trouble with cube mapping so far.. and i think i was just a moron to fiddle with the texcoord to achieve that effect.

Share this post


Link to post
Share on other sites
Quote:
Original post by baddogj
i don't mean copy and paste the code, i mean the tutorial, because i am not able to download anything like at gametutorials. i am just having trouble understanding how you texture the inside of a cube.


Um, OK, at what point do you get stuck?

"I don't know how to draw a cube"
"I can draw a cube but I don't know how to texture it"
"I can draw a textured cube but I can't see it from the 'inside'"
"My hemi-sphere lighting pixel shader seems to mess up near the corners"

Share this post


Link to post
Share on other sites
why do we still use cubes anyway?

why not an octohedron?

with an octohedron it is much easier to put all of the faces onto a single square image texture.

although [I don't know if this matters much] the uv seams don't line up, they are hard to paint [they can be generated pretty easily in a program, even if from a cubemap]

-- example ---
http://home.earthlink.net/~nwinters99/temp/sky_octohedron.jpeg

edit: now that I think about it, I like the sound of the "draw with furthest z value after drawing rest of scene" but this shape would probably have to be tesselated [and warped because the depth value on one place on the doesn't correspond to the same distance as on another place on the screen]... that is, unless there is a way to specify the z value of a pixel I don't know about

but, now that I am offtopic, I'll try to get back on it again:
Quote:
Original post by baddogj
does anyone know of tutorial that teaches how to make a skybox in your game that doesn't require any programs. i searched all around google and couldn't find anything. thanks in advance.

unfortunately, it is very difficult to attempt to paint a cube map [particularly around the seams] because of how it is warped.

That said, there are alternative shapes which are much easier to paint, such as cylinders. To paint a repeating texture [like a cylinder] the technique is:
1. paint in the middle
2. offset by 1/2 on an axis which is mirrored across [the offset filter should have an option to move what it moves off one side onto the other]
goto 1 until results are satisfactory

[Edited by - sit on October 26, 2004 2:52:42 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by baddogj
its that my father is seriosly experienced with network security, and he blocked me from doing downloading of any sort so that he doesn't risk getting a virus on his computer.


oh my! would it be of any help if someone emailed you the source code?

well, here's the source snippet for the skybox from DigiBen's 2nd heightmap tutorial available at GameTutorials.com


// This holds the texture info by an ID
UINT g_Texture[MAX_TEXTURES] = {0};

#define BACK_ID 1 // The texture ID for the back side of the cube
#define FRONT_ID 2 // The texture ID for the front side of the cube
#define BOTTOM_ID 3 // The texture ID for the bottom side of the cube
#define TOP_ID 4 // The texture ID for the top side of the cube
#define LEFT_ID 5 // The texture ID for the left side of the cube
#define RIGHT_ID 6 // The texture ID for the right side of the cube


///////////////////////////////// CREATE SKY BOX \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This creates a box centered around X Y Z. Instead of colors at
///// each vertices there is texture maps for each side of the box to
///// create the illusion of the sky box. You can set the width, height and length
///// of the sky box to create different perspectives for different sky box textures.
/////
///////////////////////////////// CREATE SKY BOX \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CreateSkyBox(float x, float y, float z, float width, float height, float length)
{
// Turn on texture mapping if it's not already
glEnable(GL_TEXTURE_2D);

// Bind the BACK texture of the sky map to the BACK side of the cube
glBindTexture(GL_TEXTURE_2D, g_Texture[BACK_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// This centers the sky box around (x, y, z)
x = x - width / 2;
y = y - height / 2;
z = z - length / 2;

// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the BACK Side
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);

glEnd();

// Bind the FRONT texture of the sky map to the FRONT side of the box
glBindTexture(GL_TEXTURE_2D, g_Texture[FRONT_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);


// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the FRONT Side
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y, z + length);
glEnd();

// Bind the BOTTOM texture of the sky map to the BOTTOM side of the box
glBindTexture(GL_TEXTURE_2D, g_Texture[BOTTOM_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the BOTTOM Side
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y, z + length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y, z + length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y, z);
glEnd();

// Bind the TOP texture of the sky map to the TOP side of the box
glBindTexture(GL_TEXTURE_2D, g_Texture[TOP_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the TOP Side
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z);

glEnd();

// Bind the LEFT texture of the sky map to the LEFT side of the box
glBindTexture(GL_TEXTURE_2D, g_Texture[LEFT_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the LEFT Side
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z + length);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z);

glEnd();

// Bind the RIGHT texture of the sky map to the RIGHT side of the box
glBindTexture(GL_TEXTURE_2D, g_Texture[RIGHT_ID]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

// Start drawing the side as a QUAD
glBegin(GL_QUADS);

// Assign the texture coordinates and vertices for the RIGHT Side
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z);
glEnd();
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement