PDA

View Full Version : My scene is too dark but light is at max


OSXRules
2003.03.20, 08:56 AM
I am trying to make a facial modelling sim. The models are pretty high resolution (130,000 polygons) and when I display them on screen, they are barely visible. I have set the ambient light up to maximum using

GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

but it makes no difference. I have tried altering material properties to have maximum ambient, diffuse and specular reflection but again, no difference.

Can anyone tell me how to make the model brighter? I did notice that the colours appear to be quite low i.e. out of 255, red is at around 20 a lot. I know that increasing the overall colour i.e. by increasing each of the components should make it brighter but when I tried this, all the colours went wrong.

One final thing, has anyone noticed that in mac os 10.2.4 when you do glEnable(GL_LIGHTING), it actually disables lighting and vice versa? Is this a bug?

Mark Levin
2003.03.20, 12:57 PM
Originally posted by OSXRules

One final thing, has anyone noticed that in mac os 10.2.4 when you do glEnable(GL_LIGHTING), it actually disables lighting and vice versa? Is this a bug?

Stupid question: Are you also enabling the light you are using?

OneSadCookie
2003.03.20, 03:40 PM
Also stupid question: are you normalizing your normals?

DoG
2003.03.20, 04:06 PM
I can do better: Do you generate normals?

OSXRules
2003.03.21, 08:50 AM
Here is what my app looks like
file://localhost/Users/anonymoususer/Desktop/Picture%202.jpg

Now, I tried using translucency with the function
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
and it displays the colours properly like so:
file://localhost/Users/anonymoususer/Desktop/Picture%201.jpg

You will see that this has wireframe enabled. This is the only way that the colours are bright enough.

Even using
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
don't work.

I'll put some source code in the next post so you can see what I have written.

OSXRules
2003.03.21, 08:56 AM
I realise I put local URLs to my images - I thought the website would upload them - like what hotmail or yahoo e-mail does. Anyway, some of my source code is below. I tried to change all the colours to white but all I got was a grey image. That is until I turn on the blending. But, I shouldn't have to do this because I already have a texture mapped cube which displays fine without translucency. When blending is turned on in this case, the model is overbright.

-(void)drawModel
{
//printf("model has %i vertices\n",num);
//printf("into drawModel\n");

glViewport(0, 0, [self frame].size.width, [self frame].size.height);
// actually clear the window
glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT+GL _STENCIL_BUFFER_BIT);
// set position to window centre
glLoadIdentity();
//printf("hello\n");

// offset drawing position/rotation from viewport centre
glTranslatef( xpos, ypos, zpos );
// Rotate on X axis
glRotatef( xrot, 1.0f, 0.0f, 0.0f );
// Rotate on Y axis
glRotatef( yrot, 0.0f, 1.0f, 0.0f );
// Rotate on Z axis
glRotatef( zrot, 0.0f, 0.0f, 1.0f );

GLfloat ambientMaterial[] = { 1.0, 1.0, 1.0, 1.0 };

//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
//glEnable(GL_COLOR_MATERIAL);

//GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

int h,i,j;
int scale = 100;
for(h=0;h<data_height-2;h++){
for(i=h*data_width;i<(h+1)*data_width-1;i++){
glBegin( GL_TRIANGLES );
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ambientMaterial);
//glColor3ub(255,255,255);
glColor3ub(model_data[i].red,model_data[i].green,model_data[i].blue);
glNormal3f(model_data[i].nx,model_data[i].ny,model_data[i].nz);
glVertex3f(model_data[i].rx/scale,model_data[i].ry/scale,model_data[i].rz/scale);

//printf("rgb is %d %d %d\n",model_data[i].red,model_data[i].green,model_data[i].blue);

//glColor3ub(255,255,255);
glColor3ub(model_data[i+1].red,model_data[i+1].green,model_data[i+1].blue);
glNormal3f(model_data[i+1].nx,model_data[i+1].ny,model_data[i+1].nz);
glVertex3f(model_data[i+1].rx/scale,model_data[i+1].ry/scale,model_data[i+1].rz/scale);

j = i+data_width;
//glColor3ub(255,255,255);
glColor3ub(model_data[j].red,model_data[j].green,model_data[j].blue);
glNormal3f(model_data[j].nx,model_data[j].ny,model_data[j].nz);
glVertex3f(model_data[j].rx/scale,model_data[j].ry/scale,model_data[j].rz/scale);
glEnd();
//printf("i is %i\n",i);
}
for(i=h*data_width+1;i<(h+1)*data_width;i++){
glBegin( GL_TRIANGLES );
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, ambientMaterial);
//glColor3ub(255,255,255);
glColor3ub(model_data[i].red,model_data[i].green,model_data[i].blue);
glNormal3f(model_data[i].nx,model_data[i].ny,model_data[i].nz);
glVertex3f(model_data[i].rx/scale,model_data[i].ry/scale,model_data[i].rz/scale);

