]> git.tdb.fi Git - libs/gl.git/commitdiff
Use HDR rendering and a colorcurve postprocessor in desertpillars
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 19:24:20 +0000 (22:24 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Jun 2020 19:24:20 +0000 (22:24 +0300)
demos/desertpillars.cpp

index bf62b7e32f6a9c37be256a6dcc07204f9c476df6..758f5eb12ef8bbce7eed1c55e7ed9d87f801fbba 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/animatedobject.h>
 #include <msp/gl/bloom.h>
 #include <msp/gl/box.h>
+#include <msp/gl/colorcurve.h>
 #include <msp/gl/cylinder.h>
 #include <msp/gl/environmentmap.h>
 #include <msp/gl/framebuffer.h>
@@ -135,6 +136,7 @@ private:
        GL::Light light;
        GL::ShadowMap shadow_scene;
        GL::Bloom bloom;
+       GL::ColorCurve colorcurve;
 
        GL::Pipeline env_pipeline;
 
@@ -335,17 +337,20 @@ void DesertPillars::setup_view()
 void DesertPillars::create_pipeline()
 {
        pipeline.set_multisample(8);
+       pipeline.set_hdr(true);
 
        /* The shadow map is focused on the part of the scene that contains the
        pillars and the cube.  Making the ground cast shadows as well would result
        either in a very low spatial resolution of the shadow map, or ugly artifacts
        as the ground crosses the shadow map boundary. */
        shadow_scene.set_target(GL::Vector3(0, 0, 0), 10);
+       shadow_scene.set_darkness(1);
 
        // Put the sun pretty high in the sky
+       light.set_diffuse(GL::Color(2.0));
        light.set_position(GL::Vector4(0.5, -2, 3, 0));
        lighting.attach(0, light);
-       lighting.set_ambient(GL::Color(0.5));
+       lighting.set_ambient(GL::Color(0.2));
 
        // The skybox is rendered first
        pipeline.add_pass(0, sky_scene);
@@ -359,6 +364,11 @@ void DesertPillars::create_pipeline()
        bloom.set_strength(0.3);
        pipeline.add_postprocessor(bloom);
 
+       /* Lighting calculations are best done in linear color space, so the final
+       image must be converted to srgb for display. */
+       colorcurve.set_srgb();
+       pipeline.add_postprocessor(colorcurve);
+
        /* Initialize a second pipeline to render the environment map.  It has the
        same renderables and passes, but no postprocessors or camera. */
        env_pipeline.add_pass(0, sky_scene);
@@ -369,7 +379,7 @@ void DesertPillars::create_pipeline()
 
 void DesertPillars::create_skybox()
 {
-       skybox_tex.storage(GL::RGB, 128);
+       skybox_tex.storage(GL::SRGB, 128);
        skybox_tex.set_min_filter(GL::LINEAR);
        skybox_tex.set_wrap(GL::CLAMP_TO_EDGE);
        for(unsigned i=0; i<6; ++i)
@@ -450,7 +460,7 @@ void DesertPillars::create_tiles_texture()
        bld.end();
 
        // Create the four tiles
-       bld.color(0.95f, 0.8f, 0.65f);
+       bld.color(GL::Color(0.95f, 0.8f, 0.65f).to_linear());
        for(unsigned i=0; i<2; ++i)
                for(unsigned j=0; j<2; ++j)
                {
@@ -491,7 +501,7 @@ void DesertPillars::create_sand_texture()
        unsigned width = 512;
        unsigned height = 512;
 
-       sand_texture.storage(GL::RGB, width/16, height/16);
+       sand_texture.storage(GL::SRGB, width/16, height/16);
        sand_texture.set_min_filter(GL::LINEAR_MIPMAP_LINEAR);
        sand_texture.set_max_anisotropy(4);
        sand_texture.set_auto_generate_mipmap(true);
@@ -658,7 +668,7 @@ float DesertPillars::ground_height(float x, float y)
 void DesertPillars::create_pillars()
 {
        // The pillars are a matt off-white
-       pillar_material.set_diffuse(GL::Color(0.9, 0.88, 0.8));
+       pillar_material.set_diffuse(GL::Color(0.9, 0.89, 0.85).to_linear());
        pillar_material.set_receive_shadows(true);
 
        GL::RenderPass *pass = &pillar_tech.add_pass(0);
@@ -732,7 +742,7 @@ void DesertPillars::create_cube()
 {
        /* The cube is bluish-gray, with a hard specular reflection to produce a
        sun-like spot */
-       cube_material.set_diffuse(GL::Color(0.5, 0.5, 0.55));
+       cube_material.set_diffuse(GL::Color(0.5, 0.5, 0.55).to_linear());
        cube_material.set_specular(GL::Color(1.0));
        cube_material.set_shininess(120);
        cube_material.set_reflectivity(0.5);