![]() |
|
Strange lighting problem - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: Strange lighting problem (/thread-5854.html) |
Strange lighting problem - Duncanla - Feb 22, 2005 10:55 AM OK.....so ive been creating a graphics engine for the first time and i am currently working on lighting. I have been using the spacesimulator.net and the nehe tutorials to guide me. So i created a program that loads 2 .3ds models and then calculates their normals and then generates the lighting. I used the same models from the spacesimulator tutorials as well as the same lighting set up to test it out. The problem is...the lighting seems very choppy. I know the smooth shading is working and all that but it seems like on my models, the vertices dont gradual shift colors, they seem to shift between white, gray, and black which gives it an effect that resembles what it would look like if i used polygon normals instead of vertex normals. I debugged both programs and found that the normals in both programs were the same and I ran the spacesimulator program to be sure it wasnt a hardware issue. I just cant find any inconsistencies between the two programs in my lighting. Very frustrating. Theres gotta be something stupid im just completely missing. If anybody would like to see how the program is working i can e-mail you the executable and data files, or i could send you my code if you want that. Anything to get this thing working. Thanks! Luke Strange lighting problem - ThemsAllTook - Feb 22, 2005 01:05 PM Maybe you need a call to glShadeModel(GL_SMOOTH)? You say you calculate the normals after loading the models. First, doesn't your .3ds file store normals already? Second, how exactly do you go about calculating the normals? Have you enabled GL_COLOR_MATERIAL? (I don't remember if this could cause the effect you describe, but it's a good thing to have on anyway.) - Alex Diener Strange lighting problem - Duncanla - Feb 22, 2005 09:40 PM I have already called set the shade model to smooth and no i havent used color material. I make my calls to glMaterial() and then use the texture. I will try the color material the next chance i get. Also, I dont know if the normals are included, i was just following the spacesimulator tutorial. To calculate the normals I take two sides of each triangle as a vector and then normalize the corss product of the sides to get the normal of each polygon. And then i keep track of how many times each vertex is used and average the normals of each vertex. I am getting the same normals as the tutorial's program but the transition of the from light to dark is not as smooth for each polygon. For instance, in the tutorial, it seems like the shade for each pixel changes very smoothly from light to dark as you rotate the object, but in mine, they seem to jump from black to gray to white. Any other ideas? thanks for your help so far! Strange lighting problem - phydeaux - Feb 23, 2005 08:09 AM It sounds like your normals are not normalized then, though you said you did that. Do you have any screenshots? Strange lighting problem - MarkJ - Feb 23, 2005 09:55 AM A quick fix to see if its a problem with un-normalized normals is to call glEnable(GL_NORMALIZE); right before you render your model. Strange lighting problem - Duncanla - Feb 23, 2005 05:19 PM I have tried the program with GL_NORMALIZE enabled as well as renormalizing all of the normalize after they are all averaged and i get the same result. I will be able to get some screenshots up soon Strange lighting problem - Duncanla - Feb 25, 2005 10:34 PM http://www.geocities.com/duncanla22/badSphere.JPG There is a screenshot of a simple sphere using the glut libraries so i would not have to find any normals. You can see how it is very choppy around the shaddow...also as the sphere spins you can see the add choppiness ass the jagged edge moves around... would anyone like to see my code? i wont post it if nobody wants to bother...im just completely shot on any ideas thanks for the help Strange lighting problem - Duncanla - Feb 25, 2005 10:47 PM Ok here is a simplified version of my code that still achieves the same bad effect ...there has got to be something im missing. This is an over simplified version that used a glut sphere so i dont have to caclulate any normals (or should i?) Code: #include <GL/glut.h>Either im suffering from major mental illness or something really weird is goin on....which one is it?
Strange lighting problem - phydeaux - Feb 26, 2005 08:41 AM I think what's going on is your total specular highlight is too high. Those sharp falloff symptoms could be of specular highlighting being overpowering. Since it multiplies the light specular by the material specular, I think the value is going to be higher than you want. Have you played around with the light values? Also, you might want to try giving your sphere a higher tesselation. It may be easier to tell what's going on. Edit: To clarify, since your SHININESS is 1.0, the specular highlight will actually just create a +k value on half of the sphere. Since the light value is interpolated across the vertices, this "half" of the sphere will end up being approximated producing a jagged edge like the one you are seeing. To eliminate this you can either remove your specular lighting, or make your SHININESS factor much higher, and your specular lighting numbers lower. Strange lighting problem - Duncanla - Feb 26, 2005 04:47 PM Changing the shininess seems to have helped a bit...but it can still be seen. Another question....why would it work in the spacesimulator.net tutorials and not in mine when im using the same values? Strange lighting problem - Duncanla - Feb 27, 2005 11:23 AM http://www.geocities.com/duncanla22/goodSphere.JPG This is a screen shot of the spacesimulator tutorial that i modified to do the same thing as mine but it looks much better... i have no idea why.... Here is the code: Code: /*I still cant find any inconsistencies between this code and mine Strange lighting problem - BinarySpike - Feb 27, 2005 11:05 PM I remember tool that found "inconsistencies" between code... (I just wish I knew the name )
Strange lighting problem - Duncanla - Feb 28, 2005 07:18 PM Any other ideas or insight? Strange lighting problem - phydeaux - Feb 28, 2005 08:00 PM I think between your code and the example you code there are a few minor parameter differences, so you might just want to start with the example code, then strip things out until it's the way you want it. It does seem very strange. Strange lighting problem - Duncanla - Mar 1, 2005 02:43 PM FINALLY I FOUND IT...... IM NOT CRAZY... i found the difference between the code. The tutorial said to do this: [CODE] glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv (GL_LIGHT1, GL_SPECULAR, light_specular); glLightfv (GL_LIGHT1, GL_POSITION, light_position); glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv (GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess); [CODE] which is correct and its what i did....but in their source code they did this by mistake: [code] glLightfv (GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv (GL_LIGHT1, GL_DIFFUSE, light_diffuse); glLightfv (GL_LIGHT1, GL_DIFFUSE, light_specular); glLightfv (GL_LIGHT1, GL_POSITION, light_position); glMaterialfv (GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv (GL_FRONT, GL_DIFFUSE, mat_specular); glMaterialfv (GL_FRONT, GL_POSITION, mat_shininess); [\code] ...notice how they gave GL_DIFFUSE the specular value as well...i cant believe it took me this long to figure this out...i swear i checked that about 300000 times.... ok...so now im going to assume that the correct answer to this would be that the specular component IS overpowering the others. Now....as soon as a review the effects of the different components i will be able to accomplish the effect that the tutorial is going for....Thanks everybody for your help!!!! |