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…?

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

hi there,

try removing
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

hope it helps

Mark

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

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

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…

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.

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(…).

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

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