PDA

View Full Version : vertex program / light



gemelli_d
07-26-2004, 12:32 AM
hello,
I think I'm doing a stupid mistake but I can't figure where it is:
I am rendering a terrain (no lighting), then I'm using a vertex program for the water (no lighting), finally I am rendering objects (ligthing activated).
The result: sometime I have all my objects rendered using lighting, sometime I have all my objects rendered without lighting...If I do not use my vertex program, everything is fine. If I use my vertex program and do "glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)" everything is fine too...

thanks for any hint about that.

plasmonster
07-26-2004, 09:20 AM
If I do not use my vertex program, everything is fine.When you use vertex programs, you subsume the lighting calculations. So it's likely that's where your problem is. Make sure your normals and vertices are in the same space as the light. Typically, this is eye-space, but it doesn't matter, as long as you're consistent about it. For eye-space, you need to transform the incoming object normals with the inverse transpose of the modelview matrix.

Perhaps you could post your VP source for inspection.

gemelli_d
07-26-2004, 10:15 PM
I did not precise it clearly but, when rendering my objects (the ones that get no lighting), I am not using my vertex program anymore...it is disabled...my VP code is (as far as I know) not responsible of the problem...
the rendering is like this:

- terrain (no light, no VP)
- water (no light, VP)
- objects (light, no VP)

thanks.

plasmonster
07-27-2004, 08:00 AM
As I understand it, you're having trouble with light and objects. Could you post the suspect code?

gemelli_d
07-28-2004, 10:29 PM
here it is :


// SETUP (once)
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, pEnv->GetFogStart());
glFogf(GL_FOG_END, pEnv->GetFogEnd());
glFogfv(GL_FOG_COLOR, color);
glFogi(GL_FOG_COORDINATE_SOURCE, GL_FRAGMENT_DEPTH);
glHint(GL_FOG_HINT, GL_NICEST);
glEnable(GL_FOG);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glAlphaFunc(GL_GREATER, 0.5f);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, m_mipmappingBias);
glShadeModel(GL_SMOOTH);
glDisable(GL_AUTO_NORMAL);
glDisable(GL_NORMALIZE);
glDisable(GL_VERTEX_PROGRAM_TWO_SIDE_ARB);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
this part is simplified for the post, I removed everything related to transparent faces, bump mapping, detail textures and other things...so
some states changes can be redundant or useless (and the "objects" section is originaly part of a loop)
I tested my application with 2 objects objects that correspond to this limitation and I get the same result.


// RENDER (each frame)
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightCol);

//---terrain
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);

glActiveTextureARB(GL_TEXTURE0_ARB);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);
// ... setup arrays
// render using glDrawRangeElements

//---water
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_CULL_FACE);
glNormal3f(0.0, 0.0, 1.0);
glDisable(GL_TEXTURE_2D);
// ... setup arrays

here is the vertex program...If I'm not using it, everything is ok

glEnable(GL_VERTEX_PROGRAM_ARB);
glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vpID);
// render using glDrawArrays
glDisable(GL_VERTEX_PROGRAM_ARB);
glEnable(GL_CULL_FACE);
glDisableClientState(GL_COLOR_ARRAY);

if I'm using the vertex program for the water, I need to add:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
before the next section

//---objects
glActiveTextureARB(GL_TEXTURE0_ARB);
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
// ... setup material
glMaterialfv(GL_FRONT, GL_EMISSION, matEm);
glMaterialfv(GL_FRONT, GL_DIFFUSE, color);
glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
glMaterialfv(GL_FRONT, GL_SPECULAR, matSpe);
glMaterialf(GL_FRONT, GL_SHININESS, matShi);
// ... setup arrays
// render using glDrawRangeElements

thanks for your time...

plasmonster
07-29-2004, 09:13 AM
Well, I don't see anything wrong with the chunks you posted. But it's simply a bunch of state changes; it's hard to glean much from that alone. I understand that you probably ripped this out of a large project, and that can be difficult.

I generally recommend building a very simple test app for the problem case; I would advise you to do this for any problem you may have (it sure makes debugging a lot easier).

I'm still having trouble understanding exactly what the problem is. What exactly are you trying to do, and how is the result different from what you expect?

gemelli_d
07-29-2004, 10:20 PM
yes, this "code" is taken from my game project.
the exact problem (as far as I can explain it in english) is:

-I am rendering a terrain with lighting disabled.
-I am rendering water with lighting disabled and using a vertex program.
-I am rendering objects with ligthing enabled.

problem: my objects are not lit.

2 "solutions" for the problem:
-do not use the vertex program (with exactly the same code without using the vertex program, everything is OK)
-add "glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);" before rendering the objects

as you can see, none of the "solution" is acceptable.

this weekend I'll do a test app...

thanks again.

gemelli_d
08-15-2004, 10:54 PM
I have a better way to get my lighting work, I do not use glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE) anymore but, before rendering my water using the vertex program, I use glEnable(GL_LIGHTING)...and it works...I still don't understand what happens but this is the best solution I can find.