Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 2805 times)
0 Members and 1 Guest are viewing this topic.
Offline Z-Knight

Senior Member


Medals: 1



« 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 (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?
Offline darkprophet

Senior Member




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 Member


Medals: 1



« 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:   http://idevgames.com/forum/showthread.php?t=14508

Also, this site mentions the issue could be with poorly defined ambient lighting http://www.ozone3d.net/tutorials/stencil_shadow_volumes.php
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline darkprophet

Senior Member




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 Member


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 Member




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 Member


Medals: 1



« 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 Member





« 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (12 views)
2014-08-28 18:26:30

CopyableCougar4 (24 views)
2014-08-22 19:31:30

atombrot (37 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (29 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (27 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (33 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!