Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-08-13 17:51:58 +0000
committerStijn Buys <ingar@osirion.org>2009-08-13 17:51:58 +0000
commit662a564a008e408acd609abb2ef460783ca45e4e (patch)
treedb6415a02a7afb4ffd9a43f8e62cbcd91577d74a
parent9f8804390d9ad183a05dc5f4d8f99627e71a791e (diff)
improved light/flare render code, disables engine activated lights on scenery
-rw-r--r--src/render/draw.cc162
1 files 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<core::EntityControlable *>(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<core::EntityControlable *>(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<core::EntityControlable *>(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<core::EntityControlable *>(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++;
}
}