aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/shaders/lighting.vert13
-rw-r--r--src/render.c4
2 files changed, 12 insertions, 5 deletions
diff --git a/data/shaders/lighting.vert b/data/shaders/lighting.vert
index 914d6ac..ad6ef27 100644
--- a/data/shaders/lighting.vert
+++ b/data/shaders/lighting.vert
@@ -22,10 +22,14 @@ varying vec3 col_emit;
void main() {
+ vec3 E, L;
+
/* Spotlight - positional light */
- vec4 vert = gl_ModelViewMatrix * gl_Vertex;
- light0vc = gl_LightSource[0].position.xyz - vert.xyz;
- light0hvc = vec3(gl_LightSource[0].halfVector - vert);
+ vec3 vert = vec3(gl_ModelViewMatrix * gl_Vertex);
+ light0vc = normalize(vec3(gl_LightSource[0].position) - vert);
+ E = vec3(0.0, 0.0, 1.0) - vert;
+ L = vec3(gl_LightSource[0].position) - vert;
+ light0hvc = normalize(E + L);
/* Diffuse "background glow" - this can be normalised only once, here, since 'position'
* is really 'direction' and is the same for all vertices. */
@@ -33,7 +37,8 @@ void main() {
/* Fill-in light */
light2vc = normalize(vec3(gl_LightSource[2].position));
- light2hvc = normalize(vec3(gl_LightSource[2].halfVector - vert));
+ L = vec3(gl_LightSource[2].position) - vert;
+ light2hvc = normalize(E + L);
/* Material properties */
normal = gl_NormalMatrix * gl_Normal;
diff --git a/src/render.c b/src/render.c
index 0d3f7fa..bd4ef60 100644
--- a/src/render.c
+++ b/src/render.c
@@ -213,6 +213,8 @@ RenderContext *render_setup(int width, int height, int disable_vbos, int disable
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
+
if ( r->fbos ) {
/* FBO for rendering swirlyness */
@@ -482,7 +484,7 @@ static void render_setup_lighting(Game *game) {
/* A fill-in light, only used on its own, to light the lander craft itself */
glLightfv(GL_LIGHT2, GL_AMBIENT, ambient); /* Initialised to zero above */
- pos[0] = -1.0; pos[1] = 0.8; pos[2] = 4.0; pos[3] = 0.0;
+ pos[0] = 0.0; pos[1] = 0.0; pos[2] = 4.0; pos[3] = 0.0;
glLightfv(GL_LIGHT2, GL_POSITION, pos);
diffuse[0] = 0.3; diffuse[1] = 0.3; diffuse[2] = 0.3; diffuse[3] = 1.0;
glLightfv(GL_LIGHT2, GL_DIFFUSE, diffuse);