PDA

View Full Version : Cubemap face orientation: how to



PaoloS
07-05-2015, 03:59 PM
Hello everyone,

I am trying to get cubemaps working in my program and I can't seem to find a logic for how I am supposed to upload the texture.
This is the texture I am uploading:

1919

and this is the code I am using:



const uint imageSize = width_ * height_ * bpp_ ;

for( uint i = 0; i < 6; ++i )
{
glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
internalFormat_,
width_, height_, 0,
pixelDataFormat_, GL_UNSIGNED_BYTE,
imagePtr + ( imageSize * i )
);
}


Before you ask, yes, I already made sure the texture is read correctly (if I import the texture as a 2d texture, it looks like the one I put above).
To render this, I am using a super simple shader that samples the cubemap with the world space normal.



OUT_FragmentColor = texture( colorTexture, normalize( worldSpaceNormal ));


The case I am using is a sphere centered at the center of the axis. I am using right hand coordinate everywhere in my program.
This is what I get when I render the sphere and I sample the cubemap (approximate camera positions):

from 1,1,1 looking down to -1,-1,-1
1920

from -1,-1,-1 looking up to 1,1,1
1921

from 0,0,1 looking down to 0,0,-1
1922

As you can see the faces are correct: RED is pointing toward positive X, GREEN is pointing toward positive Y and BLUE is pointing toward positive Z.
For some reason though the orientation of the faces is not correct.
Now I could just "make it work", but I would like to understand the logic of what the opengl call expects from the data.

As much as I looked around, I couldn't find any thorough description of how the faces should be organized.

Thanks in advance for your reply,

Paolo

PaoloS
07-05-2015, 04:26 PM
I found something very interesting: this is a gpu capture of a cubemap used in the cubemap opengl example from the OpenGL superbible 6:

1923

As you can see, even in the profiler the cubemap is "upside down" with respect as you are normally used to see it.

For clarity, these are the faces:

1924

GClements
07-05-2015, 05:21 PM
As much as I looked around, I couldn't find any thorough description of how the faces should be organized.
Section 8.13 of the OpenGL 4.5 specification (https://www.opengl.org/registry/doc/glspec45.core.pdf) has Table 8.19:


Major Axis Direction Target sc tc ma

+rx TEXTURE_CUBE_MAP_POSITIVE_X -rz -ry rx
-rx TEXTURE_CUBE_MAP_NEGATIVE_X rz -ry rx
+ry TEXTURE_CUBE_MAP_POSITIVE_Y rx rz ry
-ry TEXTURE_CUBE_MAP_NEGATIVE_Y rx -rz ry
+rz TEXTURE_CUBE_MAP_POSITIVE_Z rx -ry rz
-rz TEXTURE_CUBE_MAP_NEGATIVE_Z -rx -ry rz


The sc and tc columns give the cube-space axes corresponding to the s and t axes within the face.

Alfonse Reinheart
07-05-2015, 07:10 PM
Here's a picture of how the images look. (http://alfonse.bitbucket.org/oldtut/Texturing/CubeMapAxes.svg)

PaoloS
07-06-2015, 07:42 PM
Thanks Alfonse and GClements. I missed that part in the spec ... :(
Thank you.