12
\$\begingroup\$

I have strange problem with drawing skybox texture on Mac. On iPhone everything is going fine. I have tried to change near and far planes value with no success.

It is a skybox of six textures, and for every texture I set this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

What could be the problem?

Screenshot:

Image of sky with the edges of the skybox visible

EDIT:

I have tried to set background color to red, to ensure if it is bleeding through the texture

I have also tried to change coords of the texture to this:

float err_corr = 0.5 / TEXTURE_SIZE;

GLfloat vertices[24] = {    
        -1.0f - err_corr, -1.0f - err_corr,  1.0f + err_corr,
    1.0f + err_corr, -1.0f - err_corr,  1.0f + err_corr,
    -1.0f - err_corr,  1.0f + err_corr,  1.0f + err_corr,
    1.0f + err_corr,  1.0f + err_corr,  1.0f + err_corr,
    -1.0f - err_corr, -1.0f - err_corr, -1.0f - err_corr,
    1.0f + err_corr, -1.0f - err_corr, -1.0f - err_corr,
    -1.0f - err_corr,  1.0f + err_corr, -1.0f - err_corr,
    1.0f + err_corr,  1.0f + err_corr, -1.0f - err_corr,
    };

And the box is drawn in this order:
GLubyte indices[14] = {0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1};

SOLUTION:

The solution is to set GL_CLAMP_TO_EDGE for the cubemap itself!

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
\$\endgroup\$

5 Answers 5

8
\$\begingroup\$

Are you positive that you've set GL_CLAMP_TO_EDGE for each individual texture? This is a part of individual texture state and it defaults to GL_REPEAT, so this needs to be done after binding with glBindTexture. I realize in the original post you literally say that you set it for each texture, but I'm wondering what the code actually looks like?

For example:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glBindTexture(GL_TEXTURE_2D, tex1);
//upload texture, etc.

glBindTexture(GL_TEXTURE_2D, tex2);
//upload texture, etc.

This is not the same as:

glBindTexture(GL_TEXTURE_2D, tex1);
//upload texture, etc.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glBindTexture(GL_TEXTURE_2D, tex2);
//upload texture, etc.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
\$\endgroup\$
1
  • \$\begingroup\$ I have found the error! It was necessary not to set GL_CLAMP_TO_EDGE for every texture of cube map but for the cubemapp itself! glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); and glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); \$\endgroup\$ Commented May 6, 2011 at 20:45
1
\$\begingroup\$

inset '0.5f / texture_width' from the left and right side of the texture and '0.5f / texture_height' from top and bottom. You're seeing sampling artefacts - texture samplers usually sample from the centre of texels so on the left and right, top and bottom (at 0 and 1 uv) you're getting 50% of whatever texel your sampler gets when it's out of bounds. That's either the other side of the texture or a default sampling colour.

\$\endgroup\$
2
  • \$\begingroup\$ That is why he has got the GL_CLAMP_TO_EDGE set, it should make the out of bounds samples take the value of the nearest in-texture pixels. What you describe may very well work, but it doesn't explain why the problem is there in the first place. \$\endgroup\$ Commented May 4, 2011 at 20:47
  • \$\begingroup\$ I have tried it with no change :/ \$\endgroup\$ Commented May 5, 2011 at 6:44
0
\$\begingroup\$

My best guess is that the difference between MAC and iPhone is caused by antialiasing on the MAC. My 3D programming is a bit rusty, but I guess you would have to make all the squares part of the same mesh or something like that.

Dirty hack solution would be to make all the squares a bit too big so they overlap and clip each other and adjust UV coordinates accordingly.

\$\endgroup\$
6
  • \$\begingroup\$ I have tried to turn off anti-aliasing (by glDisable(GL_POLYGON_SMOOTH);) with no effect. I am drawing skybox as triangle strip with coords form -1 to 1 \$\endgroup\$ Commented May 4, 2011 at 19:58
  • 1
    \$\begingroup\$ That sounds good to me. At least for now I'm out of guesses, but you may want to narrow down the problem by finding out if that black is the background bleeding through or the texture edge showing as black. If you place a red polygon somewhere behind the artefact, will the artefact take it's colour? \$\endgroup\$ Commented May 4, 2011 at 20:25
  • \$\begingroup\$ I want try to extend walls, so they overlap (just like eBusiness wrote) - I think 0.0001 would be enough. You don't have to change UV coordinates. \$\endgroup\$
    – zacharmarz
    Commented May 4, 2011 at 20:44
  • \$\begingroup\$ 1/10000 certainly isn't enough, the magnitude of the problem seems to be in the 1/4 to 1/2 pixel range, so depending on texture size the minimum magnitude for this to work would be around 1/1000. Not adjusting UV coordinates is kinda sloppy, given the nature of the texture the resulting visual jump may not be noticeable, but it would still be wrong. In any case, further advice for hacks should depend on the answer to the question I asked in my previous comment. \$\endgroup\$ Commented May 4, 2011 at 21:31
  • \$\begingroup\$ The artifact is not a background bleeding through the texture. I have set background color to red with no change. I have also tried to extend texture coordinates \$\endgroup\$ Commented May 5, 2011 at 6:43
0
\$\begingroup\$

This is usual problem with cubemaps on older HW (or iphones maybe). Check for the

GL_ARB_seamless_cube_map

extension if it is available on your hw. If so. Problem will be propably solved by using it.

\$\endgroup\$
2
  • \$\begingroup\$ Problem is on GeForce 9400M, not the iPhone. This extension is not available for me. \$\endgroup\$ Commented May 5, 2011 at 6:46
  • \$\begingroup\$ This is definitely NOT a problem caused by cubemaps, regardless of being seamless or not. This is a texture wrapping issue. \$\endgroup\$
    – Tara
    Commented May 15, 2015 at 11:06
0
\$\begingroup\$

Are the six textures set up, specifically, as a cube map or are each of the skybox faces rendered separately with their own texture? I heard some early PC systems had rather poor filtering when it came to handling cubemaps in that they didn't necessarily filter across the from one face texture to the next when you sampled near the cube edges. AFAIK the SGX (iphone GPU) should filter across edges correctly.

It did occur to me that the bottom of your side textures looks to be a similar shade of blue to the artefact . Could you try, say, making the bottom row (or a few rows) of pixels a hideous shade of magenta and see if that changes the artefact colour? That might give some more idea of what may or may not be happening.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .