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: Basic lighting not working

  1. #1
    Junior Member Newbie
    Join Date
    May 2017

    Basic lighting not working

    Again, after few more attempts, I've been able to resolve this problem as well (lol). Sorry for yet another resolved post.
    Last edited by Elijah1920; 05-09-2017 at 01:28 AM.

  2. #2
    Member Regular Contributor
    Join Date
    May 2016
    your VAO "normals" is not connected to the correct vertex shader attibute location:
    Code :
    glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 0, 0);

    your vertex shader transforms the normals not correctly, you need to transform the position into 2 different coordinate systems: "world space" to do th lighting calculation, and "clip space" for gl_Position
    Code :
    gl_Position = MVP * vec4(in_position, 1);
    vec3 transformed_position = (M * vec4(in_position, 1)).xyz;
    vec3 transformed_normal = (M * vec4(in_normal, 0)).xyz;

    then you need to pass transformed_position and transformed_normal to the fragmentshader

    what your fragmentshader does isnt actually clear. try to write is more clearly to understand, like:
    Code :
    // get basic fragment color
    vec3 Kd = vertexcolor * texture(tex1, texcoord);
    // basic light parts
    vec3 Iambient = vec3(0.2, 0.2, 0.2); // for example
    vec3 Idiffuse = vec3(0, 0, 0);
    vec3 Ispecular = vec3(0, 0, 0);
    // do some calculations here ...
    // final fragment color
    finalcolor = Iambient * Ka + Idiffuse * Kd + Ispecular * Ks;

    some arent distinguishing between Ka and Kd and instead use simply Kd like that:
    // final fragment color
    Code :
    finalcolor = (Iambient + Idiffuse) * Kd + Ispecular * Ks;

Tags for this Thread

Posting Permissions

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