Skip to main content
GameDev.net gamedev.net
🔒 Locked

Skybox Cubemapping Artefacts

Started by LordSputnik Nov 17, 2009 at 11:14 AM 4 replies 3.5k views
Original Post
LordSputnik
LordSputnik
Hey everyone! Hopefully just a quick question here! I'm using the following static image cubemap for my skybox: My Cubemap However, when I render this through OpenGL, I get lines where my quads intersect: Line Vertical on the Right Line on the Right and across the Centre of the Screen I think this is something to do with texture parameters, so I have this set on my newly generated textures:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

My rendering code is as follows:
glEnable(GL_TEXTURE_2D);
TexMgr.SetCurrent(Texture[0]);

glBegin(GL_QUADS);
	/** Front Face **/
	glTexCoord2d(0.25f,0);
		glVertex3f( -500.0f, 500.0f, -500.0f );
	glTexCoord2d(0.25f,0.25f);
		glVertex3f( -500.0f, -500.0f, -500.0f );
	glTexCoord2d(0.5f,0.25f);
		glVertex3f( 500.0f, -500.0f, -500.0f );
	glTexCoord2d(0.5f,0);
		glVertex3f( 500.0f, 500.0f, -500.0f );

	/** Back Face **/
	glTexCoord2d(0.25f, 0.75f);
		glVertex3f( -500.0f, 500.0f, 500.0f );
	glTexCoord2d(0.25f, 0.5f);
		glVertex3f( -500.0f, -500.0f, 500.0f );
	glTexCoord2d(0.5f, 0.5f);
		glVertex3f( 500.0f, -500.0f, 500.0f );
	glTexCoord2d(0.5f, 0.75f);
		glVertex3f( 500.0f, 500.0f, 500.0f );

	/** Left Face **/
	glTexCoord2d(0, 0.25f);
		glVertex3f( -500.0f, 500.0f, -500.0f );
	glTexCoord2d(0.25f, 0.25f);
		glVertex3f( -500.0f, -500.0f, -500.0f );
	glTexCoord2d(0.25f, 0.5f);
		glVertex3f( -500.0f, -500.0f, 500.0f );
	glTexCoord2d(0, 0.5f);
		glVertex3f( -500.0f, 500.0f, 500.0f );

	/** Right Face **/
	glTexCoord2d(0.75f, 0.25f);
		glVertex3f( 500.0f, 500.0f, -500.0f );
	glTexCoord2d(0.5f, 0.25f);
		glVertex3f( 500.0f, -500.0f, -500.0f );
	glTexCoord2d(0.5f, 0.5f);
		glVertex3f( 500.0f, -500.0f, 500.0f );
	glTexCoord2d(0.75f, 0.5f);
		glVertex3f( 500.0f, 500.0f, 500.0f );

	/** Top Face **/
	glTexCoord2d(1, 0.25f);
		glVertex3f( -500.0f, 500.0f, -500.0f );
	glTexCoord2d(0.75f, 0.25f);
		glVertex3f( 500.0f, 500.0f, -500.0f );
	glTexCoord2d(0.75f, 0.5f);
		glVertex3f( 500.0f, 500.0f, 500.0f );
	glTexCoord2d(1, 0.5f);
		glVertex3f( -500.0f, 500.0f, 500.0f );

	/** Bottom Face **/
	glTexCoord2d(0.5f, 0.5f);
		glVertex3f( 500.0f, -500.0f, 500.0f );
	glTexCoord2d(0.25f, 0.5f);
		glVertex3f( -500.0f, -500.0f, 500.0f );
	glTexCoord2d(0.25f, 0.25f);
		glVertex3f( -500.0f, -500.0f, -500.0f );
	glTexCoord2d(0.5f, 0.25f);
		glVertex3f( 500.0f, -500.0f, -500.0f );
glEnd();

glDisable(GL_TEXTURE_2D);

Other than me not setting the correct texture parameter, I had the idea that I could extend the quads so that they intersect at the edges, but I decided that might be quite difficult to write texture co-ordinates for. Is there a quick solution to my problem or a standard way of getting around it? Many Thanks, Sputty! [Edited by - LordSputnik on November 19, 2009 4:50:36 PM]
szecs
szecs
One: split up the texture and use GL_CLAMP_TO_EDGE
or use photoshop, and copy the edge pixels, to the matching side's edge:
Meaning:
image
Because the problem is with GL_LINEAR filtering, the neighbor pixels are gray. This way, it will be perfect.

Or split up, then arrange them horizontally, because that way you only have to deal with 3 edges.
image

BTW: where did you get the nice texture?
I've been searching maps for 2 days now.

[Edited by - szecs on November 17, 2009 11:30:32 AM]
Erik Rufelt
Erik Rufelt
szecs method should solve most problems, but it is still possible to get some artifacts. For example the bottom and top edge of the texture won't necessarily match up if you use wrapping, since they aren't supposed to touch each other, and with clamping you might get a visible clamped edge where you really want a 'wrap', just you want it wrapped to a neighboring cube-face, not a wrap in the current texture itself.
If this is noticeable, it can be fixed by using a true cube-map, and seamless cube map filtering. GL_ARB_seamless_cube_map. (It can also be fixed by adding borders completely around the edges not touching other faces of course, using szecs method).
Here's a pretty good cube map tutorial: http://developer.nvidia.com/object/cube_map_ogl_tutorial.html.
LordSputnik
LordSputnik
Thanks to both of you!

szecs: I did that to my image before posting, the copying of the edge pixels, but it didn't work... :S I also have a mode which can handle single images, and that works fine with the GL_CLAMP_TO_EDGE so thanks for that! :)

As for the cubemap image, a team member got it, he can't remember where, but we would have checked that it was free to use at the time. The originals were 6 512x512 images, so if you go to the first, large 2048x2048 image in my post, they're all in there and you're more than welcome to use that!

Erik Rufelt: Thanks for the cubemapping idea, I'll look into it further! Do you mean using GL_TEXTURE_CUBE_MAP instead of GL_TEXTURE_2D? Then I would automatically generate cubemap co-ordinates with GL?

Thanks again!

Sputty
Erik Rufelt
Erik Rufelt
Quote:
Original post by LordSputnik
Erik Rufelt: Thanks for the cubemapping idea, I'll look into it further! Do you mean using GL_TEXTURE_CUBE_MAP instead of GL_TEXTURE_2D? Then I would automatically generate cubemap co-ordinates with GL?


Yes exactly. I think the tutorial I linked to shows you how to do it automatically with texcoord generation. Using glTexCoord3f manually should also work.
LordSputnik
LordSputnik
Ah great! I was actually going to move onto a cubemapping class next, but I wanted to get the skybox rendering sorted in the Renderer before I implemented dynamic cubemaps... :P

I think I'll make a static cubemap class and use that in my skybox rendering :)

Thanks again, you've both been great help!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.