Hello Guest

OpenGL Showing only half of light

  • 2 Replies
  • 3708 Views
OpenGL Showing only half of light
« on: June 06, 2015, 04:13:59 »
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:
Code: [Select]
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:


Code: [Select]
glLight(GL_LIGHT0,GL_SPOT_DIRECTION,asFlippedFloatBuffer(LightDir));
     glLight(GL_LIGHT0,GL_POSITION,asFlippedFloatBuffer(LightPos));
Misc:


Code: [Select]
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
« Last Edit: June 06, 2015, 05:56:18 by BlackHistory »

*

Kai

Re: OpenGL Showing only half of light
« Reply #1 on: June 06, 2015, 11:05:20 »
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).
« Last Edit: June 06, 2015, 11:08:59 by Kai »

Re: OpenGL Showing only half of light
« Reply #2 on: June 06, 2015, 15:21:25 »
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.