3

I'm having a problem with lighting when dealing with really small particles. I'm doing particle-based fluid simulation and am right now rendering the fluid as really tiny polygonized spheres (by really tiny I'm saying about 0.03 units radius for the spheres). The lighting in my scene isn't lighting them how I want and I can't get it to look right. I'm looking for something similar to the soft lighting on the particles in this image... particles with correct lighting

However my particles look like this...

What my particles look like

See how my particles have bright white sections whereas the green particles are just lit up softly and don't have large white hotspots. I know the reason is either the settings for my light or simply the fact that the particles are so small that the light takes up a larger space (is that possible??). My settings for lighting are as follows...

GLfloat mat_ambient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {10.0};
GLfloat light_position[] = {0.0, 0.1, p_z, 1.0};
GLfloat model_ambient[] = {0.5, 0.5, 0.5, 1.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
genpfault
  • 51,148
  • 11
  • 85
  • 139
Nitrex88
  • 2,158
  • 2
  • 21
  • 23
  • http://en.wikipedia.org/wiki/Ambient_occlusion – Ben Jackson Apr 26 '11 at 23:35
  • looks like useful information to know but how would I apply this to my scene? I'm not using shaders and I'm not sure how this would change the settings I have for the light – Nitrex88 Apr 26 '11 at 23:38
  • Applying it is not trivial: That's why I didn't make it an answer. To get softer shadows in general you could try adding multiple lights (eg 8 lights each 1/8 intensity) spread over a small area near your current source to soften the edges. – Ben Jackson Apr 26 '11 at 23:43
  • that's a good idea I'll try adding more lights. thanks! – Nitrex88 Apr 26 '11 at 23:46

3 Answers3

2

Thanks for all the suggestions everyone but unfortunately nothing worked. I sat down with my graphics professor and we determined that this problem was in fact related to the size of the particles and the fact that OpenGL treats directional lights as being infinitely far away from any vertex. The proper way to fix it was modifying the constant attenuation of the light source like this...

glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 10.0);

Now my particles look like this...

enter image description here which is exactly the lighting I was after!

Nitrex88
  • 2,158
  • 2
  • 21
  • 23
1

It looks like you need to turn down the specular component of your material, turn down the ambient a bit, and add some diffuse shading (GL_DIFFUSE). Consider also positioning the light behind the the viewport/camera.

leohutson
  • 95
  • 2
  • 10
1

The size of the particles isn't an issue - you're over-saturating your colours.

For each RGB component, you should have ambient + diffuse + specular <= 1.0

For a scene like this I'd expect ambient to be no more than 0.1 or so, diffuse of 0.6 or so, and specular making up the rest.

Alnitak
  • 334,560
  • 70
  • 407
  • 495