Fog: Make fraction of visible distance at which fog starts configurable
authorLars Hofhansl <larsh@apache.org>
Sun, 4 Dec 2016 05:43:25 +0000 (21:43 -0800)
committerparamat <mat.gregory@virginmedia.com>
Wed, 7 Dec 2016 04:07:54 +0000 (04:07 +0000)
Optimise the fetching of global settings 'camera_smoothing',
'cinematic' and 'cinematic_camera_smoothing'.
Cache 'cam_smoothing'.

builtin/settingtypes.txt
client/shaders/nodes_shader/opengl_fragment.glsl
client/shaders/water_surface_shader/opengl_fragment.glsl
client/shaders/wielded_shader/opengl_fragment.glsl
minetest.conf.example
src/defaultsettings.cpp
src/game.cpp
src/shader.cpp

index b1f31054eb9bf5519854fe649858e47a4260109e..10db4787dbb7861143057f5a583397ff602b3991 100644 (file)
@@ -529,6 +529,9 @@ ambient_occlusion_gamma (Ambient occlusion gamma) float 2.2 0.25 4.0
 #    Enables animation of inventory items.
 inventory_items_animations (Inventory items animations) bool false
 
+#    Fraction of the visible distance at which fog starts to be rendered
+fog_start (Fog Start) float 0.4 0.0 0.99
+
 [**Menus]
 
 #    Use a cloud animation for the main menu background.
index 149aa2bc5b72be7df39b767000fd85f4a47d6208..71ded2b9d3b47d0b78564ded47917c9cac01ef26 100644 (file)
@@ -19,7 +19,7 @@ bool normalTexturePresent = false;
 
 const float e = 2.718281828459;
 const float BS = 10.0;
-const float fogStart = 0.4;
+const float fogStart = FOG_START;
 const float fogShadingParameter = 1 / ( 1 - fogStart);
 
 #ifdef ENABLE_TONE_MAPPING
index 4164870c75abda693f2053f6e07cf30249673a9b..c4e78470d1b4ff9f7b29e3d713752a8d303b868e 100644 (file)
@@ -21,7 +21,7 @@ bool texSeamless = false;
 
 const float e = 2.718281828459;
 const float BS = 10.0;
-const float fogStart = 0.4;
+const float fogStart = FOG_START;
 const float fogShadingParameter = 1 / ( 1 - fogStart);
 
 #ifdef ENABLE_TONE_MAPPING
index 7c38b749a61b04f5297eb4989c550822e8c9497b..ba7a8f12decfeec752bcce0115123faf794cd256 100644 (file)
@@ -19,7 +19,7 @@ bool texSeamless = false;
 
 const float e = 2.718281828459;
 const float BS = 10.0;
-const float fogStart = 0.4;
+const float fogStart = FOG_START;
 const float fogShadingParameter = 1 / ( 1 - fogStart);
 
 void get_texture_flags()
index 361311ba00e2a78619615ab3c03e350d9e6b6fe5..90d7af0a3de9b9cbaef93d439d37649ded206a03 100644 (file)
 #    type: bool
 # inventory_items_animations = false
 
+#    Fraction of the visible distance at which fog starts to be rendered
+#    Range 0 - 0.99
+# fog_start = 0.4
+
 ### Menus
 
 #    Use a cloud animation for the main menu background.
index 2cb57532d2c9e68c7284ceeb299e7333b7cd2295..bd88cf53010cfb7da11e7cc8a1f042bca5adff7b 100644 (file)
@@ -106,6 +106,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("client_unload_unused_data_timeout", "600");
        settings->setDefault("client_mapblock_limit", "5000");
        settings->setDefault("enable_fog", "true");
+       settings->setDefault("fog_start", "0.4");
        settings->setDefault("fov", "72");
        settings->setDefault("view_bobbing", "true");
        settings->setDefault("leaves_style", "fancy");
index e6d38d0a08e938e377f98c379a33c254ac7ad135..cc6e5a0e352cf8fc9016bae48341c056f702c760 100644 (file)
@@ -1825,6 +1825,8 @@ private:
        f32  m_cache_mouse_sensitivity;
        f32  m_cache_joystick_frustum_sensitivity;
        f32  m_repeat_right_click_time;
