PDA

View Full Version : Specular Highlights



qwert
08-22-2001, 11:34 PM
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...?

qwert
08-22-2001, 11:35 PM
I forgot: I do the gluLookAt(...) before the rendering.

MButchers
08-23-2001, 12:59 AM
hi there,

try removing
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);

hope it helps

Mark

niko
08-23-2001, 01:34 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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

- Niko

qwert
08-23-2001, 04:22 AM
And how can I do that if I only know the coordinates of my eyepoint and those of the center? I have no angles.

qwert
08-23-2001, 04:42 AM
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...

DFrey
08-23-2001, 04:48 AM
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.

qwert
08-23-2001, 05:16 AM
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(...).

qwert
08-23-2001, 05:36 AM
Ok DFrey, I found it, you were right http://www.opengl.org/discussion_boards/ubb/wink.gif. 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

niko
08-23-2001, 06:02 AM
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. http://www.opengl.org/discussion_boards/ubb/biggrin.gif

- Niko