Jump to content
  • Advertisement
Sign in to follow this  
ahmadka

2 questions regarding lighting...

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys...I think I am getting better at this graphics programming thing :D... thanx for all your help dudes...your golden words really help me out :D.. Right Now, I am making a 3D model of my department in my university...completely in 3D.... I have done quite a lot, but 2 things regarding lighting are really bugging me...please have a read: Problem 1: ---------- I have made a model of a building, with rooms in it and everything, and I have placed just one point light source in the model, located at the origin... Now the problem I am having is that, the light seems to go through the 'walls', and into other rooms, which I think it should not do... I am using GL_QUADS to define 'walls' in my scene. Also, I am defining a Normal vector which each GL_QUAD that I define. As should be expected, only the side of the GL_QUAD, which is on the same side as the normal vector itself, lights up, the other one does not... But what does not make sense is that how can a wall light up, when there is no light in front of it, and is instead *behind* it, in some other room ?????? Problem 2: ---------- Have a look at this picture: http://img186.imageshack.us/img186/4324/lighteffectdq2.jpg Do you see how the light spreads out the roof ? Highest intensity at the place where the light is located, with the intensity decreasing as you move away from the light source....thats the effect I want in my scene.... In my scene, the roof is defined by a GL_QUAD, and the light source is directly underneath it, just like in the picture...But what happens in my scene is just a uniform spread of light....how can I fix this ?? Help needed lighting experts :P Thanx in advance..

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,30.0);

please help...

Share this post


Link to post
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 this post


Link to post
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

...please let me know...

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....:)

thanx in advance people...

Share this post


Link to post
Share on other sites
someone pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeassseee help me out man....I am really desperate...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!