Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Skybox visible borders

Tags:

c++

opengl

skybox

I have my skybox showing: enter image description here

But there are borders of the box, which I don't want. I already searched the internet and they all said that GL_CLAMP_TO_EDGE should work, but I am still seeing the borders.

This is what I used for the texture loading:

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);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenerateMipmap(GL_TEXTURE_2D);

Can anyone tell me what I am doing wrong?

EDIT: enter image description here

Strange thing is that the borders are only showing at the top of the skybox. so when a skybox face, touches the roof of the box.

Here an image of it: enter image description here

like image 867
Hugius Avatar asked Dec 11 '25 00:12

Hugius


2 Answers

I finally found the solution. This is a filthy mistake in the texture itself. There is a black border around the texture, but you can barely see it unless you zoom in. So I removed the borders and it worked.

like image 124
Hugius Avatar answered Dec 12 '25 13:12

Hugius


Its texture coordinates floating error. If you use shaders you can clean it to strict [0.0f, 1.0f]. I cannot say is there is any possible solution for OpenGL API calls. But shaders must support this. Example using HLSL 2.0 (NVIDIA Cg) for post screen shader.

float g_fInverseViewportWidth: InverseViewportWidth;
float g_fInverseViewportHeight: InverseViewportHeight;

struct VS_OUTPUT {
   float4 Pos: POSITION;
   float2 texCoord: TEXCOORD0;
};

VS_OUTPUT vs_main(float4 Pos: POSITION){
   VS_OUTPUT Out;

   // Clean up inaccuracies
   Pos.xy = sign(Pos.xy);

   Out.Pos = float4(Pos.xy, 0, 1);
   // Image-space
   Out.texCoord.x = 0.5 * (1 + Pos.x + g_fInverseViewportWidth);
   Out.texCoord.y = 0.5 * (1 - Pos.y + g_fInverseViewportHeight);

   return Out;
}

Where sign rutine is used for strict [0, 1] texture coord specification. Also there is sign rutine for GLSL you may use. sign retrives sign of the vector or scalar it mean -1 for negative and 1 for positive value so to pass texture coord for vertex shader it must be specified as -1 for 0 and 1 for 1 than you may use this like formulae for actual texture coord specification:

   Out.texCoord.x = 0.5 * (1 + Pos.x + g_fInverseViewportWidth);
   Out.texCoord.y = 0.5 * (1 - Pos.y + g_fInverseViewportHeight);

Here you can see texture 1 texel width inaccurancy:

enter image description here

Now with modified shader:

enter image description here

like image 21
Mykola Avatar answered Dec 12 '25 15:12

Mykola



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!