# Cubemap faces rotation in GS shader

I Can't get correct rotations for cubemap faces. Thats should come to geometry shader, from camera "view" matrix I want make 6 faces for my cubemap, but seems I can't get it correctly...

My first guess that camera 'indent' matrix faces to '-z':

// +X //
rot[0] = (mat4 (   0   ,  0    , -1.0  , 0 ,
0   ,  1.0  , 0     , 0 ,
1.0 ,  0    , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
// -X /
rot[1] = (mat4 (   0   ,  0    , 1.0   , 0 ,
0   ,  1.0  , 0     , 0 ,
-1.0 ,  0   , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//+Y/
rot[2] = (mat4 (   1   ,  0    , 0     , 0 ,
0   ,  0    , 1.0   , 0 ,
0   ,  -1.0 , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//-Y/
rot[3] = (mat4 (   1   ,  0    , 0     , 0 ,
0   ,  0    , -1.0  , 0 ,
0   ,  1.0  , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//+z/
rot[5] = (mat4 (   -1  ,  0    , 0     , 0 ,
0   ,  1    , 0     , 0 ,
0   ,  0    , -1    , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//-z/
rot[4] = (mat4 (   1   ,  0    , 0     , 0 ,
0   ,  1    , 0     , 0 ,
0   ,  0    , 1     , 0 ,
0   ,  0    , 0     , 1.0 )) ;


EDIT: Correct for me: Using LookAt magic, finaly find correct order of rotation: NOTE: thats RH-coordinate system Column-major order (glsl default)

// +X
rot[0] = (mat4 (    0   ,  0    , 1.0   , 0 ,
0   ,  1.0  , 0     , 0 ,
-1.0 ,  0   , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
// -X /
rot[1] = (mat4 (    0   ,  0    , -1.0  , 0 ,
0   ,  1.0  , 0     , 0 ,
1.0 ,  0    , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//+Y/
rot[3] = (mat4 (    -1  ,  0    , 0     , 0 ,
0   ,  0    , -1.0  , 0 ,
0   ,  -1.0 , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//-Y/
rot[2] =(mat4 (     -1  ,  0    , 0     , 0 ,
0   ,  0    , 1.0   , 0 ,
0   ,  1.0  , 0     , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//+z/
rot[4] = (mat4 (    -1  ,  0    , 0     , 0 ,
0   ,  1    , 0     , 0 ,
0   ,  0    , -1    , 0 ,
0   ,  0    , 0     , 1.0 )) ;
//-z/
rot[5] = (mat4 (    1   ,  0    , 0     , 0 ,
0   ,  1    , 0     , 0 ,
0   ,  0    , 1     , 0 ,
0   ,  0    , 0     , 1.0 )) ;


## 1 Answer

To fix these kinds of issues create a test cubemap clearly marking each face directions and +/- XYZ you can then figure out which one(s) is(are) pointing the wrong way.

• hm, seems that not only one issue, I make sphere with cubemap, project it using normals,but parts of cubemap are not connected – Alexsey Shestacov Jan 2 '15 at 20:04
• You should make a new question with a screenshot of this second problem. – Stephane Hockenhull Jan 3 '15 at 16:45
• Seems solved (mostly), but there new fun with convoling cubemap in compute shader (calculate SH harmonics), And there new issues. I need also correct reflections on planar surfaces somehow – Alexsey Shestacov Jan 3 '15 at 17:34