• Advertisement

Archived

This topic is now archived and is closed to further replies.

Need help beginning with Lighting

This topic is 5030 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. I have taken up a 3D home modeler as my project, which lets the user construct any simple building(its very basic though). I have already finished with the construction part, and now i want to add lighting(I have never used lighting before). I want to use a very simple lighting scheme in which there is an overall lighting all over the scene. So even if the user navigates and comes inside a room, he should find sufficient light to look around. I was thinking of simulating a light for sun, but what happens when i am inside a closed room? Does it have to do anything with global ambient light? Time is short, and ultra realism is not on my mind. To be frank, i need lighting so that my objects - like walls, become perceptible. So can someone please tell me a simple method to use lighting. If you can give some example lighting parameters to begin with, that would simply be great. Please suggest me how to define material paramaters also. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Hi, let me introduce you to a friend. Astroguru, meet google. Google, astroguru.
http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=OpenGL+Lighting

Share this post


Link to post
Share on other sites
To start with default lighting:

glEnable ( GL_LIGHTING );
glEnable ( GL_LIGHT0 );

thats it. Make sure you specify your Normals.

To alter materials & light properties, get the RedBook from this site (Resources i think) or check nehe.gamedev.net for a simple tutorial.

Share this post


Link to post
Share on other sites
I done know openGL (or a lot of DirectX)but here is what i think would work.


Place two really broad spotlights on opposite sides of the building and a little above the building.

Then find out whether the camera is inside or outside the building. If inside, turn a point light on that is situated above the camera. If outside, turn the light off.

I hope this is what you were asking.

|EDIT|: My little picture was REALLY messed up.

[edited by - envy3d on April 17, 2004 1:27:26 AM]

Share this post


Link to post
Share on other sites
Well you'll definately want an ambient lighting term so you can see things that aren't lit. To simulate sunlight you'll want a directional light, that's a light where you don't specify it's position instead you specify just it's direction. Inside a closed room you'll still get the lighting as the default OpenGL lighting doesn't do any shadowing or take occulsion into account.

Check out this tutorial on NeHe for some info on lighting in OpenGL, though I don't think it covers directional lighting which is what you want. You do directional light is basically exactly the same way as a point light (described in the above tutorial) apart from when you specify the position you use 0.0 as the 4th parameter not 1.0 i.e.(Taking code from the tutorial above as an example)


GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 0.0f };

intead of

GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };


[edited by - Monder on April 17, 2004 5:16:01 AM]

Share this post


Link to post
Share on other sites
Hi. I have done the same thing, setting a directional light at (1.0,1.0,1.0,0.0).These are my light0 settings:
GLfloat light_Diffuse[] = {1.0,1.0,1.0,1.0};
GLfloat light_Ambient[] = {0.2,0.2,0.2,1.0};
GLfloat light_Specular[] = {1.0,1.0,1.0,1.0};
GLfloat light_Pos[] = {1.0,1.0,1.0,0.0};
GLfloat global_Ambient[] = {0.2,0.2,0.2, 1.0};
But some faces of the objects look completely black when viewed from a particular angle. For ex, i have drawn a solid cube at origin, and when i view it from, say eye position (10.0, 1.0,10.0), the front face of the cube(the one whose outer face is towards +ve Z axis) looks completely black. The scene also looks dull as if viewed at the sunset. Do you suggest I should use two lights?
Another queer thing is that a huge polygon that i draw for the earth surface(y=0) looks the same Gray from both the sides, but another polygon(z=0) looks totally black when i view it from other side. using GL_LIGHT_MODEL_TWO_SIDE solves this problem, but why does the y=0 polygon remains the same color even when this option is disabled?
Thanks.

[edited by - astroguru on April 17, 2004 7:09:01 AM]

Share this post


Link to post
Share on other sites

  • Advertisement