Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Trouble with directional lighting.

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    2

    Trouble with directional lighting.

    Hi everyone!
    I have a trouble with computing directional light in vertex shader. Does anyone can help me out? I so appriciate with your helps.
    This is my vertex shader code:

    attribute vec3 normal;
    attribute vec3 coord3d;
    uniform mat4 m;
    uniform mat4 v;
    uniform mat4 p;
    varying vec3 color;
    uniform mat3 m3x3_trans_inv;

    struct lightSource {
    vec4 position;
    vec4 diffuse;
    };

    struct masterial {
    vec4 diffuse;
    };

    lightSource light0 = lightSource(
    vec4( 0.0, 1.0, 2.0, 1.0),
    vec4( 1.0, 1.0, 1.0, 1.0)
    );
    masterial obj_mst = masterial(
    vec4( 0.9, 0.9, 0.9, 1.0)
    );


    void main () {
    mat4 mvp = p*v*m;
    vec3 lightDirection;
    if( light0.position.w == 0.0)
    {
    lightDirection = normalize( vec3( light0.position));
    }
    else
    {
    lightDirection = normalize( vec3( light0.position - m * vec4( coord3d, 1.0)));
    }

    vec3 normalDirection = normalize( m3x3_trans_inv * normal);
    vec3 diffuseReflection = vec3( light0.diffuse) * vec3( obj_mst.diffuse) * max( 0.0, dot( normalDirection, lightDirection));
    vec4 newPosition = vec4( coord3d, 1.0);
    gl_Position = mvp * newPosition;
    color = diffuseReflection;
    }
    But the result is like this:

    ht tp://s815.photobucket.com/user/PCthanyeu/media/suzanne.png.html

    I try hard to figure out but I can't. Sorry for picture link, because I haven't permission to post full link.

  2. #2
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    2
    anyone :{ .

Posting Permissions

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