Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Need help with lightning

  1. #1
    Intern Contributor
    Join Date
    Apr 2016
    Berlin / Germany

    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):
    Code :
    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?


  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Quote Originally Posted by art-ganseforth View Post

    Code glsl:
    vec3 LightVec = normalize( gl_LightSource[0] - vec3(In.Vertex));
    float intens = max(dot (-normal, vec3 (LightVec)), 0.0);
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts