#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>
keyboard(window),
view(window, gl_ctx),
camera(resources.get<GL::Camera>("Camera.camera")),
+ 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");
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_seq_thsm = make_unique<GL::Sequence>();
+ shadow_seq_thsm->set_clear_enabled(true);
+ shadow_seq_thsm->set_debug_name("Shadow sequence");
+ step = &shadow_seq_thsm->add_step("shadow_thsm", content);
+ step->set_depth_test(GL::LEQUAL);
+
+ shadow_map = make_unique<GL::ShadowMap>(6144, 4096, *sky, lighting);
shadow_map->set_debug_name("Shadow map");
+ shadow_map->add_light(sun, 4096, *shadow_seq);
+ shadow_map->add_light(resources.get<GL::PointLight>("Wisp.light"), 2048, *shadow_seq_thsm);
shadow_map->set_target(GL::Vector3(0.0f, 0.0f, 0.0f), 20.0f);
GL::SequenceBuilder seq_bld(resources.get<GL::SequenceTemplate>("Desert.seq"));
sequence.reset(seq_bld.build(view));
step = &env_seq->add_step("", *shadow_map);
- step->set_lighting(&resources.get<GL::Lighting>("Desert.lightn"));
+ step->set_lighting(&lighting);
step->set_depth_test(GL::LEQUAL);
env_map = make_unique<GL::EnvironmentMap>(256, GL::RGB16F, 7, sphere, *env_seq);
content.add(resources.get<GL::Scene>("Background.scene"));
content.add(*env_map);
+ content.add(flare);
camera.set_debug_name("Main camera");
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);
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();
view.render();
}
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);
+}
virtual void setup_render(Msp::GL::Renderer &, Msp::GL::Tag) const;
};
+ class LightFlare: public Msp::GL::ObjectInstance
+ {
+ private:
+ Msp::GL::ProgramData shdata;
+
+ public:
+ LightFlare(const Msp::GL::Object &, unsigned);
+
+ virtual void setup_render(Msp::GL::Renderer &, Msp::GL::Tag) const;
+ };
+
Msp::Graphics::Display display;
Options opts;
Msp::Graphics::Window window;
Msp::GL::WindowView view;
std::unique_ptr<Msp::GL::Sequence> sequence;
Msp::GL::Camera camera;
+ const Msp::GL::Lighting &lighting;
std::unique_ptr<Msp::GL::Sky> sky;
std::unique_ptr<Msp::GL::Sequence> shadow_seq;
+ std::unique_ptr<Msp::GL::Sequence> shadow_seq_thsm;
std::unique_ptr<Msp::GL::ShadowMap> shadow_map;
std::unique_ptr<Msp::GL::Sequence> env_seq;
std::unique_ptr<Msp::GL::EnvironmentMap> env_map;
Msp::GL::Vector3 sun_axis;
Msp::Geometry::Angle<float> sun_angle;
+ Msp::GL::PointLight &wisp;
+ Msp::GL::Color wisp_base_color;
+ Msp::Geometry::Angle<float> wisp_angle;
+ LightFlare flare;
+
float camera_distance;
Msp::Geometry::Angle<float> camera_base_height;
Msp::Geometry::Angle<float> camera_angle;