From a1049d85d66264c790fa212f1c577a71890a03c9 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 8 Dec 2012 23:12:45 +0000 Subject: Added support for entity secondary color on lights, flares and particles. --- src/render/draw.cc | 49 +++++++++++++++++++++++++++++++++++++++++++------ src/render/draw.h | 6 +++--- src/render/particles.cc | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 81 insertions(+), 14 deletions(-) (limited to 'src/render') diff --git a/src/render/draw.cc b/src/render/draw.cc index 59f4a59..46d0906 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -782,7 +782,7 @@ void draw_pass_model_fragments() void draw_model_lights(model::Model *model, const float scale, const math::Vector3f & entity_location, const math::Axis & entity_axis, - const math::Color & entity_color, const float thrust, const float fuzz) + const math::Color & entity_color, const math::Color & entity_color_second, const float thrust, const float fuzz) { float t = 0.0f; float a = 0.0f; @@ -823,13 +823,31 @@ void draw_model_lights(model::Model *model, const float scale, // entity color overrides light color // light color overrides engine color if (light->entity()) { - color.assign(entity_color); + if (light->entity_second()) { + // entity tertiary color + for (size_t i = 0; i < 3; i++) { + color[i] = (entity_color[i] + entity_color_second[i]) / 2; + } + } else { + // entity primary color + color.assign(entity_color); + } + + } else if (light->entity_second()) { + // entity secondary color + color.assign(entity_color_second); + } else if (light->has_color()) { + // light color color.assign(light->color()); + } else if (light->engine()) { + // FIXME engine_color or thrust_activated color.assign(model->enginecolor()); + } else { color.assign(light->color()); + } // default alpha is 0.8, engine flag alters alpha @@ -890,16 +908,34 @@ void draw_model_lights(model::Model *model, const float scale, continue; // next flare } - // entity color overrides light color - // light color overrides engine color + // entity color overrides flare color + // flare color overrides engine color if (flare->entity()) { - color.assign(entity_color); + if (flare->entity_second()) { + // entity tertiary color + for (size_t i = 0; i < 3; i++) { + color[i] = (entity_color[i] + entity_color_second[i]) / 2; + } + } else { + // entity primary color + color.assign(entity_color); + } + + } else if (flare->entity_second()) { + // entity secondary color + color.assign(entity_color_second); + } else if (flare->has_color()) { + // flare color color.assign(flare->color()); + } else if (flare->engine()) { + // FIXME engine_color or thrust_activated color.assign(model->enginecolor()); + } else { color.assign(flare->color()); + } // default alpha is 0.8, engine flag alters alpha @@ -979,7 +1015,8 @@ void draw_pass_model_fx(float elapsed) const float modelscale = entity->radius() / entity->model()->radius(); draw_model_lights(entity->model(), modelscale, - entity->location(), entity->axis(), entity->color(), + entity->location(), entity->axis(), + entity->color(), entity->color_second(), ext_render(entity)->thrust(), ext_render(entity)->fuzz() ); } diff --git a/src/render/draw.h b/src/render/draw.h index 21145c2..122d7cd 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -34,10 +34,10 @@ void draw_sphere(const math::Color & color, float radius); void draw_globe_corona(const math::Vector3f location, const math::Color & color, const float radius, const size_t corona_id); /// draw mode lights and flares -void draw_model_lights(model::Model *model, const float scale, +void draw_model_lights( + model::Model *model, const float scale, const math::Vector3f & entity_location, const math::Axis & entity_axis, - const math::Color & entity_color, const float thrust, const float fuzz -); + const math::Color & entity_color, const math::Color & entity_color_second, const float thrust, const float fuzz); /// draw a model void draw_model_fragments(model::Model *model, diff --git a/src/render/particles.cc b/src/render/particles.cc index d5db8cf..fc27234 100644 --- a/src/render/particles.cc +++ b/src/render/particles.cc @@ -296,32 +296,62 @@ ParticleSystem::ParticleSystem(const ParticleScript *script, const core::Entity particlesystem_radius = 1.0f; if (particlesystem_script) { + // initial particle system parameters are set by the script particlesystem_texture = Textures::load("textures/" + particlesystem_script->texture()); particlesystem_radius = particlesystem_script->radius(); particlesystem_cull = particlesystem_script->cull(); - // allow the script to override itself if (particlesystem_script->entity()) { - particlesystem_color.assign(entity->color()); + + if (particlesystem_script->entity_second()) { + // entity tertiary color + for (size_t i = 0; i < 3; i++) { + particlesystem_color[i] = (entity->color()[i] + entity->color_second()[i]) / 2; + } + } else { + // entity primary color + particlesystem_color.assign(entity->color()); + } + } else if (particlesystem_script->entity_second()) { + // entity secondary color particlesystem_color.assign(entity->color_second()); + } else if (particlesystem_script->engine()) { + // FIXME engine_color or thrust_activated particlesystem_color.assign(entity->model()->enginecolor()); + } else { particlesystem_color.assign(particlesystem_script->color()); - } - + } particlesystem_axis.assign(particlesystem_script->axis()); } if (particlesystem_modelclass) { + // the modeltag can override the script parameters particlesystem_radius *= particlesystem_modelclass->scale(); if (particlesystem_modelclass->entity()) { - particlesystem_color.assign(entity->color()); + + if (particlesystem_modelclass->entity_second()) { + // entity tertiary color + for (size_t i = 0; i < 3; i++) { + particlesystem_color[i] = (entity->color()[i] + entity->color_second()[i]) / 2; + } + } else { + // entity primary color + particlesystem_color.assign(entity->color()); + } + + } else if (particlesystem_modelclass->entity_second()) { + // entity secondary color + particlesystem_color.assign(entity->color_second()); + } else if (particlesystem_modelclass->has_color()) { particlesystem_color.assign(particlesystem_modelclass->color()); + } else if (particlesystem_modelclass->engine()) { + // FIXME engine_color or thrust_activated particlesystem_color.assign(entity->model()->enginecolor()); } -- cgit v1.2.3