diff options
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp index 1339afbf0..0c1a21370 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <IGUIButton.h> #include <IGUIStaticText.h> #include <IGUIFont.h> +#include <IMaterialRendererServices.h> #include "client.h" #include "server.h" #include "guiPauseMenu.h" @@ -835,6 +836,49 @@ public: } }; +class GameGlobalShaderConstantSetter : public IShaderConstantSetter +{ + Sky *m_sky; + bool *m_force_fog_off; + f32 *m_fog_range; + +public: + GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off, + f32 *fog_range): + m_sky(sky), + m_force_fog_off(force_fog_off), + m_fog_range(fog_range) + {} + ~GameGlobalShaderConstantSetter() {} + + virtual void onSetConstants(video::IMaterialRendererServices *services, + bool is_highlevel) + { + if(!is_highlevel) + return; + + // Background color + video::SColor bgcolor = m_sky->getBgColor(); + video::SColorf bgcolorf(bgcolor); + float bgcolorfa[4] = { + bgcolorf.r, + bgcolorf.g, + bgcolorf.b, + bgcolorf.a, + }; + services->setPixelShaderConstant("skyBgColor", bgcolorfa, 4); + + // Fog distance + float fog_distance = *m_fog_range; + if(*m_force_fog_off) + fog_distance = 10000*BS; + services->setPixelShaderConstant("fogDistance", &fog_distance, 1); + } + +private: + IrrlichtDevice *m_device; +}; + void the_game( bool &kill, bool random_input, @@ -1250,6 +1294,7 @@ void the_game( bool show_hud = true; bool show_chat = true; bool force_fog_off = false; + f32 fog_range = 100*BS; bool disable_camera_update = false; bool show_debug = g_settings->getBool("show_debug"); bool show_profiler_graph = false; @@ -1260,6 +1305,12 @@ void the_game( float time_of_day_smooth = 0; /* + Shader constants + */ + shsrc->addGlobalConstantSetter( + new GameGlobalShaderConstantSetter(sky, &force_fog_off, &fog_range)); + + /* Main loop */ @@ -2434,7 +2485,6 @@ void the_game( Fog range */ - f32 fog_range; if(farmesh) { fog_range = BS*farmesh_range; |