lighting problem

Has anyone here ever had intermittent problems with lighting? I’ve written a small demo of a few balls spinning around, and occasionally a frame will either become extremely bright (the objects become almost completely white), or really dark. The balls are being drawn using gluSphere() with material properties set using glMaterialfv(). I have ruled out several possible problems:

i) The normals are correct - after all, they are generated by gl.
ii) I’m not incorrectly using the GL_PROJECTION matrix mode to set the camera position.
iii) I don’t use glScalef(), so I don’t think the normals are being stretched. I tried enabling GL_NORMALIZE, but this did not help.

The worrying thing is that the problem is intermittent, and I can’t think of any reason it does not occur every frame. This also happens on several different machines running different OS’s (win9x, 2k, and xp).

Any suggestions?

Jimmi

p.s. I have read immy’s post on the advanced board, which may be a similar problem, but did not find a solution there.

What do you mean by normals are created by opengl?

did u read the faq?, lots of advice there
perhaps youre not updating the lights position after every time u position the ‘camera’
if the sphere is the same colour overall ie all black,all grey,all white. then u are supplying differnt normals for each vertice

Hi Mancha,
I am using quadrics to render the spheres with code similar to this:

GLUQuadric* quad = gluNewQuadric();
gluQuadricDrawStyle(quad, GLU_FILL);
gluQuadricOrientation(quad, GLU_OUTSIDE);
gluQuadricNormals(quad, GLU_SMOOTH);

gluSphere(quad, 1.0, 20, 20);

gluDeleteQuadric(quad);

gluQuadricOrientation and gluQuadricNormals() define the direction of the generated normals (inside or outside) and how they are shaded (smooth, flat etc.). In this case you don’t need to specify your own normals using glNormal3f() because the quadric object generates them for you.

jimmi

Hi Zed,
I don’t think that is the problem I set up my lights every time I render (although I shouldn’t - inefficient ). The spheres may appear very dark or bright, but they are certainly being shaded. I might put a website up with examples.

jimmi

[This message has been edited by jimmi (edited 04-22-2002).]

I’ve put up examples of the problem at www.dcs.shef.ac.uk/~jedge/temp.html I should reiterate that the problem is intermittent - most of the frames are shaded normally, but occaisionally a frame is shaded extremely bright or dark. The only thing I do between frames is change the positions of the objects (rotate them around the origin) or change the manner in which they are shaded (flat/smooth, point/line/fill). After a couple of frames the object will return to normal shading.

jimmi

[This message has been edited by jimmi (edited 04-22-2002).]

oops … put in a full stop which screwed the address: www.dcs.shef.ac.uk/~jedge/temp.html

jimmi

What kind of lights are you using, what are their positions and other properties? Directional or positional lights? What attenuation parameters?

The highlights on the spheres seem to indicate multiple lights (otherwise i would expect the highlights to be elsewhere: the highlight on a sphere on the left side of the image should be more to the right than the highlight on a sphere on the right side of the image).

Jean-Marc

Only one point light source to the right of the images, set using the following code:

float pos[] = {1, 1, 1};
float amb[] = {0.6f, 0.6f, 0.6f};

glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, amb);

jimmi

Originally posted by jimmi:
[b]Only one point light source to the right of the images, set using the following code:

float pos = {1, 1, 1};
float amb = {0.6f, 0.6f, 0.6f};

glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glLightfv(GL_LIGHT0, GL_AMBIENT, amb);

jimmi[/b]

Please note: glLightfv expects four parameters for GL_POSITION and GL_AMBIENT, not three…

If the w component of the position is negative, then unpredictable results may appear.

HTH

Jean-Marc

I think this may have been the problem … thanks Jean-Marc.

jimmi