From 3f9bcac4f188dc5cbad317d875c7642ded33c045 Mon Sep 17 00:00:00 2001 From: Evan Goers Date: Wed, 4 Jan 2012 19:56:47 +0000 Subject: Various lighting tweaks and enhancements. --- src/render/draw.cc | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/render/draw.cc') diff --git a/src/render/draw.cc b/src/render/draw.cc index 2236d8c..0f39385 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -62,14 +62,25 @@ void pass_reset_lights() { // lighting settings for the default light GL_LIGHT0 GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat ambient_light[] = { r_ambient->value(), r_ambient->value(), r_ambient->value(), 1.0f }; - GLfloat diffuse_light[] = { r_diffuse->value(), r_diffuse->value(), r_diffuse->value(), 1.0f }; - GLfloat specular_light[] = { r_specular->value(), r_specular->value(), r_specular->value(), 1.0f }; + GLfloat ambient_light[4]; + GLfloat diffuse_light[4]; + GLfloat specular_light[4]; for (size_t i = 0; i < 3; i++) { light_position[i] = Camera::eye()[i]; + ambient_light[i] = r_ambient->value(); + diffuse_light[i] = r_diffuse->value(); + specular_light[i] = r_specular->value(); } + ambient_light[3] = 1.0; + diffuse_light[3] = 1.0; + specular_light[3] = 1.0; + + glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2); + glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1); + glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5); + glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); @@ -127,21 +138,28 @@ void pass_prepare(float seconds) // bright globes set level light GLfloat diffuse_light[4]; - GLfloat ambient_light[] = { 0.0f, 0.0f, 0.0f, 1.0f }; - GLfloat specular_light[] = { r_specular->value(), r_specular->value(), r_specular->value(), 1.0f }; + GLfloat ambient_light[4]; + GLfloat specular_light[4]; for (size_t i = 0; i < 3; i++) { zone_light[i] = globe->location()[i]; zone_color[i] = globe->color()[i]; - diffuse_light[i] = globe->color()[i] * (r_diffuse->value() * 2); + ambient_light[i] = globe->color()[i] * (r_ambient->value() * 0.1); + diffuse_light[i] = globe->color()[i] * (r_diffuse->value() * 0.8); + specular_light[i] = globe->color()[i] * (r_specular->value() * 0.4); } zone_light[3] = 1.0f; + ambient_light[3] = 1.0f; diffuse_light[3] = 1.0f; + specular_light[3] = 1.0f; + + glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.0001); glLightfv(GL_LIGHT1, GL_POSITION, zone_light); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient_light); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT1, GL_SPECULAR, specular_light); + gl::enable(GL_LIGHT1); has_zone_light = true; } @@ -329,7 +347,7 @@ void draw_globe(const core::EntityGlobe* globe) gl::enable(GL_TEXTURE_2D); } - // draw the globe an apply rotation if required + // draw the globe and apply rotation if required gl::push(); gl::translate(location); gl::multmatrix(globe->axis()); -- cgit v1.2.3