I’ve got a directional light working to light my solar system correctly (note, this is not just a bunch of spheres I placed randomly… all of the distances are correct down to the meter, etc. I have to scale and translate the rendered objects to keep them inside of the z-buffer each frame. This is done outside of GL, before passing any objects to the renderer.
Earlier I had a problem getting directional light to work. It turned out this was because I was using the transformed positions of the rendered objects. If two objects were both outside of the z-range they could be “moved” inside of the z-range and their relative positions were incorrect (or even on top of one another). I fixed this by using the pre-transformed positions to calculate the light direction for the infinite lights.
However, I now cannot get a specular highlights to show up.
It doesn’t matter if I have textures turned on or off.
I am 99.9% positive I have all of the lighting parameters set up correctly.
I set up the material properties so:
// initial lighting values
static flt g_fAmbient [4] =
{
0.1f, 0.1f, 0.1f, 1.0f
};
static flt g_fDiffuse [4] =
{
0.9f, 0.9f, 0.9f, 0.9f
};
static flt g_fSpecular [4] =
{
1.0f, 1.0f, 1.0f, 1.0f
};
static flt g_fGlobalAmbient [4] =
{
0.0f, 0.0f, 0.0f, 1.0f
};
static flt g_fEmission [4] =
{
0.0f, 0.0f, 0.0f, 1.0f
};
glDisable (GL_LIGHTING);
glDisable (GL_COLOR_MATERIAL);
glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat*)&g_fEmission);
glMaterialfv (GL_FRONT, GL_AMBIENT, (GLfloat*)&g_fAmbient);
glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat*)&g_fDiffuse);
glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat*)&g_fSpecular);
glMaterialf (GL_FRONT, GL_SHININESS, 128.0f);
glLightModelf (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModelf (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glLightModelfv (GL_LIGHT_MODEL_AMBIENT, g_fGlobalAmbient);
glLightModelf (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
The light is set up like this:
int nID = g_nLightID [m_nNumVisibleLights];
glLightfv (nID, GL_AMBIENT, (GLfloat*)g_fAmbient);
CColor Color;
pLight->GetColor (Color);
flt fDiffuse [4];
fDiffuse [0] = (Color.m_nRed * ONE_OVER_255) * g_fDiffuse [0];
fDiffuse [1] = (Color.m_nGreen * ONE_OVER_255) * g_fDiffuse [1];
fDiffuse [2] = (Color.m_nBlue * ONE_OVER_255) * g_fDiffuse [2];
glLightfv (nID, GL_DIFFUSE, (GLfloat*)fDiffuse);
glLightfv (nID, GL_SPECULAR, (GLfloat*)&g_fSpecular);
// no falloff
glLightf (nID, GL_CONSTANT_ATTENUATION, 1.0f);
glLightf (nID, GL_LINEAR_ATTENUATION, 0.0f);
glLightf (nID, GL_QUADRATIC_ATTENUATION, 0.0f);
vec vDir;
pLight->GetDirToObject (pObj, vDir);
g_fLightPos [0] = vDir.x;
g_fLightPos [1] = vDir.y;
g_fLightPos [2] = vDir.z;
g_fLightPos [3] = 0.0f;
glLightfv (g_nLightID [i], GL_POSITION, (GLfloat*)g_fLightPos);
My question is… do directional (infinite) lights not provide specular highlights, or am I doing something wrong? I’m using an infinite light because I need the rays to be parallel (otherwise the sphere is not lit correctly because the light inside of the z-range, i.e. relatively close compared to the size of the sphere). I could use a positional light and move it away from the sphere until the rays are almost parallel, but do I need to do that?
[This message has been edited by doc_colgate (edited 09-03-2002).]
[This message has been edited by doc_colgate (edited 09-03-2002).]