Results 1 to 4 of 4

Thread: [Newbie] Lighting problem :(

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    2

    [Newbie] Lighting problem :(

    Hi guys,

    I'm newbie to OpenGL and really need your help to complete very important project to me. I have a problem with lighting in OpenGL ES. I have spent many hours to find a right way to lit my scene with spotlights, without a success .
    First of all, my scene looks like this: a dark tunnel divided into number of cubic sectors. Every sector is a cube with 4 walls (top,bottom,left,right). I'm trying to put in every sector a spotlight that will lit a floor and part of walls. I came up with something like this: I set up 2 lights: ambient (to lit every wall with a dark light) and a diffuse light.

    Code :
    	float lightAmbient[] = { 0.3f, 0.3f, 0.3f, 1.0f };	
    	float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
     
    	glEnable(GL_LIGHTING);
    	glEnable(GL_LIGHT0);
    	glEnable(GL_LIGHT1);
     
    	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
    	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);
     
    	glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 20.0f);

    First I'm moving the player in my 3D world:

    Code :
    	glRotatef(CameraRot, 0, 1, 0);
    	glTranslatef(-PlayerPosition.x, -PlayerPosition.y, -PlayerPosition.z);

    Then I'm drawing my tunnel sectors in a loop:

    Code :
    	for(int i=0;i<SecNumber;i++) {
     
    		// Set my spotlight in a center of actual sector
     
    		GLfloat lightDirection[] = { 0, -1 , 0 };
    		GLfloat pos0[] = {0.0,0.0,0.0,1.0};
     
    		glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, lightDirection);
    		glLightfv(GL_LIGHT1, GL_POSITION, pos0);
     
    		Sector[i]->Draw();
     
    		// Move to the center of next sector
    		NextSectorPos = Sector[i]->NextSectorRelativePosition();
    		glTranslatef(NextSectorPos.x, NextSectorPos.y, NextSectorPos.z);
     
    		}

    This is (of course) not working like I expect When I move player around the 3D world, sometimes I can see a spotlight in one of the sectors (but not in all) and this light is disappearing when I'm changing distance to it.

    Could someone can point me what I'm doing wrong ? How can I achieve this lighting effect in other (not complicated ) way ?

    Treat this code as a pseudocode (my orginal code is in Objective-C).

    Thanks in advance for any reply!! (sorry for my english).

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: [Newbie] Lighting problem :(

    Have a look at this page, even if it is more than 10 years old, there is still relevant information for you, in the section "2. Poor Tessellation Hurts Lighting" :
    http://www.opengl.org/resources/feat...es/oglpitfall/

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2008
    Posts
    2

    Re: [Newbie] Lighting problem :(

    First of all, ZbuffeR thanks for your reply, however I still have some questions: why sometimes I see the spotlight on the floor and sometimes not (it depends on the distance). The spotlights should be fixed in one position, right over the surface, so I think that the wall in worse or better looking way should be lit (even if it is build of 4 vertices). Moreover I don't use the specular light so the intense of light shouldn't depend on the camera position (and in my case it unfortunately does ). Is the method I'm trying to use to lit all sectors is wrong ?? (moving 1 spotlight from sector to sector just before drawing it [all sectors are visible])

    Please help...

    Regards

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: [Newbie] Lighting problem :(

    Screenshots please, your description is not really descriptive.
    Try with much higher tesselation.
    Example, for each tunnel sector, subdive your polygons in 20x20 quads. It will be much easier for you to see what is going wrong.
    Or you will have to use per-pixel lighting, but it means using GL ES 2.

Similar Threads

  1. Lighting problem (opengl + shader lighting)
    By ox1d_47 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-19-2004, 09:43 PM
  2. Newbie Problem
    By Mjollnir in forum OpenGL: macOS
    Replies: 3
    Last Post: 05-29-2003, 10:27 AM
  3. graphics problem - newbie
    By in forum OpenGL: User Software
    Replies: 1
    Last Post: 12-27-2002, 12:16 AM
  4. newbie lighting/matrice question
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-09-2002, 04:14 AM
  5. Many Newbie Lighting Questions
    By Gunfighter in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-03-2000, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean