PDA

View Full Version : cubemap problem



greg2
07-05-2003, 05:47 AM
I have tried to use static environment mapping with cubemap. I load 6 textures of a skybox and i disply a cube which reflects it.
But i have a 2 problems. Look at this picture: http://texel3d.free.fr/bugs/cubmap.jpg
Or the program here: http://texel3d.free.fr/bugs/cubmap.zip (255Ko)

Has you can see:

1) The SkyBox is not reflected in the right way on the cube (the sky is in the bottom and the ground is in the top).

2) The texture coordinates are not well generated by opengl. There is a "break" in the horizon of the sky, which follow an invisible line between 2 vertices of each quads. This "break" is not static and move. This problem is not visible on a sphere.

It seems to be a problem of texture coordinates generation.
How can i solve this 2 problems?

I use this code to create my cubemap:



void abysseSDK_CreateCubeMap(void)
{
int i;

glEnable(GL_TEXTURE_CUBE_MAP_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);


for (i = 0; i < 6; i++)
{
AbysseSDK_CubMapTexture[i]=CreateGLTexture(cubefaces[i],skyBoxTex[i]);
}

glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_CUBE_MAP_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_EXT);


glEnable(GL_TEXTURE_CUBE_MAP_EXT);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_NORMALIZE);

}


And i display my cube with face normal.

Thanks.

JustHanging
07-05-2003, 09:03 AM
Hi,

The first problem you can solve by loading the pictures to different cubemap faces, the current positive y to negative y and so.

The other one is unfortunately not that simple. The problem is caused by linear interpolation of the reflection vectors and can't be easily solved as far as I know. You can reduce the distortion by dividing the cube's faces into many smaller ones, though.

-Ilkka

greg2
07-05-2003, 12:55 PM
Thanks. I will try to solve the second problem by dividing the faces (it seems to be the same type of problem we can have with vertex lighting).

But for the 1st problem. The order the faces are loaded will not solve my problem. The skybox textures will go to another faces, but their orientation will not change. I have to rotate my texture by 180.
But is it normal?
Why OpenGL does this "error"?
I will have to use a rotation like glRotate or to use a matrix to rotate it?

JustHanging
07-05-2003, 10:34 PM
Better rotate them in a paint program. Different 3d programs use different coordinate systems, I guess that's why they don't create compatible cubemaps.

-Ilkka

Jan
07-06-2003, 03:39 AM
crossposter!
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00008573&forum=3dtheory&id=-1

greg2
07-06-2003, 05:18 AM
http://www.opengl.org/discussion_boards/ubb/smile.gif
Sorry, but i was not sure to have an answer.
Thanks.

Relic
07-07-2003, 04:50 AM
You'd also want to change your clamping to GL_CLAMP_TO_EDGE with cubemaps to avoid seams at the cubemap's borders in case the texture border color would be sampled.

greg2
07-07-2003, 06:10 AM
I will try it.