Tuesday, December 8, 2009

Experiment: MultiLight

I am always curious about light. Amongst all OpenGL code, it is the light that held me the most. So I decide to do a lighting demo. Referencing from an application in Paul's Project, I made my own scene for the light. This is the screenshot of the program.

You can see the video here.
As you might know, OpenGL supports 8 lights only. This is a trouble when you are trying to create more than 8, which is common. One way to trick this is to render each frame multiple times, using 8 light per render, and then blend it into a buffer. In my program, I used 60 light, so I render the frame 8 times, 7 with 8 lights and the last one with 4 lights.

If you try to build the scene, be cautious that you might get white color a lot. 60 lights is a lot of lights, might results a total white color. Try to reduce the attenuation or maybe the number of the light.

This program was built using XCode under Mac OS X Snow Leopard. Using GLUT for windowing and no extension required.

Update:
This is the better version of the multilight demo. I decrease the light number to 24 so the light is noticeable. Putting too many light will only make a tendency of white color as result of adding the light color. Since the light is dividable by 8, no last loop modification is needed.

Also note that the program run smoothly in approximately 60 FPS. The jaggy experience in the movie caused by a bad free screen recording.

No comments: