Hello everyone,
I’ve been trying to load Paul Debevec’s light probes (actually the cross cube textures) into my program using GL_RGB32F_ARB internal format. To test my code, I have exactly similar code (but that’s my own opinion) for loading GL_RGB (GL_UNSIGNED_BYTE) internal format. Also, I have added functions that help me load individual faces to check my image loader.
To use this texture, right now, I am just using a simple shader program which does a textureCube using the current fragment’s normal(!).
The problem is, that this reflective shading works with the ubyte texture I am using, but shows up as black (indicating that no color is being read in from the texture) when I use the floating point format texture. I am really not sure what’s going on, may be I am missing a subtle detail I need to pay attention to, or something’s so obviously incorrect that I am overlooking.
Also, I tried using the same technique to load the image data into a GL_TEXTURE_2D just to check if my image loading is actually working. The textures show up fine.
Even if I am screwing up something really bad, at least something should show up. Below is the code I am using to load the textures.
Thanks,
verma
glPushAttrib (GL_ENABLE_BIT); check_gl ();
glEnable (GL_TEXTURE_CUBE_MAP); check_gl ();
// I find it hard to get my head around image orienation and stuff, so most of the adjustments to flips and loads have been done
// using hit and trial. But if you sit and get the image orientation right in your head, it makes sense
// generate our texture
glGenTextures (1, &texId); check_gl();
glBindTexture (GL_TEXTURE_CUBE_MAP, texId); check_gl ();
if (imageType == IMAGE_TYPE_PFM) {
fprintf (stderr, "... performing a floating point texture load.
");
// left, -ve x
fprintf (stderr, "... loading cube face 1
");
__loadSubImage (img, face_img, face_width, face_height, 0, face_height, width, height);
__imgFlipVertically (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
// front, -ve z
fprintf (stderr, "... loading cube face 2
");
__loadSubImage (img, face_img, face_width, face_height, face_width, face_height, width, height);
__imgFlipVertically (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
// right, +ve x
fprintf (stderr, "... loading cube face 3
");
__loadSubImage (img, face_img, face_width, face_height, 2*face_width, face_height, width, height);
__imgFlipVertically (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
//top, +ve y
fprintf (stderr, "... loading cube face 4
");
__loadSubImage (img, face_img, face_width, face_height, face_width, 2*face_height, width, height);
__imgFlipHorizontally (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
// bottom, -ve y
fprintf (stderr, "... loading cube face 5
");
__loadSubImage (img, face_img, face_width, face_height, face_width, 0, width, height);
__imgFlipHorizontally (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
// back, +ve z, its upside down in the image
fprintf (stderr, "... loading cube face 6
");
__loadSubImage (img, face_img, face_width, face_height, face_width, 3*face_height, width, height);
__imgFlipHorizontally (face_img, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA32F_ARB, face_width, face_height, 0, GL_RGB, GL_FLOAT, face_img); check_gl ();
free (img);
free (face_img);
}
else {
fprintf (stderr, "... performing a 8-bit per component load.
");
// do a regular PPM loading
// left, -ve x
fprintf (stderr, "... loading cube face 1
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, 0, face_height, width, height);
__imgFlipVerticallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
// front, -ve z
fprintf (stderr, "... loading cube face 2
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, face_width, face_height, width, height);
__imgFlipVerticallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
// right, +ve x
fprintf (stderr, "... loading cube face 3
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, 2*face_width, face_height, width, height);
__imgFlipVerticallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
//top, +ve y
fprintf (stderr, "... loading cube face 4
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, face_width, 0, width, height);
__imgFlipHorizontallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
// bottom, -ve y
fprintf (stderr, "... loading cube face 5
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, face_width, 2*face_height, width, height);
__imgFlipHorizontallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
// back, +ve z, its upside down in the image
fprintf (stderr, "... loading cube face 6
");
__loadSubImageC (img_c, face_img_c, face_width, face_height, face_width, 3*face_height, width, height);
__imgFlipHorizontallyC (face_img_c, face_width, face_height);
glTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, face_width, face_height, 0, GL_RGB, GL_UNSIGNED_BYTE, face_img_c); check_gl ();
free (img_c);
free (face_img_c);
}
// set some default properties
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); check_gl();
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); check_gl();
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); check_gl();
glTexParameteri (GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); check_gl();
unbindCubeMap ();
glPopAttrib ();
return texId;
Here are the shaders I am using:
// vertex shader
//
varying vec3 normal; // normal in our eye space
void main () {
normal = normalize (gl_NormalMatrix * gl_Normal);
gl_Position = ftransform ();
}
// fragment shader
//
uniform samplerCube cubemap;
varying vec3 normal;
void main (void) {
vec3 n = normalize (normal);
gl_FragColor = textureCube (cubemap, n);
}