Main Menu

Lighting

Started by zFollette, January 12, 2014, 17:33:26

Previous topic - Next topic

zFollette

I have added normals to my project, I am pretty sure they are added right, but my lighting is weird.



The raised block is 0, 0, 0 and my light position is -1, 0, -1

Here is some code:

Normals:
float[] normalData = new float[]{
                            /*Front Normal*/
                            0, 0, 1,
                            
                            /*Back Normal*/
                            0, 0, -1,
                            
                            /*Left Normal*/
                            -1, 0, 0,
                            
                            /*Right Normal*/
                            1, 0, 0,
                            
                            /*Bottom Normal*/
                            0, -1, 0,
                            
                            /*Top Normal*/
                            0, 1, 0
                        };


They are in that order to correspond to the order in which I generate my faces.

Lighting:

glEnable(GL_LIGHTING);
            glEnable(GL_LIGHT0);
            glLight(GL_LIGHT0, GL_AMBIENT, compileBuffer(new float[]{1.5f, 1.5f, 1.5f, 1f}));
            glLight(GL_LIGHT0, GL_DIFFUSE, compileBuffer(new float[]{1.5f, 1.5f, 1.5f, 1f}));
            glLight(GL_LIGHT0, GL_POSITION, compileBuffer(new float[]{light.x, light.y, light.z, 1}));


Normals Rendering:
glBindBuffer(GL_ARRAY_BUFFER, normal);
        glNormalPointer(GL_FLOAT, 0, 0);


Normals Buffering:

glBindBuffer(GL_ARRAY_BUFFER, normal);
        glBufferData(GL_ARRAY_BUFFER, normalBuffer, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, 0);


I hope that somewhere along this chain of code is my problem.

Fool Running

If you're using shaders, make sure you are multiplying the normals by the correct matrix.
Have you tried moving the light around? What happens then?

Also your lighting color arrays look suspicious (new float[]{1.5f, 1.5f, 1.5f, 1f}). Unless you are doing HDR rendering, the float values should be in the range of 0 to 1.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D