X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=demos%2Fdesertpillars%2Fsource%2Fdesertpillars.cpp;fp=demos%2Fdesertpillars%2Fsource%2Fdesertpillars.cpp;h=432c91663dbb4b7b53446a66b00be9ba2e391c0d;hp=513d81743d700dec32bc734eea0ff63357ea4a49;hb=33577fd6ef75f1c3af77720fde351459727ca68c;hpb=8751e01c31094455bbe72d23ac1bffd9a86c7c45 diff --git a/demos/desertpillars/source/desertpillars.cpp b/demos/desertpillars/source/desertpillars.cpp index 513d8174..432c9166 100644 --- a/demos/desertpillars/source/desertpillars.cpp +++ b/demos/desertpillars/source/desertpillars.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -25,12 +27,15 @@ DesertPillars::DesertPillars(int, char **): keyboard(window), view(window, gl_ctx), camera(resources.get("Camera.camera")), + lighting(resources.get("Desert.lightn")), sphere(resources.get("Sphere.object")), sphere_morph(0.0f), sphere_frozen(false), sphere_stopped(false), sun(resources.get("Sun.light")), sun_angle(Geometry::Angle::from_turns(0.1f)), + wisp(resources.get("Wisp.light")), + flare(resources.get("Flare.object"), lighting.find_light_index(wisp)), camera_stopped(false) { window.set_title("Desert Pillars"); @@ -54,8 +59,16 @@ DesertPillars::DesertPillars(int, char **): GL::Sequence::Step *step = &shadow_seq->add_step("shadow", content); step->set_depth_test(GL::LEQUAL); - shadow_map = make_unique(8192, *sky, sun, *shadow_seq); + shadow_seq_thsm = make_unique(); + 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(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("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("Desert.seq")); @@ -64,7 +77,7 @@ DesertPillars::DesertPillars(int, char **): sequence.reset(seq_bld.build(view)); step = &env_seq->add_step("", *shadow_map); - step->set_lighting(&resources.get("Desert.lightn")); + step->set_lighting(&lighting); step->set_depth_test(GL::LEQUAL); env_map = make_unique(256, GL::RGB16F, 7, sphere, *env_seq); @@ -73,6 +86,7 @@ DesertPillars::DesertPillars(int, char **): content.add(resources.get("Background.scene")); content.add(*env_map); + content.add(flare); camera.set_debug_name("Main camera"); @@ -83,6 +97,8 @@ DesertPillars::DesertPillars(int, char **): 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); @@ -126,6 +142,14 @@ void DesertPillars::tick() sun_angle += Geometry::Angle::from_degrees(4*dt/Time::sec); sun.set_direction(GL::Matrix::rotation(sun_angle, sun_axis)*-sun_node); + wisp_angle += Geometry::Angle::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(); } @@ -163,3 +187,16 @@ void DesertPillars::MorphSphere::setup_render(GL::Renderer &renderer, GL::Tag ta 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(i)); +} + +void DesertPillars::LightFlare::setup_render(GL::Renderer &renderer, GL::Tag tag) const +{ + ObjectInstance::setup_render(renderer, tag); + renderer.add_shader_data(shdata); +}