My scene is too dark but light is at max

OSXRules
Unregistered
 
Post: #1
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?
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #2
Quote: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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Also stupid question: are you normalizing your normals?
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
I can do better: Do you generate normals?
Quote this message in a reply
OSXRules
Unregistered
 
Post: #5
Here is what my app looks like
[img]file://localhost/Users/anonymoususer/Desktop/Picture%202.jpg[/img]

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

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.
Quote this message in a reply
OSXRules
Unregistered
 
Post: #6
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
}
Quote this message in a reply
OSXRules
Unregistered
 
Post: #7
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?
Quote this message in a reply
OSXRules
Unregistered
 
Post: #8
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?
Quote this message in a reply
macboy
Unregistered
 
Post: #9
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 };
Quote this message in a reply
OSXRules
Unregistered
 
Post: #10
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.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #11
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.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #12
I'm willing to bet your problem lies here:

[sourcecode]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);[/sourcecode]

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:

[sourcecode]
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();[/sourcecode]

EDIT: An example shot of what the above code draws.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #13
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.
Quote this message in a reply
OSXRules
Unregistered
 
Post: #14
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?
Quote this message in a reply
OSXRules
Unregistered
 
Post: #15
Dooog - I should have sent you an e-mail containing the code by now. I sent it to dog4@...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Transforming directional light to eye space in GLSL Coyote 4 6,750 Dec 8, 2009 03:16 PM
Last Post: Coyote
  OpenGL Blending for 2D Light Effects metacollin 10 13,233 Jun 6, 2009 12:51 AM
Last Post: NelsonMandella
  light attenuation NelsonMandella 2 3,818 Jun 4, 2009 03:28 PM
Last Post: reubert
  Surface/Vertice Normals and Scene Placement Jones 3 3,045 Aug 22, 2006 02:45 PM
Last Post: scgames
  Use Spencil in 2D scene and OpenGl ? RB jp 1 2,211 Apr 12, 2006 02:33 PM
Last Post: RB jp