//printf("pixel %i at %f %f %f\n",i,model_data[i].rx/10,model_data[i].ry/10,model_data[i].rz/10);
j = i+data_width;
//glColor3ub(255,255,255);
glColor3ub(model_data[j-1].red,model_data[j-1].green,model_data[j-1].blue);
glNormal3f(model_data[j-1].nx,model_data[j-1].ny,model_data[j-1].nz);
glVertex3f(model_data[j-1].rx/scale,model_data[j-1].ry/scale,model_data[j-1].rz/scale);

//glColor3ub(255,255,255);
glColor3ub(model_data[j].red,model_data[j].green,model_data[j].blue);
glNormal3f(model_data[j].nx,model_data[j].ny,model_data[j].nz);
glVertex3f(model_data[j].rx/scale,model_data[j].ry/scale,model_data[j].rz/scale);
glEnd();
//printf("i2 is %i\n",i);
}
//printf("height is at %i\n",h);
}
[[self openGLContext] flushBuffer]; // execute the OpenGL commands
}

OSXRules
2003.03.21, 09:00 AM
Oh, and has no one experienced the glEnable problem. That is, if I specify glEnable(GL_LIGHTING), the lighting is actually disabled and vice versa.
How about the problem where my entire source tree under project builder is recompiling when I just change one file?

OSXRules
2003.03.21, 09:54 AM
when I printed out my normals, they were wrong. But, I corrected this and - you guessed it, still too dark. By the way, do I have to specify the normal before I specify the colour?

I'm doing
glColour3ub...;
glNormal3f...;
glVertex3f...;

Is there any way I can view the normals on screen to see if they are pointing the right way?

macboy
2003.03.21, 04:44 PM
I'm no Cocoa or Carbon guru, but can't you set it past max lighting or does that have undesired effects?

For example:

GLfloat lmodel_ambient[] = { 1.5, 1.5, 1.5, 1.5 };

instead of

GLfloat lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };

OSXRules
2003.03.22, 12:07 PM
changing up to 1.5 from 1.0 has no effect because OpenGL clamps any values higher than 1.0 back to 1.0. It looks like I need to increase something like luminoscity. When I turn on the glBlendFunc( GL_SRC_ALPHA, GL_ONE ) and use wireframe, all the colours look correct and white looks like pure white. If I draw lines in the scene, they all appear white but filled polygons don't.
If I increase the brightness of the lights, I get a brighter model sure but I lose the colour definition. On full brightness without blending, the model just looks entirely grey where it ought to look really bright white.

Also, has anyone got any feedback on the glEnable(GL_LIGHTING) disabling lights? Even if it doesn't happen to you - I'd still like to know because I can't see what's happening. I have 2 checkboxes - one switches on/off a light I defined and the other the GL_LIGHTING. When I call glEnable(GL_LIGHTING), my scene is noticeably darker and is brighter when I do glDisable(GL_LIGHTING). Now, my other light is brighter than default lighting so the effect I am seeing can be explained if the default lighting overrides my settings when enabled - but I don't think it is. Still, this ain't my big problem (the above is).

Please help me someone, 'cos this is for my senior honours project which is due in a month and I can't demo it if it's too dark.

DoG
2003.03.22, 12:55 PM
The only thing I can think of is that you are doing something wrong, but its hard to tell. Lighting does have some quirks, and is sensitive to quite a few things you wouldn't think of. I had my issues with it, too, all of which seemed to disappear without me apparently changing anything related to lighting. If you send over the code, I could take a look, and maybe figure it out.

Bachus
2003.03.22, 05:15 PM
I'm willing to bet your problem lies here:

glNormal3f(model_data[i].nx,model_data[i].ny,model_data[i].nz);
glVertex3f(model_data[i].rx/scale,model_data[i].ry/scale,model_data[i].rz/scale);

Try removing the "/scale" from all your glVertex3f statements and see if that fixes it. Scaling is bad for lighting as you have to renormalize your normals.

If that isn't it, then you've got me. Try doing what I did and draw your normals to make sure they're the right length and orientation:


center.x = (vertex1.x + vertex2.x + vertex3.x) / 3;
center.y = (vertex1.y + vertex2.y + vertex3.y) / 3;
center.z = (vertex1.z + vertex2.z + vertex3.z) / 3;

// draw the normals, debugging
glBegin (GL_LINES);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(center.x, center.y, center.z);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(center.x + normal.x, center.y + normal.y, center.z + normal.z);
glEnd();

