From: Mikko Rasa Date: Sat, 16 Oct 2021 16:01:44 +0000 (+0300) Subject: Add a moving point light to the night phase of desertpillars X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=33577fd6ef75f1c3af77720fde351459727ca68c;p=libs%2Fgl.git Add a moving point light to the night phase of desertpillars --- diff --git a/demos/desertpillars/data/billboard.glsl b/demos/desertpillars/data/billboard.glsl new file mode 100644 index 00000000..959c4630 --- /dev/null +++ b/demos/desertpillars/data/billboard.glsl @@ -0,0 +1,7 @@ +import unlit; + +#pragma MSP stage(vertex) +vec4 get_vertex_position() override +{ + return vec4(mat3(world_eye_matrix)*vertex.xyz, 1.0); +} diff --git a/demos/desertpillars/data/exported/Desert.lightn b/demos/desertpillars/data/exported/Desert.lightn index 25144b2e..2747c787 100644 --- a/demos/desertpillars/data/exported/Desert.lightn +++ b/demos/desertpillars/data/exported/Desert.lightn @@ -1,2 +1,3 @@ ambient 0.320000 0.480000 0.880000; light "Sun.light"; +light "Wisp.light"; diff --git a/demos/desertpillars/data/exported/Desert.scene b/demos/desertpillars/data/exported/Desert.scene index bdf14015..f46a621b 100644 --- a/demos/desertpillars/data/exported/Desert.scene +++ b/demos/desertpillars/data/exported/Desert.scene @@ -13,3 +13,16 @@ scene }; }; }; +scene +{ + type zsorted; + object "Flare.object" "Flare" + { + transform + { + position 0.0409660 -1.87497 3.35741; + euler 0.00000 -0.00000 0.00000; + scale 1.00000 1.00000 1.00000; + }; + }; +}; diff --git a/demos/desertpillars/data/exported/Desert.seq b/demos/desertpillars/data/exported/Desert.seq index 34213785..be6377e9 100644 --- a/demos/desertpillars/data/exported/Desert.seq +++ b/demos/desertpillars/data/exported/Desert.seq @@ -10,6 +10,12 @@ step "" "content" lighting "Desert.lightn"; scene "Desert.scene"; }; +step "blended" "content" +{ + depth_test LEQUAL; + lighting "Desert.lightn"; + scene "Desert.scene"; +}; ambient_occlusion { occlusion_radius 0.500000; diff --git a/demos/desertpillars/data/exported/Flare.mat b/demos/desertpillars/data/exported/Flare.mat new file mode 100644 index 00000000..7b318175 --- /dev/null +++ b/demos/desertpillars/data/exported/Flare.mat @@ -0,0 +1,3 @@ +type unlit; +texture "flare.png.tex"; +sampler "linear_mip.samp"; diff --git a/demos/desertpillars/data/exported/Flare.mesh b/demos/desertpillars/data/exported/Flare.mesh new file mode 100644 index 00000000..b77a058e --- /dev/null +++ b/demos/desertpillars/data/exported/Flare.mesh @@ -0,0 +1,16 @@ +vertices NORMAL3_BYTE TEXCOORD2_USHORT VERTEX3_FLOAT +{ + normal 0.00000 0.00000 1.00000; + texcoord 1.00000 0.00000; + vertex 0.150000 -0.150000 0.00000; + texcoord 1.00000 1.00000; + vertex 0.150000 0.150000 0.00000; + texcoord 0.00000 0.00000; + vertex -0.150000 -0.150000 0.00000; + texcoord 0.00000 1.00000; + vertex -0.150000 0.150000 0.00000; +}; +batch TRIANGLE_STRIP +{ + indices 0 1 2 3; +}; diff --git a/demos/desertpillars/data/exported/Flare.object b/demos/desertpillars/data/exported/Flare.object new file mode 100644 index 00000000..f8aa36d7 --- /dev/null +++ b/demos/desertpillars/data/exported/Flare.object @@ -0,0 +1,3 @@ +bounding_sphere_hint 0.00000 0.00000 0.00000 0.212132; +mesh "Flare.mesh"; +technique "Flare.tech"; diff --git a/demos/desertpillars/data/exported/Flare.tech b/demos/desertpillars/data/exported/Flare.tech new file mode 100644 index 00000000..c04117ed --- /dev/null +++ b/demos/desertpillars/data/exported/Flare.tech @@ -0,0 +1,6 @@ +method "blended" +{ + material "Flare.mat"; + blend SRC_ALPHA ONE; + shader "flare.glsl.shader"; +}; diff --git a/demos/desertpillars/data/exported/Iron.tech b/demos/desertpillars/data/exported/Iron.tech index 1e55ffba..7fa4e39b 100644 --- a/demos/desertpillars/data/exported/Iron.tech +++ b/demos/desertpillars/data/exported/Iron.tech @@ -7,3 +7,7 @@ method "shadow" { shader "sphere_shadow.glsl.shader"; }; +method "shadow_thsm" +{ + shader "sphere_shadow_thsm.glsl.shader"; +}; diff --git a/demos/desertpillars/data/exported/Wisp.light b/demos/desertpillars/data/exported/Wisp.light new file mode 100644 index 00000000..a2964c64 --- /dev/null +++ b/demos/desertpillars/data/exported/Wisp.light @@ -0,0 +1,4 @@ +type point; +position 0.0409660 -1.87497 3.35741; +attenuation 1.00000 0.00000 1.00000; +color 10.0000 10.0000 10.0000; diff --git a/demos/desertpillars/data/exported/flare.png.tex b/demos/desertpillars/data/exported/flare.png.tex new file mode 100644 index 00000000..58018fc7 --- /dev/null +++ b/demos/desertpillars/data/exported/flare.png.tex @@ -0,0 +1,3 @@ +type \2d; +generate_mipmap true; +external_image_srgb "flare.png"; diff --git a/demos/desertpillars/data/flare.glsl b/demos/desertpillars/data/flare.glsl new file mode 100644 index 00000000..dd287581 --- /dev/null +++ b/demos/desertpillars/data/flare.glsl @@ -0,0 +1,12 @@ +import billboard; + +uniform Flare +{ + int flare_light_index; +}; + +#pragma MSP stage(fragment) +vec4 get_color() override +{ + return texture(color_tex, texcoord.xy)*vec4(light_sources[flare_light_index].color, 1.0); +} diff --git a/demos/desertpillars/data/flare.png b/demos/desertpillars/data/flare.png new file mode 100644 index 00000000..aadc9f24 Binary files /dev/null and b/demos/desertpillars/data/flare.png differ diff --git a/demos/desertpillars/data/sphere.shader b/demos/desertpillars/data/sphere.shader index d203cd1b..48fd74ae 100644 --- a/demos/desertpillars/data/sphere.shader +++ b/demos/desertpillars/data/sphere.shader @@ -1,4 +1,5 @@ module "sphere.glsl" { specialize "use_image_based_lighting" true; + specialize "use_shadow_map" true; }; diff --git a/demos/desertpillars/data/sphere_shadow_thsm.glsl b/demos/desertpillars/data/sphere_shadow_thsm.glsl new file mode 100644 index 00000000..1a401736 --- /dev/null +++ b/demos/desertpillars/data/sphere_shadow_thsm.glsl @@ -0,0 +1,2 @@ +import occluder_thsm; +import sphere_morph; diff --git a/demos/desertpillars/scene.blend b/demos/desertpillars/scene.blend index 2a73dd58..e452b8b7 100644 Binary files a/demos/desertpillars/scene.blend and b/demos/desertpillars/scene.blend differ 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); +} diff --git a/demos/desertpillars/source/desertpillars.h b/demos/desertpillars/source/desertpillars.h index 41707381..18522a57 100644 --- a/demos/desertpillars/source/desertpillars.h +++ b/demos/desertpillars/source/desertpillars.h @@ -54,6 +54,17 @@ private: 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; @@ -64,9 +75,11 @@ private: Msp::GL::WindowView view; std::unique_ptr sequence; Msp::GL::Camera camera; + const Msp::GL::Lighting &lighting; std::unique_ptr sky; std::unique_ptr shadow_seq; + std::unique_ptr shadow_seq_thsm; std::unique_ptr shadow_map; std::unique_ptr env_seq; std::unique_ptr env_map; @@ -83,6 +96,11 @@ private: Msp::GL::Vector3 sun_axis; Msp::Geometry::Angle sun_angle; + Msp::GL::PointLight &wisp; + Msp::GL::Color wisp_base_color; + Msp::Geometry::Angle wisp_angle; + LightFlare flare; + float camera_distance; Msp::Geometry::Angle camera_base_height; Msp::Geometry::Angle camera_angle;