PDA

View Full Version : Stupid cubemap



Jan
02-07-2003, 09:41 AM
Hi

I tried using cubemaps for environmental mapping.
I load my 6 textures, assign each to one face of the cube, then i do this:

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

glEnable (GL_TEXTURE_GEN_R);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);

And watch the result.

However it just cannot be physically correct!

I have a simple cube. When i look down at it, i should see the sky, but i see one side of the cubemap. Ok, it might be possible, that i have assign one side wrong.
BUT when i look at it from beneath, i see exactly the same side of the cube! That is absolutely not possible, cause i know that i assigned 6 different images to 6 different sides.

Also when i stay at one point and rotate around the y-axis, of course the reflection rotates, too. BUT it rotates in the opposite direction. Thatīs not correct (i actually took a mirror, lay it on the floor and checked it!).

Which setting do i have to change to correct this?

Jan.

Humus
02-07-2003, 10:18 AM
Are you sure you have correct normals?

Mazy
02-07-2003, 10:29 AM
Rotate the texturematrix to the inverse of the camera.

Jan
02-07-2003, 12:12 PM
@Humus: Yes, i am sure i have correct normals.

@Mazy: Could you go a bit more into detail. I think i know what you mean, but i donīt know how to accomplish this.

Jan.

Jan
02-07-2003, 12:28 PM
Ok, the thing that it rotates in the wrong direction is solved.
And i found out how i can rotate the texture matrix.

The only missing piece is, that i donīt know how i get the reverse of the camera.
Do you mean to use the forward, up and right vector of the camera to form a matrix, reverse that and rotate the texture matrix with that? Maybe you can tell me exactly in which way i would have to do that.

Jan.

ScottManDeath
02-07-2003, 01:55 PM
Hi

to inverse the rotation you just take the upper 3x3 matrix and transpose it because its a orthonormal(or orthogonal ??) matrix. So you reverse the rotation. Then set the texture matrix to this transposed and the translation of the texture matrix to (0,0,0).

Its the same way as you have billboards always facing to the camera.

Bye
ScottManDeath

Jan
02-07-2003, 02:52 PM
Thanks, itīs working now.

However, after playing a bit with it, i have some questions about it.

1. On my GF2 i can setup one Cubemap per texture unit. That means 2. When i create a cubemap i have to have the tu enabled, i want to use it later in. When i create two cubemaps in one tu, i can only use the last one. It seems, that bindtexture has no effect. Also i donīt have to bind the cubemap to the texture unit, but when i call glEnable (GL_CUBEMAP...), it is already working.

Why these restrictions? A cubemap is only a texture object, why is it not allowed to create more than one cubemap, and switch between them via glBindTexture?
And why am i forced to use the cubemap in the tu i created it in?

2. Of course i donīt want all my objects to be environmental mapped. Therefore when i draw my geometry, i have to enable and disable it quite often (i use BSP-trees already, so i cannot sort the objects).
How heavy is the performance hit of this?

3. I examined the Splinter Cell Demo. I noticed, that they donīt use a real cubemap for their environment mapping. They seem to use an image with "undefined" content. And they donīt alter that texture, depending on the room, one is in.
Of course this is a very easy approach to avoid having several cubemaps for every room.
But i wondered, how such a texture looks like? What kind of texture would you use?

Maybe i will have even more questions. But for now itīs enough :P

Thanks for the help so far.
Jan.

jwatte
02-07-2003, 11:58 PM
The GL spec doesn't distinguish between CUBE_MAP texture objects and 2D texture objects. If you treat them just the same, they should work just the same.

Note that TEXTRE_CUBE_MAP has higher priority than TEXTURE_2D, so if you enable both on the active texture unit, the CUBE_MAP target will "win" and stay enabled until it gets disabled on that same texture unit.

zeckensack
02-08-2003, 12:58 AM
Jan, regarding your point 1,
you sure you did it like this:
1)Create a texture object (glGenTextures blabla)
2)Bind it to target GL_TEXTURE_CUBE_MAP_ARB
3)Upload the six sides

Or did you reverse something, or bind to GL_TEXTURE_2D?

Jan
02-08-2003, 01:47 AM
Originally posted by zeckensack:
Jan, regarding your point 1,
you sure you did it like this:
1)Create a texture object (glGenTextures blabla)
2)Bind it to target GL_TEXTURE_CUBE_MAP_ARB
3)Upload the six sides

Or did you reverse something, or bind to GL_TEXTURE_2D?

Yes, that was it! In my routine, which binds my textures, i forgot to make it compatible with cubemaps.
Now that works, too.

Thanks for the help!
Jan.