EDIT: An example shot (http://www.killerrobots.com/games/images/terrain/shot2.gif) of what the above code draws.

DoG
2003.03.22, 05:48 PM
I don't know why you would want to scale vertices manually instead of using a scale matrix, or glScale, instead. It is much more convenient, simple, and less error prone.

Also, you I am not sure why you set your viewport in your draw function. You are also not calling glMatrixMode(GL_MODELVIEW) in the beginning, which should be done whenever you are dealing with modelling matrices, just to make sure. Call glEnable(GL_NORMALIZE) to have your object normals normalized. This incurs a small performance hit, but I doubt it would make any difference in your case.

OSXRules
2003.03.24, 10:29 AM
I already set the program to use MODEL_VIEW elsewhere and the NORMALIZE makes no difference - I think my normals are alright. I have also drawn them on screen and they are pointing in the right direction.

By the way, I noticed that the image the other guy posted has normals coming from the middle of the polygon - my normals are the vertex normals not the polygon normal, is that o.k?
Should I just be specifying one normal per triangle?

Oh and thanks for the glScale tip, it is much easier to use but to clarify to the other person, the scaling isn't affecting the lighting at all - I too thought it might have but my model was still dark when I removed the scaling and zoomed in.

The thing is, I looked at a post on lighting elsewhere and they suggested altering the brightness using some gamma correction. You see, in my model, the colours are the correct colours - they are just too dark i.e. white is displaying as grey. If you play Quake 3 or some game similar and change the brightness, I get that sort of effect. Like I said, it looks like there is not enough luminoscity or something. Does anyone know how Quake 3 does brightness or where I can get the source code?

Everything looks the right intensity only when I use glBlendFunc( GL_SRC_ALPHA, GL_ONE ); and when I am on wireframe. I have tried changing the emission, ambient, specular, diffuse reflection of the material and the light components. With my own light, I can make the model a bit lighter coloured but it's just not intense enough.
Do you think using a glBlendEXT might help - I saw someone else using this. They said to increase brightness, they overlayed a rectangle and blended it or something.

If you have any other suggestions please feel free - I am totally stuck. I wouldn't mind e-mailing the code - although the file you have to load in is quite large. If you have an e-mail address that would be fine or should I post it elsewhere?

OSXRules
2003.03.24, 10:39 AM
Dooog - I should have sent you an e-mail containing the code by now. I sent it to dog4@...

DoG
2003.03.24, 03:04 PM
I have not yet recieved any email, but it may take a while because it is forwarded. I will edit this message when I get the mail.

Just one more thought: are you calling glEnable(GL_BLEND) ? Just asking because I have not seen it in the previous code samples.

Bachus
2003.03.24, 04:15 PM
By the way, I noticed that the image the other guy posted has normals coming from the middle of the polygon - my normals are the vertex normals not the polygon normal, is that o.k? Should I just be specifying one normal per triangle?

You have to define a normal for every vertex in the triangle. If the normal is the same for all three vertices then you have per-polygon lighting which is what that shot showed. I just drew the normals from the center of the polygon in that shot because it's easier to see if you've got the right normals that way than if you have them coming from the vertices. To get per-vertex lighting you just have to add up the normals for all the polygons that use that vertex, then divide by the number of polygons.

I'm almost out of ideas as to why lighting wouldn't be working. Try switching your winding between clockwise and counter-clockwise by using "glFrontFace(GL_CCW);" and "glFrontFace(GL_CW);" or draw the front and back faces in two different ways like this "glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_LINE); // draw front faces in filled mode, back faces in wireframe". Oh, and make sure you aren't applying any transformations to your GL_PROJECTION matrix.

Other than that, I'm completely out of ideas now.

henryj
2003.03.24, 07:54 PM
Haven't seen this mentioned but have you examined the length of your normals, they should equal 1.0

Also where is your light. It may be that you are looking at the dark side of the moon.

OSXRules
2003.03.25, 08:00 AM
I got a delivery failure from your e-mail dooog. My message says that what I sent was too large - 1.2 MB and that the message was truncated to 5k.

Anyway, I uploaded my code as a GLSurgery.tgz file to my yahoo briefcase at

http://uk.briefcase.yahoo.com/ajr650

so any of you can look at it. It should be in the "my documents" folder, which is public.

I removed the build code to save space so you will have to compile it yourself but I included the project builder files so just open the .pbproj file and everything should be o.k.

When you compile it and run it, go to the menu load surface and select the file bernard.srf (also included). It takes a wee bit of time to load as the model contains ~130,000 polygons. You will also notice that you can't see the face when it first loads. It is just misaligned. You have to move the first and third sliders half way to the left to see it. In the lighting tab, you can switch on the extra light to make it a bit brighter. Ignore the default light as it is redundant now.

If you select the translucent and wireframe buttons, you will see what I was saying about the brightness.

henryj
2003.03.26, 05:59 PM
Your briefcase is empty.

OSXRules
2003.03.27, 08:25 AM
That's weird, I made all my folders public (damn yahoo). I see what you mean though, I logged out and saw the folder was empty. I don't know how to fix it though.

Anyway, I have made a trial .mac account. Please someone access it quickly at

homepage.mac.com/osxrules

I only have less than a month left on my project - I need to get it fixed (panic).

:wacko:

MacFiend
2003.03.27, 09:23 AM
I know you are enabling lighting: glEnable(GL_LIGHTING), but are you enabling one of the light instances? ie: glEnable(GL_LIGHT0)?

glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT+GL
_STENCIL_BUFFER_BIT);

