I'm having problems getting a cubemap to work properly in a fragment shader (Cg). Each of the six textures works properly if I load them as individual textures, so I know the images are loading properly. I think my problem has something to do with the application side of things.
Does anyone see anything in particular that would cause this to result in solid black in the shader? (BTW, *YES* the shader compiles and executes... if I change the shader to explicitly set the alpha of the lookup to something other than 1.0, it becomes semi-transparant black).
Relevent snippets from app source:
// This is where the cube map is generated...
glGenTextures(1, &cubeMap);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMap);
//glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
//glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
for (int i = 0; i < 6; i++)
setupCubemapTarget(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, envTex);
cgGLSetTextureParameter(cubeMapParam, cubeMap);
cgGLSetManageTextureParameters(context, CG_TRUE);
// Here's what is in the function that sets up each face of cube map
// where target and srcImg are arguments passed above
glTexImage2D(
target, 0, GL_RGBA, srcImg->getWidth(), srcImg->getHeight(),
0, GL_RGBA, GL_UNSIGNED_BYTE, srcImg->getData());
Is the cgGLSetTextureParameter() call the correct way to setup a cubemap sampler in Cg? The runtime side of things isn't very well documented, but I assumed it was setup like any other texture.
The fragment program--at least the part that is broken--is very straightforward...
float4 main(in FRAGDATA input,
uniform float3 lightPos,
uniform float3 cameraPos,
uniform samplerCUBE envMap) : COLOR0
{
// ... do some stuff until eventually...
// Refract the ray...
float refRay = refract(view, normal, val);
color = texCUBE(envMap, refRay);
color.a = 1.0;
return color;
}
If I uncomment the glTexParameter lines in the cubemap setup, I get 2 distinct colors (I am refracting a sphere at the moment), but nothing like the actual texture lookup.
Any ideas what might be wrong? Thanks in advance for any help you guys (and gals) can offer.