Results 1 to 10 of 10

Thread: Specular Highlights

  1. #1
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Specular Highlights

    I've got a Problem with my specular highlights. My situation:

    An object (like an egg), my camera(which I set with gluLookAt(...) and a positional light ( light-egg-camera angle is 45 degrees in xz-plane). I turn the camera around the egg (the light alway this 45 degrees next to the camera). The problem is, that the highlights are computed someway wrong. It appears not always on the lighten side of the egg. Sometimes it appears on the dark side. Here some code:

    m_Ambient[0] = 0.0f;
    m_Ambient[1] = 0.0f;
    m_Ambient[2] = 0.1f;
    m_Ambient[3] = 1.0f;
    m_Diffuse[0] = 1.0f;
    m_Diffuse[1] = 1.0f;
    m_Diffuse[2] = 1.0f;
    m_Diffuse[3] = 1.0f;
    m_Specular[0] = 1.0f;
    m_Specular[1] = 1.0f;
    m_Specular[2] = 1.0f;
    m_Specular[3] = 1.0f;
    m_Shinyness = 100.0f;

    for the material of the egg.
    plus in the egg-render-function
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, m_Ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, m_Diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, m_Specular);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, m_Shinyness);

    for the light:
    m_Diffuse[0] = 1.0f;
    m_Diffuse[1] = 1.0f;
    m_Diffuse[2] = 1.0f;
    m_Diffuse[3] = 1.0f;
    m_Specular[0] = 1.0f;
    m_Specular[1] = 1.0f;
    m_Specular[2] = 1.0f;
    m_Specular[3] = 1.0f;

    plus

    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
    glLightfv(GL_LIGHT0+m_lnumber, GL_POSITION, m_params);
    glLightfv(GL_LIGHT0+m_lnumber, GL_DIFFUSE, m_Diffuse);
    glLightfv(GL_LIGHT0+m_lnumber, GL_SPECULAR, m_Specular);
    glEnable(GL_LIGHT0+m_lnumber);


    Does anybody have an idea...?

  2. #2
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Re: Specular Highlights

    I forgot: I do the gluLookAt(...) before the rendering.

  3. #3
    Member Contributor
    Join Date
    May 2001
    Location
    Cheltenham,Gloucestershire,England
    Posts
    59

    Re: Specular Highlights

    hi there,

    try removing
    glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

    hope it helps

    Mark

  4. #4
    Member Contributor
    Join Date
    Oct 2000
    Location
    Helsinki, Finland
    Posts
    59

    Re: Specular Highlights

    Originally posted by qwert:
    I forgot: I do the gluLookAt(...) before the rendering.
    Yeah, I never quite seemed to get the lighting work properly when using gluLookAt(). Instead,
    before rendering objects call glTranslate and glRotate to move the objects (camera) and see if it works. Worked for me

    Redbook has a nice piece of code in chapter 3 called 'void polarView(...)'.

    - Niko

  5. #5
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Re: Specular Highlights

    And how can I do that if I only know the coordinates of my eyepoint and those of the center? I have no angles.

  6. #6
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Re: Specular Highlights

    I've got something, but it behaves completely wrong.

    void COpenGLCtrl::OwnLookAt(double eyex, double eyey, double eyez, double centerx, double centery, double centerz)
    {
    double xzangle=0,yzangle=0,dx=eyex-centerx, dy=eyey-centery, dz=eyez-centerz;

    ActEyeDist(); <-calculates the distance

    xzangle = atan2(dz,dx);
    if (xzangle<0)
    xzangle += 2*PI;
    yzangle = PI*0.5 - asin(dy/m_dEyeCenter);


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    glTranslated(0,0,-m_dEyeCenter);
    glRotated(-ONERAD*xzangle,1,0,0);
    glRotated(ONERAD*yzangle,0,0,1);

    glTranslated(centerx,centery,centerz);
    }


    I really don't know how to get it work...

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Specular Highlights

    Using gluLookAt is perfectly fine and does not in itself mess up lighting. It is only doing the same matrix transformations that you are now trying to do explicitly.
    The most common causes of lighting problems would be incorrect normals, and incorrect light position. For example you say you do a gluLookAt before rendering. Do you also set the light position after using gluLookAt? You need to every frame of course.

  8. #8
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Re: Specular Highlights

    It's kind of strange...
    Now, my camera movement is completely messed up, but the specular highlights are shown correct.
    If I use gluLookAt(...) instead of my own function, the ligthing is wrong again. I change only the gluLookAt(...) by OwnLookAt(...).

  9. #9
    Member Newbie
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    47

    Re: Specular Highlights

    Ok DFrey, I found it, you were right . gluLookAt really don't mess anything up. When I called glulookAt, I was actually in the prjection-matrix and not in rhe modelview-matrix as it should be. Maybe you made the same mistake, niko.

    Thanks very much for your help, that was a lousy one.

    regards qwert

  10. #10
    Member Contributor
    Join Date
    Oct 2000
    Location
    Helsinki, Finland
    Posts
    59

    Re: Specular Highlights

    Originally posted by qwert:
    When I called glulookAt, I was actually in the prjection-matrix and not in rhe modelview-matrix as it should be. Maybe you made the same mistake, niko.
    Right, so I did [bangs head on the table]. But anyways, because of that mistake I now know the math to do my own 'gluLookAt()'. Sweet.

    - Niko

Similar Threads

  1. Possible to reflect specular highlights?
    By PickleWorld in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 04-16-2005, 03:57 PM
  2. faking specular highlights?
    By ewan_s in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-11-2004, 04:39 PM
  3. fog and specular highlights problem
    By Phoenix in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 07-17-2002, 01:43 AM
  4. problem on specular highlights
    By Dong Ke in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-11-2001, 02:28 PM
  5. Specular highlights and texturing.
    By Siwko in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 05-03-2001, 07:36 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