Hello,
Still working on cube maps, I need to use multitexturing to apply diffuse and specular colors using diffuse and specular reflection cube maps.
First I try to do this without render to texture using a fbo.
I use a very simple GLSL shader to compute lighting:
vertex shader:
varying vec3 normal;
varying vec3 position;
uniform vec3 eyePos;
void main()
{
normal = normalize(gl_NormalMatrix * gl_Normal);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_Position = ftransform();
position = gl_Position.xyz;
}
fragment shader:
uniform samplerCube cubeMapD;
uniform samplerCube cubeMapS;
uniform vec3 eyePos;
varying vec3 normal;
varying vec3 position;
void main()
{
vec3 eyeDir=normalize(eyePos-position);
vec3 texCoords=normalize(eyeDir-2.0*dot(normal, eyeDir)*normal);
gl_FragColor = vec4(1.0, 0.6, 0.1, 1.0)*textureCube(cubeMapD, texCoords)/3.0 + textureCube(cubeMapS, texCoords)/5.0;
}
You see that in this code I compute twice the cube map texture coordinates but the classic way to do this does not work :
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
whereas I generate automatically the texture coordinates doing this after loading the cube map texture using glTexImage2D:
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glEnable(GL_NORMALIZE);
this is the render I obtain when I use texCoords in the textureCube function:
this what I obtain when I use gl_TexCoord[0].stp in the textureCube function:
seeing this last picture, the texture coordinates clearly seem to not be generated…
Does someone see the problem?
Another strange thing is when I set up the texture units from TU1 to TU0 like this:
glActiveTexture( GL_TEXTURE1_ARB );
glDisable(GL_TEXTURE_2D);
skyBoxS->bind(); // specular reflection map
glActiveTexture( GL_TEXTURE0_ARB );
glDisable(GL_TEXTURE_2D);
skyBoxD->bind(); // diffuse reflection map
I works, but when I do the same from TU0 to TU1 I see simply nothing in the framebuffer! I don’t understand why…
Thank you for your help.