Need help with lightning


i probably need some help with a strange beaviour of a lightning-function in a fragment-shader.

This is the relevant shader-code (a bit simplified):

in Data {
    vec4 Vertex;
    vec3 Normal;
    vec4 Position;
    vec4 TexCoord;
} In;

out vec4    color;

vec3    normal          = In.Normal;
vec3    LightVec        = normalize( gl_LightSource[0] - vec3(In.Vertex));


void main() {


    // --- Create Bumpmap ----------------------------------
    if (uniBumpFact >  0) normal = normal + bump(Texture0, uniBumpFact) ;

    // --- Shadow ------------------------------------------
    float intens    = max(dot (-normal, vec3 (LightVec)), 0.0);
    color           = color  * intens;


The problem is that the light on the back side of the vertices is somehow inverted, so the shadow on an object which is drawn fron right to left, appears on the wrong side.

Does anyone have an idea what the problem might be?


This looks really strange.

You want both of these vectors to point away from the surface, and this appears to have one pointing toward it.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.