# 2 questions regarding lighting...

This topic is 4252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
Problem 1:

This is a common problem in all 3D APIs. OpenGL has global lighting, meaning that each polygon is being lighted individually without regard for any other polygons in the scene. That's why light "goes through" walls. To solve this problem you can render your scene like this:

Set up light 1.
Find all objects that are affected by light 1. (for example, building exterior).
Draw these objects.

Turn off light 1.
Set up light 2.
Find all objects that are affected by light 2. (for example, building interior)
Draw these objects.

...

Problem 2:

Have a look at OpenGL specular lighting (GL_SPECULAR) and lighting attenuation formula (GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION). Make your light really bright and apply a large attenuation value. Nate Robbins has at excellent OpenGL lighting tutorial where you can play around with these knobs: http://www.xmission.com/~nate/tutors.html.

##### Share on other sites
Quote:
 Problem 1:This is a common problem in all 3D APIs. OpenGL has global lighting, meaning that each polygon is being lighted individually without regard for any other polygons in the scene. That's why light "goes through" walls. To solve this problem you can render your scene like this:Set up light 1.Find all objects that are affected by light 1. (for example, building exterior).Draw these objects.Turn off light 1.Set up light 2.Find all objects that are affected by light 2. (for example, building interior)Draw these objects....

Thanx dude...thats a beautiful tip :D..works great...

the only thing is, that I read somewhere that GLUT only allows a maximum of 8 lights... LIGHT0 ~ LIGHT7, and my scene requires at least 20 to 30 lights..how can I implement more lights ?

Quote:
 Problem 2:Have a look at OpenGL specular lighting (GL_SPECULAR) and lighting attenuation formula (GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, GL_QUADRATIC_ATTENUATION). Make your light really bright and apply a large attenuation value. Nate Robbins has at excellent OpenGL lighting tutorial where you can play around with these knobs: http://www.xmission.com/~nate/tutors.html.

Thanx for this tip too dude, although I havent tried this one out yet..the link you are offering is dead..do you have any other tutorial links that explain light attenuation ? Thanx in advance :P

##### Share on other sites
ok, regarding the 2nd problem, I tried putting in the following code..but I detect no changes...

glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,1.0);
glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,10.0);

##### Share on other sites
In relation to drawing all objects affecting by light 1, etc....rather than using Light0...Light1...etc incrementally, you can use the same Light* and just change the parameters of that light. That way you can have as many lights as you wish.

In psuedo-code:

-> Set Up 1st Light's Parameters in Light1 (reserving Light0 for Ambient/Environment Lighting)
-> Draw All Objects Affected By Said Light

-> Set Up 2nd Light's Parameters in Light1
-> Draw All Objects Affected By Said Light

-> etc
-> etc

You get the idea. Hope this helps.

##### Share on other sites
Regarding Problem 2:
--------------------

Well I have tried everything I know of, to try and get this lighting effect in my model:

http://img186.imageshack.us/img186/4324/lighteffectdq2.jpg

Because I dont understand this can be implemented, I am putting my code here..Please have a look at this, and see if you can get this effect for me...please dudes...

Here is the complete VC++ project:

http://www.mediafire.com/?dhjkygtmymm

Dont worry, the size is higher because of a few texture BMPs, that are being used in the model...

Once you run the program, use the forward arrow key to move into the classroom...

other keys that can be used are the following:

Forward/Backward Arrow Keys: Move forward/backward

Left/Right Arrow Keys: Look left/right

Page Up/Down Keys: Move Up/Down in a vertical direction....

'8','2','4','6' on numpad: rotate camera in different directions at changing speeds (just to have some fun!!)

'.' on numpad: reset camera position

This model has a classroom defined in it..

The classroom has the following objects in it:

-Chairs
-Desks
-Windows
-Switch Board
-Doors
-Stage
-Projector
-Presentation Screen

You dont need to be concerned with all the functions and variables defined in the program. The part that relates to this question of mine (the lighting parts)
are as follows:

-The Light Colour/Position properties are defined right underneath the header files

-These properties are used when generating the light in the init() function

-The rest of the stuff is non-light related, so you can just skip all that...

In case you are able to see what needs to be done, in order to get an attenuation like this:

http://img186.imageshack.us/img186/4324/lighteffectdq2.jpg

I am sure the issue is very basic, which I dont have a solution to because I am just a beginner at GLUT....please have a look at this code and tell me the solution....:)

##### Share on other sites
someone pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeassseee help me out man....I am really desperate...

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633704
• Total Posts
3013457
×