Specular lighting problem

Started by
3 comments, last by Revelation60 15 years, 12 months ago
Hi, For some reason, all my surfaces that point to the light are white when I have specular lighting enabled. I use this for the material:

						glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, SceneMaterials[matid]->ambcol);
				        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, SceneMaterials[matid]->difcol);
                        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SceneMaterials[matid]->speccol);
						glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, SceneMaterials[matid]->shinestrength);

and for the light:

GLfloat LightAmbient[]=		{ 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat LightDiffuse[]=		{ 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightSpecular[]=	{ 1.0f, 1.0f, 1.0f, 1.0f };

            glLightfv(GL_LIGHT0 + i, GL_SPECULAR, LightSpecular);
			glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0 + i, GL_AMBIENT, LightAmbient); 

Even when shininess is set to zero, it still happens. What could be the problem?
Currently working on WalledIn
Advertisement
Need to see your render loop - esp the geometry. Bewarned - if your sending in low res poly data then results won't look good. Also - check your normals. Lighting is dependent upon the normals your are using.

Well, no much to say about the render loop:

glEnableClientState(GL_VERTEX_ARRAY);        glBindBufferARB(GL_ARRAY_BUFFER_ARB, o->BufferHandles[0]);        glVertexPointer(3, GL_FLOAT, 0, 0);        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, o->BufferHandles[1]);        glEnableClientState(GL_NORMAL_ARRAY);        glBindBufferARB(GL_ARRAY_BUFFER_ARB, o->BufferHandles[2]);        glNormalPointer(GL_FLOAT, 0, 0);        float defcol [] = {1.0f, 1.0f, 1.0f, 1.0f};        float defamb [] = {0.2f, 0.2f, 0.2f, 1.0f};        float defdif [] = {0.8f, 0.8f, 0.8f, 1.0f};        float defspec [] = {0.0f, 0.0f, 0.0f, 1.0f};        float defshin = 0.0f;        for (int i = 0; i < o->GroupCount; i++)        {            int matid = o->GroupedTriangles.triangle->MaterialID;            glActiveTexture(GL_TEXTURE0);            glDisable(GL_TEXTURE_2D);            glActiveTexture(GL_TEXTURE1);            glDisable(GL_TEXTURE_2D);            glActiveTexture(GL_TEXTURE0);            if (matid == -1)            {                glColor4fv(defcol);                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, defamb);                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, defdif);                glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, defspec);                glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, defshin);            }            if (matid > -1)            {				 glColor4fv(defcol);                glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, SceneMaterials[matid]->ambcol);                glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, SceneMaterials[matid]->difcol);                glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, SceneMaterials[matid]->speccol);                glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, SceneMaterials[matid]->shinestrength);                //glMaterialf(GL_BACK, GL_SHININESS, SceneMaterials[matid]->shininess);                //glColor3ub(SceneMaterials[o->triangles->MaterialID]->color[0],SceneMaterials[o->triangles->MaterialID]->color[1],                //SceneMaterials[o->triangles->MaterialID]->color[2]);            }            PolygonsDrawn += o->GroupedTriangles.tricount;            glDrawElements(GL_TRIANGLES, o->GroupedTriangles.tricount * 3, GL_UNSIGNED_INT, (void*)(o->GroupedTriangles.tristart * 3 * sizeof(unsigned int)));        }//		glDrawElements(GL_TRIANGLES, o->TriangleCount * 3, GL_UNSIGNED_INT, 0);        glDisableClientState(GL_VERTEX_ARRAY);        glDisableClientState(GL_NORMAL_ARRAY);        glDisableClientState(GL_TEXTURE_COORD_ARRAY)    }


This gives me a completely white polygon for every polygon that's in front view for the light. If I set

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR .. to (0, 0, 0, 1) I can see them again.

Currently working on WalledIn
This is why I hate the OGL fixed-func lighting - its difficult to control the lighting quality.

The problem most likely lies in one of these areas:

*) Model tessellation: - fixed func only really looks nice with high density meshes
*) Your specular lighting seems to be over powering the scene
*) Reduce the specular's color brightness. Does it have to be pure white
*) Increasethe Power Function of the specular reflection. In your setup code - the shineness factor. A lower number like 8.0 will actually spread out the specular highlight more widely than a high number like 128.0. Since in your scene the surfaces seem to be specular highlight saturated it might be because the materials your are emulating need to less dull (plastic - low shininess/reflective) and more metalic looking (high reflectivity/shineness)

*) Your are doing two sided lighting - really unless your trying to do sub-surface scattering or something. You really should stick to FRONT

*) Are you implementing directional or positional lighting?
If its positional lighting - how far is the light source from the model - is it too close and hence saturating the nearest polys.

Thanks for your tips :)

I've found out that if my shininess is the default value, 0, every vertex that is lit is completely white. When I picked a larger value, my scene was visible again.

Weird that the default value is zero..
Currently working on WalledIn

This topic is closed to new replies.

Advertisement