Results 1 to 9 of 9

Thread: Specular light not directional?

  1. #1
    Guest

    Specular light not directional?

    my problem is this, i set up a light, and just goofing around i make it(the light) rotate and translate with the mouse, heres the odd thing, the specularity only moves positionally?
    if i change the light direction, the specularity stays put? WTF?
    is this supposed to happen? is there a work around other than putting a huge diffuse?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Specular light not directional?

    that is queer. of course there's a workaround : there must be a problem inside of your code. Could you post part of it ?

  3. #3
    Guest

    Re: Specular light not directional?

    most assuredly,

    GL Init Code
    Code :
     
    GLfloat	Ambient_Light[] = {0.1f,0.1f,0.1f,1.0f};
    GLfloat Diffuse_Light[] = {0.3f,0.3f,0.3f,1.0f};
    GLfloat Specular_Light[] = {0.5f,0.5f,0.5f,1.0f};
    GLfloat Specular_Reflection[] = {1.0,1.0,1.0,1.0f};
    static GLfloat Light_Position[] = {0.0,0.0,1.0,1.0};
    static GLfloat Light_Direction[] = {-0.0,0.0,-1.0};
     
    void GL_Init(void)
    {
    	glClearColor(0.5f,0.5f,0.5f,1.0f);
    	glClearDepth(1.0f);
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	glShadeModel(GL_SMOOTH);
    	glFrontFace(GL_CW);
    	glEnable(GL_CULL_FACE);
    	glEnable(GL_DEPTH_TEST);
     
    	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Ambient_Light);
     
    	glLightfv(GL_LIGHT0,GL_AMBIENT,Ambient_Light);
    	glLightfv(GL_LIGHT0,GL_DIFFUSE,Diffuse_Light);
    	glLightfv(GL_LIGHT0,GL_SPECULAR,Specular_Light);
    	glLightfv(GL_LIGHT0,GL_POSITION,Light_Position);
    	glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Light_Direction);
    	glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,90.0f);
    	glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,128.0f);
     
    	glEnable(GL_LIGHT0);
    	glEnable(GL_COLOR_MATERIAL);
    	glColorMaterial(GL_FRONT,GL_AMBIENT);
     
    	glMaterialfv(GL_FRONT,GL_DIFFUSE,Specular_Reflection);
    	glMaterialfv(GL_FRONT,GL_AMBIENT,Specular_Reflection);
    	glMaterialfv(GL_FRONT,GL_SPECULAR,Specular_Reflection);
    	glMateriali(GL_FRONT,GL_SHININESS,128);
    	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
    	glEnable(GL_LIGHTING);
    }
    the lighting draw code

    the Scroll/angles are float point values alter by the movement of the mouse.

    Code :
     
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    	glLoadIdentity();
     
    glPushMatrix();
    		glLoadIdentity();
    			glTranslatef(XScroll,YScroll,ZScroll);
    			glRotatef(xangle,1.0f,0.0f,0.0f);
    			glRotatef(yangle,0.0f,1.0f,0.0f);
    			glLightfv(GL_LIGHT0,GL_POSITION,Light_Position);
    			glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,Light_Direction);
     
    		glPopMatrix();
     
    		glTranslatef(-0.23,0.1,-1.0);
    		glRotatef(90,0.0,1.0,0.0);
     
    		glCallList(board);
    the List being drawn, doesn't really alter anything

    this enough?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Specular light not directional?

    ???
    What's this glPopMatrix doing here ?
    It cancels all matrix transformations done above !

    Try calling glPopMatrix _after_ the glCallList.

    Does it work now ?
    If not, try replacing the glCallList by the equivalent opengl code. (ie, the code between glNewList and glEndList).

  5. #5
    Guest

    Re: Specular light not directional?

    >Try calling glPopMatrix _after_ the glCallList.

    Does it work now ?
    <

    unfortunatly if i do this the object(board) will also be rotated/translated with the light.

    >
    If not, try replacing the glCallList by the equivalent opengl code. (ie, the code between glNewList and glEndList).
    <

    nope... still nothing.

    another oddity, if i set GL_LIGHT_MODEL_LOCAL_VIEWER to true as in the code shown the specularity no longer works positionally either?

    im totalally at a loss.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Specular light not directional?

    I've read more carefully your first post. so, the light's position is ok, but you have a problem with the light's direction.

    I'd like to know : when you change the initial value of Light_Direction, does it change the specularity ?
    Also, could you post me your whole code by e-mail ?

    Also, here's an ugly trick that will necessarily work : instead of applying opengl transformations to the light, compute by yourself (using sine and cosine) the transformed light's direction. (But I admit that it isn't a wholly satisfactory answer).

  7. #7
    Guest

    Re: Specular light not directional?

    >
    I'd like to know : when you change the initial value of Light_Direction, does it change the specularity ?
    <

    the initial specularity makes no difference.

    >
    Also, could you post me your whole code by e-mail ?
    <

    its several thousand lines(lwo loader for the model/file handler/win32 handler/utilities). i'll try and work out a smaller version minus the loader/files/utilities/ maybe win32 handling, shouldn't take to long, though ive been somewhat preoccupied.

    >
    Also, here's an ugly trick that will necessarily work : instead of applying opengl transformations to the light, compute by yourself (using sine and cosine) the transformed light's direction. (But I admit that it isn't a wholly satisfactory answer).
    <

    i don't know how much help this wold be if even the inital direction doesn't work.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Jul 2001
    Posts
    352

    Re: Specular light not directional?

    Eureka !!!

    Forget all what I've previously said !

    It's absolutely normal that the specularity does _not_ depend on the spot's direction.
    Specularity = the surface reflecting the light like a mirror.
    Go to a mirror in your bathroom. Take a pocket lamp with you. Does the image of the pocket lamp in the mirror depend on its direction ? No ! it depends on
    1) position of the pocket lamp
    2) position of your eye (or eyes if you're healthy)
    3) normal vector of the mirror

    Got it ?

  9. #9
    Guest

    Re: Specular light not directional?

    aaahhh, yes. i see, in order for the light to be specular it must be reflected directly, therefore it was reflecting directly along the specified normals, since only the light was changing and not the normals the specularity did not move.

    thanks a bunch!

Similar Threads

  1. Directional Light
    By yuzi in forum COLLADA
    Replies: 1
    Last Post: 09-27-2010, 03:03 PM
  2. directional light specular
    By somboon in forum OpenGL: General
    Replies: 4
    Last Post: 05-05-2010, 03:20 PM
  3. Specular Lighting with directional lights
    By welford in forum OpenGL: GLSL
    Replies: 4
    Last Post: 05-13-2009, 04:37 PM
  4. Specular Highlights and Directional lights
    By doc_colgate in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-06-2002, 01:04 AM
  5. Directional Light
    By Xero_Tolerance in forum OpenGL: Advanced Coding
    Replies: 18
    Last Post: 04-16-2002, 12:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean