View Full Version : Normalization cube maps

02-25-2006, 06:06 AM

I am trying to implement the Example 8-1 and 8-2 (C8E1v_bumpWall and C8E2f_bumpSurf shader programs) from the Cg Tutorial book and I fail at initializing the normalization cube map.

The fragment shader calls for a "uniform samplerCUBE" and I try to pass the NormalizationMap.dds because the book said it is a normalization map I can use. But all I get is white color all over the rectangle I try to texture - without the normalization cube map (i.e. just with the Brick.dds normal map) I do see the normal map and everything is fine.

How am I to load a normalization cube map into OpenGL so that Cg can use it? I am using DevIL and do it like this:

static void myInit (void) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

// initialize devIL

textureIdx0 = ilutGLLoadImage("Brick.dds");
textureIdx1 = ilutGLLoadImage("NormalizationMap.dds");



static void initCG() {
cgNormalMap = cgGetNamedParameter(cgFragmentProgram1, "normalMap");
cgNormalizeCube = cgGetNamedParameter(cgFragmentProgram1, "normalizeCube");
cgGLSetTextureParameter(cgNormalMap, textureIdx0);

cgGLSetTextureParameter(cgNormalizeCube, textureIdx1);
}Do I have to load the cube map differently? It probably isn't a texture coordinates problem, because when I load just the normal map everything seems fine.

I know that this isn't just an OpenGL problem, but it lies directly on the line between Cg and OpenGL so I didn't know where else to turn. I posted this also on the Cg developer forum and hope that someone will be able to help me. Any help will be appreciated.

02-26-2006, 01:28 AM
It's difficult to say what is going on because of the library calls you're making, all those il* calls that really don't have anything to do with OpenGL but obviously include a lot of OpenGL calls.

Same with the cg stuff really, it's obviously attribute/resource setup for a shader. The only OpenGL code apparent is set clear color to black, enable depth test and disable texture.

02-26-2006, 02:42 AM
Ok, let me rephrase ... I want to use a normalization cube map saved in a single .dds file in Cg. For that I need to load it in OpenGL and then pass it on to Cg - OpenGL will have its texturing disabled because Cg takes care of that. I am fairly certain that the passing of the texture to Cg works. Now if I wasn't to use the DevIL stuff to load the .dds as a normalization cube map, how would I do it in OpenGL only?

Keep in mind that I do not have 6 different images for each side of the cube and therefore cannot create a cube map "the usual way".

Any help will be appreciated.

02-26-2006, 09:39 AM
One question springs to mind, is DevIL smart enough to recognize the cubemap and load it to the cubemap face texture targets? I doubt it but I could be wrong.

You do know what's in a normalization cubemap right? Each point just represents the color of a unit normal in that direction. As such you don't really need to load it, you can generate the cubemap procedurally quite easily. Treat each image like it's +1.0 to -1,0 on the face of a unit cube and the missing (major) axis is fixed at 1.0, normalize the vector and convert the range -1->+1 to 0->1.0, then store that pixel as an rgb triplet in your chosen format, next load the image array to the appropriate texture face. Rinse & repeat for each face, transposing axes & switching signs accordingly.

You shouldn't need to load the images from disk.

02-26-2006, 10:39 AM
From the source code of DevIL, it seems it supports loading of cubemap textures, so this can not be the problem...

But I agree with dorbie, you shouldn't be loading a texture from file that can easily be generated on the fly.

03-01-2006, 12:05 AM
Ok, thx for the tipps. I will try to create the cube map procedurally.