PDA

View Full Version : How to set up light?



betwixt
03-14-2010, 02:43 PM
Hello.

I want to know how to make my gl scene darker and brighter. So that if I set a value to complete darkness, then nothing is seen :). How can I do that? I tried some light functions, but I didn't quite understand them and for those to properly work it needed every object to have normals.

float lightAmbient[] = new float[] { 0.2f, 0.3f, 0.6f, 1.0f };
float lightDiffuse[] = new float[] { 0.2f, 0.3f, 0.6f, 1.0f };
float[] lightPosition = new float[] {0,0,3,1};

gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT,lightAmbientBuffer); //Setup The Ambient Light
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer); //Setup The Diffuse Light
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer); //Position The Light
gl.glEnable(GL10.GL_LIGHT0);

this worked so that whatever the surface is facing me flat then it looks the brightest.

What is the diffuse and what is ambient?
Do I really need normals for every surface?
Do I need to set the lightPosition very far?

Ehsan Kamrani
03-14-2010, 04:07 PM
1)Ambient light is added to the whole scene, so you see the objects that look flat. This property is used to add a color to the scene, so you no longer see those "black places" that are not affected by any lights. in summery, ambient light is just a color.I use only one ambient light for light0 and set the ambient light of other lights to 0.Ambient lights are added to each other and with "more" and "brighter" ambient lights, you see a brighter scene.
2) This article (http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir1) has explained the diffuse term. With diffuse light, your objects look 3D.So the back part of object that is not affected by light now looks darker, but this dark part of the object has some ambient color if you specify the ambient light in your scene.Again note that the ambient light is added to the whole object .So brighter ambient == brighter object. You need to add normal vectors to your model if you want to use the diffuse light.
3) With farther point light you usually get less brightness( specified with constant, linear and quadratic attenuation). Point lights are like bulbs.However directional lights are really far. They are like sun. The last value of a directional light's position is 0:
float m_directionalLightPosition[] = {0,0,3,0};

lighting the scene properly is an art.Usually artists have a better understanding of placing the lights in proper places.