Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (613)
Games in Android Showcase (173)
games submitted by our members
Games in WIP (659)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  ? Saw Tooth Lighting ?  (Read 3235 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Devvie

Medals: 2

« Posted 2008-03-19 17:35:49 »

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 ( 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:   (main is in
     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/ 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?
Offline darkprophet

Senior Devvie

Go Go Gadget Arms

« Reply #1 - Posted 2008-03-19 17:40:07 »

The lighting is correct. However, because the lighting equation is performed per vertex then interpolated across the fragments, your precieving this as sawtooth.

You have two options:

1) Increase the tesselation of the sphere.
2) Start using shaders to do your own per-pixel lighting

The first option will not get rid of the artifact, but it would make it less visisble and noticable. The second option would add a significat amount of complexity to your renderer to manage shaders and uniforms correctly and in a performant manner.

PS. You could also add some ambient to reduce the effect, but since your in space....there isn't any ambient lighting! So experiement with it...

HTH, DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #2 - Posted 2008-03-19 17:44:30 »

sigh...I was afraid of that.  Increasing the tessellation ends up costing me frame rates and using shaders is currently not an option because I'm trying to make an app that I can't guarantee the hardware it will be running on and I'm told that shaders are hardware specific so for now I'd like to concentrate on simple opengl solution which doesn't appear to exist.  Plus I don't even know opengl that well much less shaders.

thx, darkprophet.

I forgot to add in my previous post a link to another forum with a user having the same issue (though in OpenGL not JOGL)...he also didn't have a solution:

Also, this site mentions the issue could be with poorly defined ambient lighting
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkprophet

Senior Devvie

Go Go Gadget Arms

« Reply #3 - Posted 2008-03-19 17:54:04 »

shaders are easy once you get used to the quirks.

The problem is two fold really, the first one is the pixel shaders have versions that are not regressable. I.e. PS3.0 will not run on hardware that doesn't support it, meaning you can't gain from its flexibility unless you use newer hardware. Which means you are forced to create a baseline for your game/application and create multiple pixel shaders that do the same thing.

The second problem is compatibility, Nvidia and ATI do things different and will have their own quirks when it comes to things, just experiement and you'll soon find them.

HTH, DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #4 - Posted 2008-03-19 19:54:05 »

Steady on there, I'm pretty sure that the lighting is not correct.
Before you go off and try shaders, make the simplest possible test of gluSphere rendering.
Take the Gears demo from jogl and replace the gear-rendering code with a call to gluSphere.

It looked like this when I did it

Thats with 10 stacks and slices for the spheres, so fewer than in your sample image. Code here
Offline darkprophet

Senior Devvie

Go Go Gadget Arms

« Reply #5 - Posted 2008-03-19 20:59:14 »

Hmmm...apologies, your right. Looks like normals are to blame. I initially thought it was something to do with the way he's set his materials up, but looking at the image he's posted, there doesnt seam to be any interpolation across the lit faces at all.

I would suggest you look at the gluSphere code and copy what it is doing for normals.

DP Smiley

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Z-Knight

Senior Devvie

Medals: 2

« Reply #6 - Posted 2008-03-19 22:28:52 »

Thanks for that code...I'm wodering if it may be more an issue with the choice of color properties for the specular, diffuse, ambient that could lead me to a nice terminator (day/night transition) on the map.   I suspect it is a combination of all of those factors and I just need to add some JSliders to my example code and start messing with the colors and properties to hit upon the right combination.  I used the light setting from the Gears/Spheres code you provided and unfortunately that combination of lighting properties made it hard to even see my textured sphere, but when I removed the texture the sphere underneath did appear to have a nice terminator...I think I just need to do the color tweaking I suggested and see what I can come up with. Thank you
Offline Chris61182

Junior Devvie

« Reply #7 - Posted 2008-03-19 22:45:50 »

Looking through your code briefly I didn't see any non-uniform scales, but it might still be worth it to test out glEnable(GL_NORMALIZE) or glEnable(GL_RESCALE_NORMAL)
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Coldstream24 (13 views)
2015-09-03 00:41:28

Andrew_3ds (24 views)
2015-09-01 19:08:10

afikri (16 views)
2015-08-31 09:30:22

afikri (24 views)
2015-08-31 09:30:07

afikri (12 views)
2015-08-31 09:27:24

afikri (16 views)
2015-08-31 09:26:40

Roquen (23 views)
2015-08-29 11:30:54

GamerC4 (34 views)
2015-08-22 20:38:50

GamerC4 (31 views)
2015-08-22 20:37:18

GamerC4 (37 views)
2015-08-22 20:37:01
HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!