OpenGL Showing only half of light

Started by BlackHistory, June 06, 2015, 04:13:59

Previous topic - Next topic

BlackHistory

Trying to get a spotlight to work in OpenGL, no matter what I do it only draws the light within a 180 degree semi-circle, the picture shows the light on the border.
Lighting Inilization code:
glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glLightModel(GL_LIGHT_MODEL_AMBIENT,asFlippedFloatBuffer(new float[]{0.5f, 0.5f, 0.5f, 1f}));
    glLight(GL_LIGHT0,GL_DIFFUSE,asFlippedFloatBuffer(new float[]{1.0f, 1.0f, 1.0f, 1f}));
    glLight(GL_LIGHT0, GL_POSITION, asFlippedFloatBuffer(new float[]{0, 0, 5, 1}));
    glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,45f);
    glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,0.0f);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glShadeModel(GL_SMOOTH);

Code ran every loop:


glLight(GL_LIGHT0,GL_SPOT_DIRECTION,asFlippedFloatBuffer(LightDir));
     glLight(GL_LIGHT0,GL_POSITION,asFlippedFloatBuffer(LightPos));

Misc:


float[] LightDir = new float[]{0,-1,0,1};         
 float[] LightPos = new float[]{0,5,0,1};

Heres what it looks like:
Without per-pixel shader

with per-pixel shader


Has anyone seen this before? What needs to be done to fix. I haven't gotten it to successfully work at all

Kai

I have one assumption: The smooth transition from lit to unlit makes it look like the normals of the surface are wrong.
If this is the "top" surface of a cube, then maybe the normals of the lower two corners point to the viewer or even downwards (i.e. away from the light) or are otherwise degenerate (such as zero, where also glEnable(GL_NORMALIZE) would not change that).

BlackHistory

It's not the normals, I can move the light around the plane and it happens relative to the lights position. I just show it in the center because it looks the best. I'm actually using a inverted sphere now to test it.