From 662a564a008e408acd609abb2ef460783ca45e4e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 13 Aug 2009 17:51:58 +0000 Subject: improved light/flare render code, disables engine activated lights on scenery --- src/render/draw.cc | 162 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 99 insertions(+), 63 deletions(-) diff --git a/src/render/draw.cc b/src/render/draw.cc index 150356c..3e2547c 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -863,6 +863,7 @@ void draw_pass_model_fx(float elapsed) float a = 0.0f; float light_size = 0.0f; bool power = true; + bool draw_quad = true; float thrust; //math::Vector3f quad[4]; @@ -903,33 +904,36 @@ void draw_pass_model_fx(float elapsed) // draw model lights for (model::Model::Lights::iterator lit = entity->model()->lights().begin(); lit != entity->model()->lights().end(); lit++) { light = (*lit); - - // engine flares - thrust = 1.0f; - if (light->engine() && ( entity->type() == core::Entity::Controlable)) { - core::EntityControlable *ec = static_cast(entity); - if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { - thrust = 1.0f; + draw_quad = true; + + // engine activated lights + if (light->engine()) { + if (entity->type() == core::Entity::Controlable) { + core::EntityControlable *ec = static_cast(entity); + if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { + thrust = 1.0f; + } else { + thrust = ec->thrust(); + if (thrust < 0.001f) { + draw_quad = false; + } + } } else { - thrust = ec->thrust(); + draw_quad = false; } } // strobe frequency - t = 1.0f; - if (light->strobe()) + if (draw_quad && light->strobe()) { + t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * light->frequency(); - if ((!light->strobe()) || (( t - floorf(t)) <= light->time())) { - location.assign(entity->location() + (entity->axis() * light->location())); - light_size = 0.0625 * light->radius(); - - // track stat changes - if (current_texture != light->texture()) { - gl::end(); - current_texture = Textures::bind(light->texture()); - gl::begin(gl::Quads); + if ((t - floorf(t)) > light->time()) { + draw_quad = false; } + } + // draw visible lights + if (draw_quad) { // default alpha is 0.8 a = 0.8f; if (light->entity()) { @@ -941,6 +945,18 @@ void draw_pass_model_fx(float elapsed) color.assign(light->color()); } color.a = a; + + location.assign(entity->location() + (entity->axis() * light->location())); + light_size = 0.0625f * light->radius(); + + // track OpenGL state changes + if (current_texture != light->texture()) { + gl::end(); + current_texture = Textures::bind(light->texture()); + gl::begin(gl::Quads); + } + + // draw the quad gl::color(color); glTexCoord2f(0,1); @@ -956,30 +972,65 @@ void draw_pass_model_fx(float elapsed) } // draw flares - for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { + for (model::Model::Flares::iterator flit = entity->model()->flares().begin(); flit != entity->model()->flares().end(); flit++) { flare = (*flit); - - // engine flares - thrust = 1.0f; - if (flare->engine() && ( entity->type() == core::Entity::Controlable)) { - core::EntityControlable *ec = static_cast(entity); - if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { - thrust = 1.0f; + draw_quad = true; + + // engine activated flares + if (flare->engine()) { + if (entity->type() == core::Entity::Controlable) { + core::EntityControlable *ec = static_cast(entity); + if ((ec->state() == core::Entity::ImpulseInitiate) || (ec->state() == core::Entity::Impulse)) { + thrust = 1.0f; + } else { + thrust = ec->thrust(); + if (thrust < 0.001f) { + draw_quad = false; + } + } } else { - thrust = ec->thrust(); + draw_quad = false; } } - + // strobe frequency - t = 1.0f; - if (flare->strobe()) - t = (core::application()->time() + ext_render(entity)->fuzz() - flare->offset()) * flare->frequency(); + if (draw_quad && flare->strobe()) { + + t = (core::application()->time() + ext_render(entity)->fuzz() - light->offset()) * flare->frequency(); + if ((t - floorf(t)) > light->time()) { + draw_quad = false; + } + } - if ((thrust > 0 ) && ((!flare->strobe()) || (( t - floorf(t)) <= flare->time()))) { + // calulcate viewing angle factor + if (draw_quad) { flare_axis.assign(entity->axis() * flare->axis()); + a = math::absf(dotproduct(flare_axis.forward(), Camera::axis().forward())); + + if (a < 0.01f) { + draw_quad = false; + } + } + + // draw visible flares + if (draw_quad) { + + // alpha decreases with viewing angle + a *= 0.8f; + if (flare->entity()) { + color.assign(entity->color()); + } else if (flare->engine()) { + color.assign(entity->model()->enginecolor()); + a *= thrust; + } else { + color.assign(flare->color()); + } + color.a = a; + location.assign(entity->location() + (entity->axis() * flare->location())); - light_size = 0.0625 * flare->radius(); - + light_size = 0.0625f * flare->radius(); + + // track OpenGL state changes if ((current_cull != flare->cull()) || (current_texture != flare->texture())) { gl::end(); @@ -1008,35 +1059,20 @@ void draw_pass_model_fx(float elapsed) gl::begin(gl::Quads); } + + // draw the quad + gl::color(color); - a = math::absf( dotproduct(flare_axis.forward(), Camera::axis().forward())); - if (a > 0.1f) { - - // alpha decreases as the viewing angle increases - a = a - 0.1f; - if (flare->entity()) { - color.assign(entity->color()); - } else if (flare->engine()) { - color.assign(entity->model()->enginecolor()); - a *= thrust; - } else { - color.assign(flare->color()); - } - color.a = a; - gl::color(color); - - glTexCoord2f(0,1); - gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); - glTexCoord2f(0,0); - gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); - glTexCoord2f(1,0); - gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); - glTexCoord2f(1,1); - gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); - - Stats::quads++; - } - + glTexCoord2f(0,1); + gl::vertex(location + (flare_axis.up() + flare_axis.left()) * light_size); + glTexCoord2f(0,0); + gl::vertex(location + (flare_axis.up() - flare_axis.left()) * light_size); + glTexCoord2f(1,0); + gl::vertex(location + (flare_axis.up() * -1 - flare_axis.left()) * light_size); + glTexCoord2f(1,1); + gl::vertex(location + (flare_axis.up() * -1 + flare_axis.left()) * light_size); + + Stats::quads++; } } -- cgit v1.2.3