Does the directional spotlight work correctly on the spheres?

When i use from the directional spotlight that only emits part of the sphere-I have adjusted the cutoff angle to 30 degrees-, the result is too bad. What’s the problem?
-Ehsan-

OpenGL’s standard lighting is per vertex.
If that looks bad it’s normally because the underlying geometry is too coarse. Use a finer tesselation on your geometry.

Another approach is to do lighting on fragment level. You can search the forum for Phong shaders.

What Relic said.
Compare :
http://www.csie.ntu.edu.tw/~r89004/hive/perpixel/images/vertex_lighting_3.jpg
http://www.csie.ntu.edu.tw/~r89004/hive/perpixel/images/vertex_lighting_10.jpg

The problem that you have mentioned refers to the OpenGL lighting and so the spotlight. But my problem is only about the spotlight. The boundary of the dark and shining parts of the sphere extremely depends on the polygons of the sphere and so isn’t like a curve or line–This boundary is jagged.If i use from more and more polygons in my sphere, i can get the better result;But not a good result.
-Ehsan-

Are you sure that you did’nt fall into the common OpenGL pitfall #2?

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

If not, a screenshot of you problem would help a lot.

The problem is definitely vertex lighting. It is a variation of pitfall #2 that’s peculiar to cutoff, basically it can’t be fixed without extreme tesselation and actually can look worse with moderate tesselation that you might assume would look OK.

Spotlight cutoff is a binary thing, for each vertex it is in the cone or outside the cone, when that happens on any polygon mesh the boundary is obvious and shows the underlying tesselation pattern as a pronounced sawtooth effect in places.

There is a cosine distribution and an exponent for illumination distribution in a spotlight, but the actual cutoff value is a sharp boundary. The more triangles you have the smaller the scale of the artifact but it is always there until you have a vertex per pixel. It is really a design flaw in spotlights and it isn’t limited to spheres.

SGI introduced an improvement with their fragment lighting spec (now defunct) that had two cutoff angles that defined a fadeout region instead of a sharp transition. That isn’t available to you so OpenGL lacks this and there’s not much you can do about the problem.

There are two possible solutions:

  1. Increase GL_SPOT_EXPONENT to narrow the beam of the spotlight and fade it out away from the center, this will help a bit but cannot fix the problem.

  2. Use a projected texture to do spotlights with a texture unit instead of vertex lighting.

  3. increase the subdivision on the illuminated surfaces dramatically, this probably isn’t practical but you can try it as a test just to prove (for your own satisfaction) that it is the tesselation across the cutoff boundary that is causing the artifacts.

My opinion is that this is a spec oversight in the initial 1.0 lighting design. I suspect that the cosine for the spotlight angle should have been normalized between the center vector and the cutoff angle. i.e. the cutoff should have been scaled to 90 degrees pre cosine and then run through the exponent giving all spotlights a lot of control over the angular attenuation within the cone instead of within the hemisphere independent of the cone, the second choice would have been an additional cutoff angle to define the penumbra region. Neither was done so per vertex spotlight cutoff is about as useful as a chocolate teaspoon :-), and you’re stuck with it.

Now that is what I call a thorough explanation.

Thanks dorbie.

Whats wrong with chocolate teaspoons