]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a moving point light to the night phase of desertpillars
authorMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 16:01:44 +0000 (19:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 16 Oct 2021 16:03:02 +0000 (19:03 +0300)
18 files changed:
demos/desertpillars/data/billboard.glsl [new file with mode: 0644]
demos/desertpillars/data/exported/Desert.lightn
demos/desertpillars/data/exported/Desert.scene
demos/desertpillars/data/exported/Desert.seq
demos/desertpillars/data/exported/Flare.mat [new file with mode: 0644]
demos/desertpillars/data/exported/Flare.mesh [new file with mode: 0644]
demos/desertpillars/data/exported/Flare.object [new file with mode: 0644]
demos/desertpillars/data/exported/Flare.tech [new file with mode: 0644]
demos/desertpillars/data/exported/Iron.tech
demos/desertpillars/data/exported/Wisp.light [new file with mode: 0644]
demos/desertpillars/data/exported/flare.png.tex [new file with mode: 0644]
demos/desertpillars/data/flare.glsl [new file with mode: 0644]
demos/desertpillars/data/flare.png [new file with mode: 0644]
demos/desertpillars/data/sphere.shader
demos/desertpillars/data/sphere_shadow_thsm.glsl [new file with mode: 0644]
demos/desertpillars/scene.blend
demos/desertpillars/source/desertpillars.cpp
demos/desertpillars/source/desertpillars.h

diff --git a/demos/desertpillars/data/billboard.glsl b/demos/desertpillars/data/billboard.glsl
new file mode 100644 (file)
index 0000000..959c463
--- /dev/null
@@ -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);
+}
index 25144b2e5d02034ebfd5637355b4e381b572cfef..2747c787533fe06fb52d6ac9ddcd6721fc1bb3c7 100644 (file)
@@ -1,2 +1,3 @@
 ambient 0.320000 0.480000 0.880000;
 light "Sun.light";
+light "Wisp.light";
index bdf1401597d6b77959d3f67e09701cda7eaa70e9..f46a621b2533d93db2faba11cc39393cbd1fbc14 100644 (file)
@@ -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;
+               };
+       };
+};
index 34213785876e1b43740015aef33b4a0202f105a4..be6377e996d71c8663e6850b71fdc5d696a63df1 100644 (file)
@@ -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 (file)
index 0000000..7b31817
--- /dev/null
@@ -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 (file)
index 0000000..b77a058
--- /dev/null
@@ -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 (file)
index 0000000..f8aa36d
--- /dev/null
@@ -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 (file)
index 0000000..c04117e
--- /dev/null
@@ -0,0 +1,6 @@
+method "blended"
+{
+       material "Flare.mat";
+       blend SRC_ALPHA ONE;
+       shader "flare.glsl.shader";
+};
index 1e55ffba5676e0d59da2e281db42cba3384e34f4..7fa4e39bfe5b1bf2a9768f2aefc535a3b74348a3 100644 (file)
@@ -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 (file)
index 0000000..a2964c6
--- /dev/null
@@ -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 (file)
index 0000000..58018fc
--- /dev/null
@@ -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 (file)
index 0000000..dd28758
--- /dev/null
@@ -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 (file)
index 0000000..aadc9f2
Binary files /dev/null and b/demos/desertpillars/data/flare.png differ
index d203cd1b35dd2e2a83bdb207340e4260032e4597..48fd74ae596f3acd44d4fdf7a4f362c868d89a7a 100644 (file)
@@ -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 (file)
index 0000000..1a40173
--- /dev/null
@@ -0,0 +1,2 @@
+import occluder_thsm;
+import sphere_morph;
index 2a73dd583de3351201363a5259573ecdd802dcfd..e452b8b7fc75158494b44add4e6c4e7579c007a5 100644 (file)
Binary files a/demos/desertpillars/scene.blend and b/demos/desertpillars/scene.blend differ
index 513d81743d700dec32bc734eea0ff63357ea4a49..432c91663dbb4b7b53446a66b00be9ba2e391c0d 100644 (file)
@@ -1,6 +1,8 @@
 #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>
@@ -25,12 +27,15 @@ DesertPillars::DesertPillars(int, char **):
        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");
@@ -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<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"));
@@ -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<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);
@@ -73,6 +86,7 @@ DesertPillars::DesertPillars(int, char **):
 
        content.add(resources.get<GL::Scene>("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<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();
 }
@@ -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<int>(i));
+}
+
+void DesertPillars::LightFlare::setup_render(GL::Renderer &renderer, GL::Tag tag) const
+{
+       ObjectInstance::setup_render(renderer, tag);
+       renderer.add_shader_data(shdata);
+}
index 417073816b0fd50fe433de311fb571817e4de295..18522a57ca324f0449d52d50d7b7cf892d3c3365 100644 (file)
@@ -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<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;
@@ -83,6 +96,11 @@ private:
        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;