-1

I'm trying to light a scene with a few simple objects. I have two lights, one spot light and one point light and the lighting seems to work fine on the objects in the scene, but when it comes to the textured floor its only affected by ambient and I can't figure out why. I thought it had something to do with normals by I defined it as I think it should be, pointing up. if I remove the texture I get the same results. what did I do wrong?

here is my code:

void drawFloor()
{
    setMaterial(mat_specularFloor, mat_specularFloor, mat_specularFloor, mat_specularFloor);
    //glColor3f(1.0, 1.0, 1.0);
    glEnable(GL_TEXTURE_2D);
    //glEnable(GL_NORMALIZE);
    glBindTexture(GL_TEXTURE_2D, g_Texture[0]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    //glColor3f(.5, 0.5, 0.7);
    glBegin(GL_TRIANGLE_FAN);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f, 0.0f);

    glVertex3f(-50, 0, -50);
    glTexCoord2f(10.0f, 0.0f);
    glVertex3f( 50, 0, -50);
    glTexCoord2f(10.0f, 10.0f);
    glVertex3f( 50, 0,  50);
    glTexCoord2f(0.0f, 10.0f);
    glVertex3f(-50, 0,  50);
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

enter image description here

Amit Ofer
  • 413
  • 1
  • 7
  • 26
  • When you say it's unaffected: is the light stationary? – Tommy Aug 17 '15 at 20:37
  • Do you have `GL_LIGHTING` enabled, when drawing the floor? – ProXicT Aug 17 '15 at 20:49
  • Yes, both lights are stationary, you can move the spotlight with the keyboard. GL_LIGHTING was enable before drawing the floor. in fact the table and teapot are drawn right after the floor and these are lit just fine. – Amit Ofer Aug 17 '15 at 21:31
  • 1
    In the fixed pipeline, lighting is calculated per vertex, and then interpolated. So if you draw the floor as one very large quad, the lighting calculations are only performed on the corners, and the result is linearly interpolated across the whole floor. – Reto Koradi Aug 18 '15 at 04:10
  • Yeah thats right, but the same goes for the big polygon on the table, but its light isn't floor so the floor shouldn't be as well – Amit Ofer Aug 18 '15 at 05:09
  • shouldn't you call glNormal3f one time per vertex ? So four times and not one time like you do for glVertex3f / glTexCoord2f ? – VB_overflow Aug 18 '15 at 07:17
  • I tried that, I saw in an example that it was redundant so I removed the extra 3 calls – Amit Ofer Aug 18 '15 at 07:41
  • 2
    The quad for the table looks much smaller than the floor. – Reto Koradi Aug 18 '15 at 13:54
  • I thought about this as a possibility. maybe all the 4 vertices are too far from the light so all the corners are dark which makes the entire polygon dark. I will try to subdivide it better today. is it possible to divide it into a lot of quads but only map the texture to the 4 original vertices? – Amit Ofer Aug 18 '15 at 15:34

2 Answers2

0

I am not familiar with fixed function pipeline this can be fixed by using a newer version of opengl and using shaders for per pixel lighting. One possible way to fix this is to subdivide the floor so it is made of many smaller sections. Since opengl is running the calculation one for each vertex your light is being averaged out and if you were to subdivide it each section the light will have more impact on

htuacc
  • 1
  • 2
0

ok so the main problem with my lighting was that it was just one giant polygon and because it was so big I didn't get any lighting at the vertices so there was nothing to interpolate.

Now I'm getting the diffuse lighting of the spotlight but I don't seem to get specular highlight. Is it even possible to get a specular highlight on a plane? If so, what else do I need to do to fix this? I need to make the floor look shiny.

Amit Ofer
  • 413
  • 1
  • 7
  • 26