View Full Version : cube mapping reversed?
10-04-2004, 12:54 AM
seems my cube made reflection is backwards, i move up and the point im looking at also moves up with the camera, so the top texture is always facing the camera?
is there some way to reverse it? any one had this problem before?
10-04-2004, 08:13 PM
Could you throw us a bone here, maybe in the form of some code, or a screenshot?
Reflections, as I've always known them, follow me wherever I go. A mirror is a good example of the this phenomenon :)
10-05-2004, 01:53 AM
// code to set up my cube map, this is called 6 //times, after:
// that is
void TextureCube::GenerateTextureFace(int face, char* image, int width, int height, GLint type)
GLenum target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
glTexImage2D(target, 0, type, width, height, 0, type, GL_UNSIGNED_BYTE, image);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}images from top and bottom:
see how the main blue section (the sky) can be seen from the top and bottom, in roughly the same position?
10-06-2004, 02:12 AM
I think your problem is due to the fact that the reflection vector is in eye-space, rather than world-space, hence the reflection follows the eye. If you look at the spec on reflection mapping you'll see that the whole thing takes place in eye-space. First, the reflection vector is computed as it is in sphere mapping. This reflection vector is then assigned to the texture coordinate. If left in eye-space, it will be as if the cube map were oriented about the head, like a box on a stick.
Try loading the inverse of the camera matrix on the texture matrix stack before you draw your reflection mapped geometry. You can do this by calling glGetFloatv with GL_MODELVIEW_MATRIX right after the camera transform is applied, invert the upper 3x3 rotation matrix by simply transposing it, then push the result onto the texture matrix stack before you draw.
Here's the math behind this:
Ve = Normalized eye to vertex in eye-space.
Ne = Normalized vertex normal in eye-space.
Vo = Normalized eye to vertex in object-space.
No = Normalized normal in object-space.
C = Camera matrix.
M = Model matrix.
CM = Modelview matrix.
^T = Transpose.
^-1 = Inverse.
^-T = Inverse transpose.
Computed reflection vector, as in sphere mapping:
Re = Ve - 2 Ne Ve^T Ne
= CMVo - 2 ((CM)^-T No) (CMVo)^T ((CM)^-T No)
= CMVo - 2 (C^-T M^-T No) (Vo^T No)
Now multiply through by C^-1:
C^-1 Re = MVo - 2 (M^-T No) (Vo^T No)
= Reflection vector in world-space.
Note that if your cube map is defined in eye-space, then the reflection vector should work without modification. It's only when the cube is defined in world-space that you need this step. You just need to make sure the vectors you're working with are in the same space.
10-06-2004, 02:38 AM
oh didnt realise i had to use a texture matrix to get this working :) thx for the suggestion, will get around to testing it.
can i use the cheating inverse? (transpose)
10-07-2004, 04:42 AM
can i use the cheating inverse? (transpose)I believe that's what I suggested :)
You could do something like this:
glGetFloatv( GL_MODELVIEW_MATRIX, mat );
float texMat =
mat, mat, mat, 0,
mat, mat, mat, 0,
mat, mat, mat, 0,
0, 0, 0, 1
10-08-2004, 02:16 AM
yeah works fine :)
i thought u meant proper inverse :)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.