I've never seen it done that way. I've always seen glClear(bit | bit | bit...). Not sure if there is any difference, but you might want to look into it.

Try adding a constant spin to the object you are rending (for debug purposes) and see if it lights up any.

MacFiend
2003.03.27, 09:34 AM
I just looked at your source. Try putting (if you havent already tried this):


glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);


at the beginning of drawGLScene and see what happens. If it works, then the error is in your checkLighting or related lighting functions.

OSXRules
2003.03.28, 06:31 AM
My extra light (called LIGHT_1) is enabled and disabled by flipping the switch in the interface. That's not the problem. The problem lies in the amount of light being reflected from or blended with my model.

Has anyone had it running and can see what's going on?

I had considered using software lighting but I shouldn't have to resort to that.

Please bear in mind that although the code is very large, the problem is only in GLView.mm. So, there is no point in trailing through any of the other code. I probably should have pointed that out earlier.

OSXRules
2003.03.28, 06:45 AM
I see what you mean about using + in glClear(). I think I just saw someone else's code that used it. It didn't seem to make a difference though.

As for rotation, my sliders allow the model to rotate 360 degrees in all directions. Still there is no difference.

OSXRules
2003.04.01, 08:23 AM
Hey, have you forgotten about me? (boo hoo). No one has replied for a while. Am I to assume that no one has sorted out my problem?

Come on, surely one of you 'gurus' and 'code crunchers' can figure it out. Pleeeeeease.

KenD
2003.04.01, 02:27 PM
Originally posted by OSXRules
I see what you mean about using + in glClear(). I think I just saw someone else's code that used it. It didn't seem to make a difference though.

As for rotation, my sliders allow the model to rotate 360 degrees in all directions. Still there is no difference.

Yes, but where is your light positioned? If it's behind the model (from the cameras point of view) it doesn't matter how much you rotate the model.

KenD

Mark Levin
2003.04.01, 04:49 PM
You said you are using light 1... Try switching over to light 0 (unless it's already used for something else). The clip planes have a bug where none of the planes work unless plane 0 is enabled, maybe lights work the same way.

OSXRules
2003.04.02, 06:02 AM
You misunderstand, my light 1 works. It is making a visible difference to the scene in that when I turn it on, the scene is brighter but it looks like I have turned on a torch in a dark room whose batteries are run down.

The brightness intensity is just not there. The easiest way for you to see how to make a difference is to download the code I uploaded to

http://homepage.mac.com/osxrules

and compile it yourself. You just have to modify the file GLView.mm.

DoG
2003.04.02, 07:52 AM
Sorry, its on my HD, but havent had the time to look through the stuff yet.

OSXRules
2003.04.02, 08:23 AM
I don't mean to be a pain but it's for my project which now only has 3 weeks left and I also have to write a 50 page report with it. So if you wouldn't mind trying to fix it ASAP, I would very much appreciate the help.

Again I want to stress that the code you need to look at is only in the file GLView.mm, ignore the other files.

Aside: By the way, does anyone have the free classic dockling on their machine. It is just a little dock extension which lets you know if classic is running. If you have it, remove it because it badly affects the performance in mac os x. It makes the itunes visualizer, movie playback and games jitter periodically. I just discovered this yesterday.

Also, if you have the date and time bug in 10.2.4, please fix the time because it affects compile times. Project builder thinks all the object files are old and recompiles them all every time. This was slowing my compile time down a lot.

OSXRules
2003.04.04, 06:19 AM
I have sorted it out finally. I discovered by accident that I wasn't disabling GL_TEXTURE_2D from the first model I rendered so as the second model had no textures, it wasn't lighting it up properly.

A subtle but very annoying error and difficult to find in a lot of code.

Anyway thank you all for your interest and helpful comments. I can at last put this thread to rest.