+       f32  m_cache_cam_smoothing;
+       f32  m_cache_fog_start;
 
 #ifdef __ANDROID__
        bool m_cache_hold_aux1;
@@ -1876,6 +1878,12 @@ Game::Game() :
                &settingChangedCallback, this);
        g_settings->registerChangedCallback("free_move",
                &settingChangedCallback, this);
+       g_settings->registerChangedCallback("cinematic",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("cinematic_camera_smoothing",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("camera_smoothing",
+               &settingChangedCallback, this);
 
        readSettings();
 
@@ -1929,6 +1937,12 @@ Game::~Game()
                &settingChangedCallback, this);
        g_settings->deregisterChangedCallback("free_move",
                &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("cinematic",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("cinematic_camera_smoothing",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("camera_smoothing",
+               &settingChangedCallback, this);
 }
 
 bool Game::startup(bool *kill,
@@ -2034,16 +2048,10 @@ void Game::run()
                processUserInput(&flags, &runData, dtime);
                // Update camera before player movement to avoid camera lag of one frame
                updateCameraDirection(&cam_view_target, &flags, dtime);
-               float cam_smoothing = 0;
-               if (g_settings->getBool("cinematic"))
-                       cam_smoothing = 1 - g_settings->getFloat("cinematic_camera_smoothing");
-               else
-                       cam_smoothing = 1 - g_settings->getFloat("camera_smoothing");
-               cam_smoothing = rangelim(cam_smoothing, 0.01f, 1.0f);
                cam_view.camera_yaw += (cam_view_target.camera_yaw -
-                               cam_view.camera_yaw) * cam_smoothing;
+                               cam_view.camera_yaw) * m_cache_cam_smoothing;
                cam_view.camera_pitch += (cam_view_target.camera_pitch -
-                               cam_view.camera_pitch) * cam_smoothing;
+                               cam_view.camera_pitch) * m_cache_cam_smoothing;
                updatePlayerControl(cam_view);
                step(&dtime);
                processClientEvents(&cam_view_target, &runData.damage_flash);
@@ -4284,7 +4292,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
                driver->setFog(
                                sky->getBgColor(),
                                video::EFT_FOG_LINEAR,
-                               runData->fog_range * 0.4,
+                               runData->fog_range * m_cache_fog_start,
                                runData->fog_range * 1.0,
                                0.01,
                                false, // pixel fog
@@ -4660,7 +4668,18 @@ void Game::readSettings()
        m_cache_enable_noclip                = g_settings->getBool("noclip");
        m_cache_enable_free_move             = g_settings->getBool("free_move");
 
+       m_cache_fog_start                    = g_settings->getFloat("fog_start");
+
+       m_cache_cam_smoothing = 0;
+       if (g_settings->getBool("cinematic"))
+               m_cache_cam_smoothing = 1 - g_settings->getFloat("cinematic_camera_smoothing");
+       else
+               m_cache_cam_smoothing = 1 - g_settings->getFloat("camera_smoothing");
+
+       m_cache_fog_start = rangelim(m_cache_fog_start, 0.0f, 0.99f);
+       m_cache_cam_smoothing = rangelim(m_cache_cam_smoothing, 0.01f, 1.0f);
        m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
+
 }
 
 /****************************************************************************/
index d51c1e3087e63f5322878502ad611229ab39bdc8..c0ecf738dd545474d932e2739ddab660e4c01fb5 100644 (file)
@@ -751,6 +751,10 @@ ShaderInfo generate_shader(std::string name, u8 material_type, u8 drawtype,
        if (g_settings->getBool("tone_mapping"))
                shaders_header += "#define ENABLE_TONE_MAPPING\n";
 
+       shaders_header += "#define FOG_START ";
+       shaders_header += ftos(rangelim(g_settings->getFloat("fog_start"), 0.0f, 0.99f));
+       shaders_header += "\n";
+
        // Call addHighLevelShaderMaterial() or addShaderMaterial()
        const c8* vertex_program_ptr = 0;
        const c8* pixel_program_ptr = 0;