#include <msp/fs/dir.h>
+#include <msp/gl/directionallight.h>
+#include <msp/gl/lighting.h>
#include <msp/gl/sequencebuilder.h>
+#include <msp/gl/pointlight.h>
#include <msp/gl/renderer.h>
-#include <msp/gl/tests.h>
#include <msp/input/keys.h>
#include <msp/time/utils.h>
#include "desertpillars.h"
{
wnd_opts.width = 1920;
wnd_opts.height = 1080;
- gl_opts.gl_version_major = Graphics::GLOptions::LATEST_VERSION;
- gl_opts.core_profile = true;
}
DesertPillars::DesertPillars(int, char **):
window(display, opts.wnd_opts),
- gl_ctx(window, opts.gl_opts),
+ gl_device(window),
keyboard(window),
- view(window, gl_ctx),
- camera(resources.get<GL::Camera>("Camera.camera")),
+ resources(&res_mgr),
+ view(window),
+ lighting(resources.get<GL::Lighting>("Desert.lightn")),
sphere(resources.get<GL::Object>("Sphere.object")),
sphere_morph(0.0f),
sphere_frozen(false),
sphere_stopped(false),
+ sun(resources.get<GL::DirectionalLight>("Sun.light")),
+ sun_angle(Geometry::Angle<float>::from_turns(0.1f)),
+ wisp(resources.get<GL::PointLight>("Wisp.light")),
+ flare(resources.get<GL::Object>("Flare.object"), lighting.find_light_index(wisp)),
camera_stopped(false)
{
window.set_title("Desert Pillars");
window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &DesertPillars::exit), 0));
keyboard.signal_button_press.connect(sigc::bind_return(sigc::mem_fun(this, &DesertPillars::key_press), false));
- GL::Light &sun = resources.get<GL::Light>("Sun.light");
- sky = make_unique<GL::Sky>(content, sun);
- sky->set_debug_name("Sky");
-
- shadow_seq = make_unique<GL::Sequence>();
- shadow_seq->set_clear_enabled(true);
- shadow_seq->set_debug_name("Shadow sequence");
- GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content);
- step->set_depth_test(GL::LEQUAL);
-
- shadow_map = make_unique<GL::ShadowMap>(8192, *sky, sun, *shadow_seq);
- shadow_map->set_debug_name("Shadow map");
- shadow_map->set_target(GL::Vector3(0.0f, 0.0f, 0.0f), 20.0f);
-
GL::SequenceBuilder seq_bld(resources.get<GL::SequenceTemplate>("Desert.seq"));
- seq_bld.set_renderable("content", *shadow_map);
+ seq_bld.set_renderable("content", content);
seq_bld.set_debug_name("Main sequence");
sequence.reset(seq_bld.build(view));
- env_seq = make_unique<GL::Sequence>();
- env_seq->set_clear_enabled(true);
- env_seq->set_debug_name("Environment sequence");
- step = &env_seq->add_step("", *shadow_map);
- step->set_lighting(&resources.get<GL::Lighting>("Desert.lightn"));
- step->set_depth_test(GL::LEQUAL);
+ GL::SequenceBuilder env_bld(resources.get<GL::SequenceTemplate>("Desert_environment.seq"));
+ env_bld.set_renderable("content", *sequence->get_steps().front().get_renderable());
+ env_bld.set_debug_name("Environment sequence");
+ env_seq.reset(env_bld.build());
- env_map = make_unique<GL::EnvironmentMap>(256, GL::RGB16F, 7, sphere, *env_seq);
+ env_map = make_unique<GL::EnvironmentMap>(256, GL::RGBA16F, 7, sphere, *env_seq);
env_map->set_debug_name("Environment map");
sphere.set_matrix(GL::Matrix::translation(GL::Vector3(0.0f, 0.0f, 3.3f)));
content.add(resources.get<GL::Scene>("Background.scene"));
content.add(*env_map);
+ content.add(flare);
+ camera.copy_parameters(resources.get<GL::Camera>("Camera.camera"));
camera.set_debug_name("Main camera");
view.set_content(sequence.get());
view.set_camera(&camera);
+ const GL::Vector3 &sun_direction = sun.get_direction();
+ sun_node = normalize(GL::Vector3(sun_direction.y, -sun_direction.x, 0.0f));
+ sun_axis = normalize(cross(sun_direction, sun_node));
+
+ wisp_base_color = wisp.get_color();
+
const GL::Vector3 &cam_pos = camera.get_position();
camera_distance = cam_pos.norm();
camera_angle = Geometry::atan2(cam_pos.y, cam_pos.x);
camera.set_look_direction(-cam_dir);
}
+ sun_angle += Geometry::Angle<float>::from_degrees(4*dt/Time::sec);
+ sun.set_direction(GL::Matrix::rotation(sun_angle, sun_axis)*-sun_node);
+
+ wisp_angle += Geometry::Angle<float>::from_degrees(6*dt/Time::sec);
+ float r = 3.1f+1.1f*cos(4.0f*wisp_angle);
+ GL::Vector3 p(cos(wisp_angle)*r, sin(wisp_angle)*r, 3.6f+0.4f*sin(1.6f*wisp_angle));
+ wisp.set_position(p);
+ float twilight = 0.8f-min(max(sin(sun_angle), -0.05f), 0.2f)*4.0f;
+ wisp.set_color(wisp_base_color*((3.0f-2.0f*twilight)*twilight*twilight));
+ flare.set_matrix(GL::Matrix::translation(p));
+
display.tick();
+ res_mgr.tick();
view.render();
}
}
-DesertPillars::Resources::Resources()
+DesertPillars::Resources::Resources(GL::ResourceManager *rm)
{
FS::Path base_dir = FS::get_sys_data_dir()/"demos"/"desertpillars"/"data";
source.add_directory(base_dir);
source.add_directory(base_dir/"textures");
source.add_directory(base_dir/"exported");
add_source(source);
+
+ set_resource_manager(rm);
}
ObjectInstance::setup_render(renderer, tag);
renderer.add_shader_data(shdata);
}
+
+
+DesertPillars::LightFlare::LightFlare(const GL::Object &o, unsigned i):
+ ObjectInstance(o)
+{
+ shdata.uniform("flare_light_index", static_cast<int>(i));
+}
+
+void DesertPillars::LightFlare::setup_render(GL::Renderer &renderer, GL::Tag tag) const
+{
+ ObjectInstance::setup_render(renderer, tag);
+ renderer.add_shader_data(shdata);
+}