I’m having a problem with saw tooth lighting on a 3D gluSphere() that I just can’t seem to figure out or fix. I originally posted this problem inside another post related to drawing distance (http://www.java-gaming.org/forums/index.php?topic=18296.0) but this really should have been its own topic so I’m starting one here.
Here is a picture (sawtoothlight.jpg) showing the issue I’m having:
Here is the source code for this viewer so you can see my poor jogl code:
http://www.zaczek.com/jogl/SawToothLight.zip (main is in TexturedSphere.java)
Keys that can be used:
- W - toggles wireframe on/off
- S - toggles glShadeModel() between GL.GL_FLAT and GL.GL_SMOOTH
- T - toggles sphere texture on/off
- P - toggles light to be infinite or point light
- COMMA / PERIOD - decrease / increase the tessellation of the 3D gluSphere()
- PAGE UP Arrow / PAGE DOWN arrow - increase / decrease X coordinate of light position
- RIGHT Arrow / LEFT arrow - increase / decrease Y coordinate of light position
- UP Arrow / DOWN arrow - increase / decrease Z coordinate of light position
- RIGHT BRACKET / LEFT BRACKET - Scale up / Scale down light position/distance…ie move light farther out or in
- Mouse left button for rotation
- Mouse middle button for zooming
As you can see from the image I get this saw tooth effect on my lighting even though I’m using GL_SMOOTH - note the sawtooth is best visible when the light position is not along the “equator” of the sphere but off at some angle…light position in this code is [-500, 500, 0] and it can be changed using the inputs above. I think it might be an issue with normals but I use the gluQuadricNormals(sphere, GLU.GLU_SMOOTH) and I thought that would be all I needed…I didn’t think I would need to go off an calculate the normals at each vertex of this sphere that I don’t even create directly but instead use the gluSphere() quadric. Note that removing the texture results in the same issue and increasing the tessellations of the sphere doesn’t help either…try out toggling the FLAT/SMOOTH using the ‘S’ key
I’ve been hacking around this code for days commenting in and out different parts and I still don’t understand what the cause is. I though this might be an issue with the gluSphere() in general so I even loaded a 3DS model of a sphere using joglutils and I also get the same sawtooth light pattern. I really need to have code that generates a smooth looking day/night transition that is distinguishable and not just a simply lit sphere…any thoughts on what I’m doing wrong here?