Lighting

Started by DavidYazel, July 05, 2003, 03:34:07

Previous topic - Next topic

DavidYazel

I am getting some really strange things happening in lighting.  I have one ambient light:

       Color3f c = leaf.getColor();
        floatBuffer4.clear();
        floatBuffer4.put(c.x);
        floatBuffer4.put(c.y);
        floatBuffer4.put(c.z);
        floatBuffer4.put(1);
        gl.lightModelfv(GL.LIGHT_MODEL_AMBIENT, floatBuffer4Addr);
        gl.lightfv(GL.LIGHT0, GL.AMBIENT, floatBuffer4Addr);
        gl.enable(GL.LIGHT0);


and one material

               gl.enable(GL.LIGHTING);
                gl.materiali(GL.FRONT_AND_BACK, GL.SHININESS,
                             (int) material.getShininess());

                Color3f c = material.getAmbientColor();
                floatBuffer4.clear();
                floatBuffer4.put(c.x);
                floatBuffer4.put(c.y);
                floatBuffer4.put(c.z);
                floatBuffer4.put(1f); // 1.0 is the alpha
                gl.materialf(GL.FRONT, GL.AMBIENT, floatBuffer4Addr);


the ambient color is 0.2,0.2,02 and the ambient material is 1,1,1

There are vertex colors of different kinds also.

So this is what is happening.

1. The vertex colors are being completely ignored
2. The objects are shown in pure white
3. When I rotate the object it gets darker and darker and then snaps back to white.

If I disable lighting then my vertex colors work.  There is no directional light, just this one ambient one, so I can't understand why the color changes as it rotates.  

Are there any LWJGL bugs in lighting?  Any possibility that GL.AMBIENT is the wrong value?

DavidYazel

Ok one problem is that I needed to enable:

gl.enable(GL.COLOR_MATERIAL);

This now has the material * vertex color.

But the colors are now going from correct to pure white and back again as the object rotates.

I should not need to set a light position for ambient light right?

DavidYazel

Got it!  For some reason I have to use LIGHT1 and not LIGHT0.

Works like a champ now!

Dave

cfmdobbie

There's one difference between LIGHT0 and any other light - the defaults are different for the Diffuse and Specular components.  LIGHT0 has these both set to (1, 1, 1, 1) while the rest have them set to (0, 0, 0, 0).  This is probably the root of your problem.
ellomynameis Charlie Dobbie.

Matzon

to lessen the eye pain of all the put's - you could do:

floatBuffer4.clear();
 floatBuffer4.put(c.x).put(c.y).put(c.z);.put(1f);

princec

or even
floarBuffer4.clear();
floatBuffer4.put(new float[] {c.x, c.y, c.z, 1.0f});

But that might not be so good in a rendering loop because of the new().

Cas :)

oNyx

Quote from: "Matzon"to lessen the eye pain of all the put's - you could do:

floatBuffer4.clear();
 floatBuffer4.put(c.x).put(c.y).put(c.z);.put(1f);

/me points at the first ';' in the 2nd line :>

princec

Must fix that horrible orange colour. I can hardly read it.

Cas :)

cfmdobbie

Could be worse...
ellomynameis Charlie Dobbie.

Matzon

yeah it could! LOL

Matzon

ARGH of course my white text gets positioned in the grey one !!! luckily this means that this must be a white one good thing :)