CubeMapping and glsl lighting

Hi all,
I’m using cubemaps for an upcoming project (dome projection) and am having issues getting uniform lighting while dynamically creating each of the faces of the cubemap. In short, the bright and dark areas of my objects do not match up from face to face in the cubemap.

Rather than post my code in its current state, to illustrate the problem I used the ‘DynamicCubeMapping’ sample and changed ‘mSatelliteBatch’ to use a simple glsl shader which calculates lighting (as opposed to the stockShader().color() that the example uses). When that shader is bound to the satellites, the lighting of the objects fails to be uniform between each of the faces of the cube . - Difficult to see, but circled in red is the inconsistency - the bottom portion of the image shows it a bit more obviously from my project :

my frag shader:

    `#version 150
    uniform vec3 lightPos;
    in vec3 vertPosition;
    in vec3 vertNormal;
    in vec2 vertTexCoord0;
    in vec4 diffuse;
    out vec4 oColor;
void main()
{
	vec3 n = normalize(vertNormal);
	vec3 l = normalize(lightPos-vertPosition.xyz);
	float phong = max(dot(n,l),0.0);
	oColor.rgb = vec3(diffuse*((phong)));
	oColor.a = 1.0;
}

and my vert:
#version 150

uniform mat4 ciModelViewProjection;
uniform mat3 ciNormalMatrix;

in vec4 ciPosition;
in vec3 ciNormal;
in vec2 ciTexCoord0;
in vec4 ciColor;
out vec3 vertPosition;
out vec3 vertNormal;
out vec2 vertTexCoord0;
out vec4 diffuse;
out highp vec3 NormalWorldSpace;
void main()
{
	vertPosition = ciPosition.xyz;
	vertNormal = ciNormalMatrix * ciNormal;
	vertTexCoord0 = ciTexCoord0;
	diffuse = ciColor;
	gl_Position = ciModelViewProjection * ciPosition;
	NormalWorldSpace = vec3(ciPosition);
}

As I said, aside from the shader binding, the rest of the code is unchanged from the dynamicCubeMapping sample. Any suggestions as to what I’m missing?

thanks,
Brandon

Make sure both your lightPos, vertPosition and vertNormal are specified in the same coordinate space. Chances are lightPos is in world space, vertPosition is in object space and vertNormal is in view space, because this is what ciNormalMatrix does.

If you choose to use view space throughout, the positions will be different for each of the 6 faces of the cube map.

Alternatively, calculate the view space position of lightPos in your vertex shader (not recommended for performance reasons):

uniform mat4 ciModelView;
uniform mat4 ciViewMatrix;
uniform mat4 ciProjectionMatrix;

...

uniform vec3 lightPosWS;

...

out vec3 lightPosVS;

void main(void)
{
    ...
    vertPosition = ciModelView * ciPosition; // from OS to VS
    lightPosVS = vec3( ciViewMatrix * vec4( lightPosWS, 1.0 ) ); // from WS to VS
    
    gl_Position = ciProjectionMatrix * vertPosition;
}

That did the trick, thanks!