Commit 9d20cf07 authored by Georg Schaefer's avatar Georg Schaefer
Browse files

add the posibillity for rendering several tractor beams

parent 3b552a2d
......@@ -9,11 +9,6 @@ uniform sampler2D albedo_texture;
uniform bool invert;
void main() {
vec3 beam_color = vec3(0.2f, 0.8f, 0.9f);
if (invert) {
beam_color = vec3(1.f, 0.5f, 0.f);
}
frag_color = texture(albedo_texture, texcoord_);
frag_color.xyz *= beam_color;
frag_color.xyz *= color;
}
......@@ -22,6 +22,16 @@ namespace gdw {
class staticmesh_component;
}
namespace gdw {
struct tractor_beam {
glm::mat4 beam_model;
float beam_length;
float beam_scale;
bool invert_beam;
glm::vec3 color;
};
}
namespace gdw {
class rendering_system {
private:
......@@ -62,11 +72,7 @@ namespace gdw {
program traktor_beam_program_;
mesh_ptr traktor_beam_;
mesh_ptr traktor_beam_stripes_;
glm::mat4 beam_model_;
float beam_length_;
float beam_scale_;
bool render_beam_;
bool invert_beam_;
std::vector<tractor_beam> tractor_beams_;
vertex_layout simple_render_layout_;
program simple_render_program_;
......@@ -124,7 +130,7 @@ namespace gdw {
void update_instance_per_frame(unsigned long long id, bool per_frame);
void rebake_shadows();
void render_trakor_beam(const glm::vec3& position, const glm::quat& rotation, float length, float radius, bool invert);
void render_trakor_beam(const glm::vec3& position, const glm::quat& rotation, float length, float radius, bool invert, const glm::vec3& color = glm::vec3(1.f));
private:
void render_gbuffer(float delta_time, camera_component& camera);
......
......@@ -201,10 +201,10 @@ namespace gdw {
if (input.isMouseButtonDown(inputMaping::beam_normal)) {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
engine_.rendering_system().render_trakor_beam(r.source, rot, ray_length, 1.f, false);
engine_.rendering_system().render_trakor_beam(r.source, rot, ray_length, 1.f, false, glm::vec3(0.2f, 0.8f, 0.9f));
} else {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
engine_.rendering_system().render_trakor_beam(r.source, rot, ray_length, 1.f, true);
engine_.rendering_system().render_trakor_beam(r.source, rot, ray_length, 1.f, true, glm::vec3(1.f, 0.5f, 0.f));
}
}
}
......
......@@ -672,27 +672,35 @@ namespace gdw {
auto projection = camera.projection();
auto view = camera.view();
if (render_beam_) {
static float accumulated_time = 0.f;
accumulated_time += delta_time;
if (accumulated_time / 2.f >= 4.f) {
accumulated_time = 0.f;
}
static float accumulated_time_stripes = 0.f;
accumulated_time_stripes += delta_time;
if (accumulated_time_stripes >= 4.f) {
accumulated_time_stripes = 0.f;
}
traktor_beam_program_.use();
traktor_beam_program_.uniform("projection", false, projection);
traktor_beam_program_.uniform("view", false, view);
for (auto& beam : tractor_beams_) {
float sign = 1.f;
if (invert_beam_) {
if (beam.invert_beam) {
sign = -1.f;
}
glCullFace(GL_FRONT);
static float accumulated_time = 0.f;
accumulated_time += delta_time;
if (accumulated_time / 2.f >= beam_length_ / 4.f) {
accumulated_time = 0.f;
}
traktor_beam_program_.use();
traktor_beam_program_.uniform("projection", false, projection);
traktor_beam_program_.uniform("view", false, view);
traktor_beam_program_.uniform("model", false, beam_model_);
traktor_beam_program_.uniform("mit", false, glm::inverseTranspose(beam_model_));
traktor_beam_program_.uniform("beam_length", beam_scale_);
traktor_beam_program_.uniform("model", false, beam.beam_model);
traktor_beam_program_.uniform("beam_length", beam.beam_scale);
traktor_beam_program_.uniform("offset", sign * accumulated_time / 2.f);
traktor_beam_program_.uniform("albedo_texture", 0);
traktor_beam_program_.uniform("invert", invert_beam_);
traktor_beam_program_.uniform("color", beam.color);
traktor_beam_program_.uniform("invert", beam.invert_beam);
traktor_beam_->draw(traktor_beam_program_);
glCullFace(GL_BACK);
......@@ -700,12 +708,6 @@ namespace gdw {
traktor_beam_program_.uniform("offset", sign * accumulated_time / 2.f);
traktor_beam_->draw(traktor_beam_program_);
static float accumulated_time_stripes = 0.f;
accumulated_time_stripes += delta_time;
if (accumulated_time_stripes / 2.f >= beam_length_ / 4.f) {
accumulated_time_stripes = 0.f;
}
glCullFace(GL_FRONT);
traktor_beam_program_.use();
......@@ -716,9 +718,8 @@ namespace gdw {
traktor_beam_program_.uniform("offset", sign * accumulated_time_stripes);
traktor_beam_stripes_->draw(traktor_beam_program_);
render_beam_ = false;
}
tractor_beams_.clear();
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
......@@ -763,15 +764,17 @@ namespace gdw {
baked_ = false;
}
void rendering_system::render_trakor_beam(const glm::vec3& position, const glm::quat& rotation, float length, float radius, bool invert) {
beam_scale_ = radius / length * 4.f;
beam_length_ = length;
beam_model_ = glm::mat4(1.f);
beam_model_ *= glm::translate(glm::mat4(1.f), position);
beam_model_ *= glm::toMat4(rotation);
beam_model_ *= glm::scale(glm::mat4(1.f), glm::vec3(radius, radius, length));
render_beam_ = true;
invert_beam_ = invert;
void rendering_system::render_trakor_beam(const glm::vec3& position, const glm::quat& rotation, float length, float radius, bool invert, const glm::vec3& color) {
tractor_beam beam;
beam.beam_scale = radius / length * 4.f;
beam.beam_length = length;
beam.beam_model = glm::mat4(1.f);
beam.beam_model *= glm::translate(glm::mat4(1.f), position);
beam.beam_model *= glm::toMat4(rotation);
beam.beam_model *= glm::scale(glm::mat4(1.f), glm::vec3(radius, radius, length));
beam.invert_beam = invert;
beam.color = color;
tractor_beams_.emplace_back(beam);
}
void rendering_system::register_component(camera_component* component) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment